Documentation ¶
Overview ¶
Package testutil implements common testing utilities.
Index ¶
- func DNSQuery(srv, addr string, qtype uint16) (*dns.Msg, dns.RR, error)
- func GetFreePort() string
- func MakeStaticHandler(tb testing.TB, answer string) func(dns.ResponseWriter, *dns.Msg)
- func NewRR(tb testing.TB, s string) dns.RR
- func ServeTestDNSServer(addr string, handler func(dns.ResponseWriter, *dns.Msg))
- func WaitForDNSServer(addr string) error
- func WaitForHTTPServer(addr string) error
- type NullTrace
- func (t *NullTrace) Finish()
- func (t *NullTrace) LazyLog(x fmt.Stringer, sensitive bool)
- func (t *NullTrace) LazyPrintf(format string, a ...interface{})
- func (t *NullTrace) SetError()
- func (t *NullTrace) SetMaxEvents(m int)
- func (t *NullTrace) SetRecycler(f func(interface{}))
- func (t *NullTrace) SetTraceInfo(traceID, spanID uint64)
- type TestResolver
- type TestTrace
- func (t *TestTrace) Finish()
- func (t *TestTrace) LazyLog(x fmt.Stringer, sensitive bool)
- func (t *TestTrace) LazyPrintf(format string, a ...interface{})
- func (t *TestTrace) SetError()
- func (t *TestTrace) SetMaxEvents(m int)
- func (t *TestTrace) SetRecycler(f func(interface{}))
- func (t *TestTrace) SetTraceInfo(traceID, spanID uint64)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetFreePort ¶
func GetFreePort() string
GetFreePort returns a free TCP port. This is hacky and not race-free, but it works well enough for testing purposes.
func MakeStaticHandler ¶
MakeStaticHandler for the DNS server. The given answer must be a valid zone.
func ServeTestDNSServer ¶
func ServeTestDNSServer(addr string, handler func(dns.ResponseWriter, *dns.Msg))
ServeTestDNSServer starts the fake DNS server.
func WaitForDNSServer ¶
WaitForDNSServer waits 5 seconds for a DNS server to start, and returns an error if it fails to do so. It does this by repeatedly querying the DNS server until it either replies or times out. Note we do not do any validation of the reply.
func WaitForHTTPServer ¶
WaitForHTTPServer waits 5 seconds for an HTTP server to start, and returns an error if it fails to do so. It does this by repeatedly querying the server until it either replies or times out.
Types ¶
type NullTrace ¶
type NullTrace struct{}
NullTrace implements the tracer.Trace interface, but discards everything.
func (*NullTrace) LazyPrintf ¶
func (*NullTrace) SetMaxEvents ¶
func (*NullTrace) SetRecycler ¶
func (t *NullTrace) SetRecycler(f func(interface{}))
func (*NullTrace) SetTraceInfo ¶
type TestResolver ¶
type TestResolver struct { // Has this resolver been initialized? Initialized bool // Maintain() sends a value over this channel. MaintainC chan bool // The last query we've seen. LastQuery *dns.Msg // What we will respond to queries. Response *dns.Msg RespError error }
TestResolver is a dnsserver.Resolver implementation for testing, so we can control its responses during tests.
func NewTestResolver ¶
func NewTestResolver() *TestResolver
NewTestResolver creates a new TestResolver with minimal initialization.
type TestTrace ¶
TestTrace implements the tracer.Trace interface, but prints using the test logging infrastructure.
func NewTestTrace ¶
func (*TestTrace) LazyPrintf ¶
func (*TestTrace) SetMaxEvents ¶
func (*TestTrace) SetRecycler ¶
func (t *TestTrace) SetRecycler(f func(interface{}))