Đảm bảo query trả đúng country/ASN cho IP đã biết (vd 8.8.8.8 → US).
Validate edge case (IP sai dạng, IP private, IPv6).
Fix đề xuất
internal/data/query_test.go: test Query("8.8.8.8") thành công, Query("not-an-ip") lỗi, IP not found.
internal/data/ipdb_test.go: test Reload() không leak, IsLoaded().
Build test có thể -race để bắt regression race.
Lưu ý: cloneDBFile() dùng path tương đối (data/...) → test chạy với CWD = package dir sẽ fail. Cần xử lý (chdir trong test hoặc làm path configurable) — liên quan chặt đến issue #10.
(Lưu ý phụ: data CSV/mmdb đang commit trong repo (data/), nên test có data sẵn để chạy.)
## Vấn đề
Repo **chưa có file test nào**. Lớp `internal/data` (đặc biệt là `Query`/`Reload` concurrency) rất đáng có test để:
1. Bảo vệ regression cho fix data race (issue #10).
2. Đảm bảo query trả đúng country/ASN cho IP đã biết (vd 8.8.8.8 → US).
3. Validate edge case (IP sai dạng, IP private, IPv6).
## Fix đề xuất
- `internal/data/query_test.go`: test `Query("8.8.8.8")` thành công, `Query("not-an-ip")` lỗi, IP not found.
- `internal/data/ipdb_test.go`: test `Reload()` không leak, `IsLoaded()`.
- Build test có thể `-race` để bắt regression race.
- Lưu ý: `cloneDBFile()` dùng **path tương đối** (`data/...`) → test chạy với CWD = package dir sẽ fail. Cần xử lý (chdir trong test hoặc làm path configurable) — liên quan chặt đến issue #10.
(Lưu ý phụ: data CSV/mmdb đang commit trong repo (`data/`), nên test có data sẵn để chạy.)
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Vấn đề
Repo chưa có file test nào. Lớp
internal/data(đặc biệt làQuery/Reloadconcurrency) rất đáng có test để:Fix đề xuất
internal/data/query_test.go: testQuery("8.8.8.8")thành công,Query("not-an-ip")lỗi, IP not found.internal/data/ipdb_test.go: testReload()không leak,IsLoaded().-raceđể bắt regression race.cloneDBFile()dùng path tương đối (data/...) → test chạy với CWD = package dir sẽ fail. Cần xử lý (chdir trong test hoặc làm path configurable) — liên quan chặt đến issue #10.(Lưu ý phụ: data CSV/mmdb đang commit trong repo (
data/), nên test có data sẵn để chạy.)Đã sửa trong PR #22 (merge commit
361eb40).internal/data/data_test.go(mới): 4 test caseTestQueryValidIP—8.8.8.8→ country US + network record chứa IP.TestQueryInvalidIP—not-an-ip→ error.TestQueryNotFound—240.0.0.1→ErrNotFound(sentinel).TestQueryReloadConcurrent— 8 goroutine Query × 5000 + 4 goroutine Reload × 30 chạy song song — regression test cho data race #10/#12.Verify:
go test -race -count=1 ./...PASS (internal/data2.4s, không race).