b8428b302f
* refactor(netxlite): make sure we always use netmocks While there, improve logging and make sure we test 100% of the package with unit tests only. (We don't need to have integration testing in this package because it's fairly simple/obvious.) Part of https://github.com/ooni/probe/issues/1505 * further improve logs
35 lines
802 B
Go
35 lines
802 B
Go
package netxmocks
|
|
|
|
import "context"
|
|
|
|
// resolver is the interface we expect from a resolver
|
|
type resolver interface {
|
|
LookupHost(ctx context.Context, domain string) ([]string, error)
|
|
Network() string
|
|
Address() string
|
|
}
|
|
|
|
// Resolver is a mockable Resolver.
|
|
type Resolver struct {
|
|
MockLookupHost func(ctx context.Context, domain string) ([]string, error)
|
|
MockNetwork func() string
|
|
MockAddress func() string
|
|
}
|
|
|
|
// LookupHost calls MockLookupHost.
|
|
func (r *Resolver) LookupHost(ctx context.Context, domain string) ([]string, error) {
|
|
return r.MockLookupHost(ctx, domain)
|
|
}
|
|
|
|
// Address calls MockAddress.
|
|
func (r *Resolver) Address() string {
|
|
return r.MockAddress()
|
|
}
|
|
|
|
// Network calls MockNetwork.
|
|
func (r *Resolver) Network() string {
|
|
return r.MockNetwork()
|
|
}
|
|
|
|
var _ resolver = &Resolver{}
|