6d3a4f1db8
When preparing a tutorial for netxlite, I figured it is easier to tell people "hey, this is the package you should use for all low-level networking stuff" rather than introducing people to a set of packages working together where some piece of functionality is here and some other piece is there. Part of https://github.com/ooni/probe/issues/1591
40 lines
1.0 KiB
Go
40 lines
1.0 KiB
Go
package mocks
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
// Resolver is a mockable Resolver.
|
|
type Resolver struct {
|
|
MockLookupHost func(ctx context.Context, domain string) ([]string, error)
|
|
MockNetwork func() string
|
|
MockAddress func() string
|
|
MockCloseIdleConnections func()
|
|
MockLookupHTTPS func(ctx context.Context, domain string) (*HTTPSSvc, error)
|
|
}
|
|
|
|
// 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()
|
|
}
|
|
|
|
// CloseIdleConnections calls MockCloseIdleConnections.
|
|
func (r *Resolver) CloseIdleConnections() {
|
|
r.MockCloseIdleConnections()
|
|
}
|
|
|
|
// LookupHTTPS calls MockLookupHTTPS.
|
|
func (r *Resolver) LookupHTTPS(ctx context.Context, domain string) (*HTTPSSvc, error) {
|
|
return r.MockLookupHTTPS(ctx, domain)
|
|
}
|