mirror of
https://github.com/mpolden/echoip.git
synced 2025-07-21 00:06:08 +02:00
Add support for city lookup
This commit is contained in:
@ -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},
|
||||
}
|
||||
|
Reference in New Issue
Block a user