Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregory Russell committed Apr 15, 2019
1 parent 86d8dbd commit cf49788
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions manager/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ func TestInitDataset(t *testing.T) {
//geoloader.UseOnlyMarchForTest()
year, month, day := "(2018|2017|2015|2014)", "03", "(07|08)"
geoloader.UseSpecificGeolite2DateForTesting(&year, &month, &day)
year, month, day = "2018", "03", "(01|08)"
geoloader.UseSpecificASNDateForTesting(&year, &month, &day)

// Load the small directory.
manager.MustUpdateDirectory()
Expand All @@ -46,29 +48,27 @@ func TestInitDataset(t *testing.T) {
res string
}{
// This request needs a legacy binary dataset
{"1.4.128.0", "1199145600", `{"Geo":{"continent_code":"AS","country_code":"TH","country_code3":"THA","country_name":"Thailand","region":"40","city":"Bangkok","latitude":13.754,"longitude":100.501},"Network":null}`},
{"1.4.128.0", "1199145600", `{"Geo":{"continent_code":"AS","country_code":"TH","country_code3":"THA","country_name":"Thailand","region":"40","city":"Bangkok","latitude":13.754,"longitude":100.501},"Network":{"Systems":[{"ASNs":[23969]}]}}`},
// This request needs another legacy binary dataset
// `{"Geo":{"continent_code":"AS","country_code":"TH","country_code3":"THA","country_name":"Thailand","region":"77","city":"Bung","postal_code":"37000","latitude":15.695,"longitude":104.648},"Network":null}`
{"1.4.128.0", "1399145600", `{"Geo":{"continent_code":"AS","country_code":"TH","country_code3":"THA","country_name":"Thailand","region":"40","city":"Bangkok","latitude":13.754,"longitude":100.501},"Network":null}`},
{"1.4.128.0", "1399145600",
`{"Geo":{"continent_code":"AS","country_code":"TH","country_code3":"THA","country_name":"Thailand","region":"40","city":"Bangkok","latitude":13.754,"longitude":100.501},"Network":{"Systems":[{"ASNs":[23969]}]}}`},
// This request needs a geolite2 dataset
{"1.9.128.0", "1512086400", `{"Geo":{"continent_code":"AS","country_code":"MY","country_code3":"MYS","country_name":"Malaysia","region":"14","city":"Kuala Lumpur","postal_code":"50586","latitude":3.167,"longitude":101.7},"Network":null}`},
{"1.9.128.0", "1512086400",
`{"Geo":{"continent_code":"AS","country_code":"MY","country_code3":"MYS","country_name":"Malaysia","region":"05","city":"Pantai","latitude":2.787,"longitude":101.995},"Network":{"Systems":[{"ASNs":[4788]}]}}`},
// This request needs the latest dataset in the memory.
{"1.22.128.0", "1544400000", `{"Geo":{"continent_code":"AS","country_code":"IN","country_name":"India","region":"HR","city":"Faridabad","latitude":28.4333,"longitude":77.3167},"Network":null}`},
// This request used a loaded & removed legacy dataset.
//{"1.4.128.0", "1199145600", `{"Geo":{"continent_code":"AS","country_code":"TH","country_code3":"THA","country_name":"Thailand","region":"40","city":"Bangkok","latitude":13.754,"longitude":100.501},"Network":null}`},
{"1.22.128.0", "1544400000",
`{"Geo":{"continent_code":"AS","country_code":"IN","country_name":"India","region":"HR","city":"Faridabad","latitude":28.4333,"longitude":77.3167},"Network":{"Systems":[{"ASNs":[45528]}]}}`},
}
for n, test := range tests {
w := httptest.NewRecorder()
r := &http.Request{}
r.URL, _ = url.Parse("/annotate?ip_addr=" + url.QueryEscape(test.ip) + "&since_epoch=" + url.QueryEscape(test.time))
log.Println("Calling handler")
handler.Annotate(w, r)
if w.Result().StatusCode != http.StatusOK {
t.Error("Failed annotation for", test.ip)
continue
}
body := w.Body.String()
log.Println(body)

if string(body) != test.res {
t.Errorf("%d:\nGot\n__%s__\nexpected\n__%s__\n", n, body, test.res)
Expand Down

0 comments on commit cf49788

Please sign in to comment.