Add support for city lookup

This commit is contained in:
Martin Polden
2016-04-17 11:28:47 +02:00
parent 8027c55fdf
commit 8f71576357
7 changed files with 77 additions and 11 deletions

View File

@ -13,9 +13,11 @@ type mockOracle struct{}
func (r *mockOracle) LookupAddr(string) ([]string, error) { return []string{"localhost"}, nil }
func (r *mockOracle) LookupCountry(net.IP) (string, error) { return "Elbonia", nil }
func (r *mockOracle) LookupCity(net.IP) (string, error) { return "Bornyasherk", nil }
func (r *mockOracle) LookupPort(net.IP, uint64) error { return nil }
func (r *mockOracle) IsLookupAddrEnabled() bool { return true }
func (r *mockOracle) IsLookupCountryEnabled() bool { return true }
func (r *mockOracle) IsLookupCityEnabled() bool { return true }
func (r *mockOracle) IsLookupPortEnabled() bool { return true }
func newTestAPI() *API {
@ -60,6 +62,7 @@ func TestClIHandlers(t *testing.T) {
{s.URL, "127.0.0.1\n", 200},
{s.URL + "/ip", "127.0.0.1\n", 200},
{s.URL + "/country", "Elbonia\n", 200},
{s.URL + "/city", "Bornyasherk\n", 200},
{s.URL + "/foo", "404 page not found", 404},
}
@ -86,7 +89,7 @@ func TestJSONHandlers(t *testing.T) {
out string
status int
}{
{s.URL, `{"ip":"127.0.0.1","country":"Elbonia","hostname":"localhost"}`, 200},
{s.URL, `{"ip":"127.0.0.1","country":"Elbonia","city":"Bornyasherk","hostname":"localhost"}`, 200},
{s.URL + "/port/31337", `{"ip":"127.0.0.1","port":31337,"reachable":true}`, 200},
{s.URL + "/foo", `{"error":"404 page not found"}`, 404},
}