Refactor lookup methods

This commit is contained in:
Martin Polden
2016-04-17 11:09:56 +02:00
parent 7d23fe9853
commit 8027c55fdf
5 changed files with 130 additions and 90 deletions

View File

@ -9,20 +9,21 @@ import (
"testing"
)
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) LookupPort(net.IP, uint64) error { return nil }
func (r *mockOracle) IsLookupAddrEnabled() bool { return true }
func (r *mockOracle) IsLookupCountryEnabled() bool { return true }
func (r *mockOracle) IsLookupPortEnabled() bool { return true }
func newTestAPI() *API {
return &API{
lookupAddr: func(string) ([]string, error) {
return []string{"localhost"}, nil
},
lookupCountry: func(ip net.IP) (string, error) {
return "Elbonia", nil
},
oracle: &mockOracle{},
ipFromRequest: func(*http.Request) (net.IP, error) {
return net.ParseIP("127.0.0.1"), nil
},
testPort: func(net.IP, uint64) error {
return nil
},
}
}