testutil

package
v0.0.0-...-7bc2641 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 16, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package testutil implements common testing utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DNSQuery

func DNSQuery(srv, addr string, qtype uint16) (*dns.Msg, dns.RR, error)

DNSQuery is a convenient wrapper to issue simple DNS queries.

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

func MakeStaticHandler(tb testing.TB, answer string) func(dns.ResponseWriter, *dns.Msg)

MakeStaticHandler for the DNS server. The given answer must be a valid zone.

func NewRR

func NewRR(tb testing.TB, s string) dns.RR

func ServeTestDNSServer

func ServeTestDNSServer(addr string, handler func(dns.ResponseWriter, *dns.Msg))

ServeTestDNSServer starts the fake DNS server.

func WaitForDNSServer

func WaitForDNSServer(addr string) error

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

func WaitForHTTPServer(addr string) error

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) Finish

func (t *NullTrace) Finish()

func (*NullTrace) LazyLog

func (t *NullTrace) LazyLog(x fmt.Stringer, sensitive bool)

func (*NullTrace) LazyPrintf

func (t *NullTrace) LazyPrintf(format string, a ...interface{})

func (*NullTrace) SetError

func (t *NullTrace) SetError()

func (*NullTrace) SetMaxEvents

func (t *NullTrace) SetMaxEvents(m int)

func (*NullTrace) SetRecycler

func (t *NullTrace) SetRecycler(f func(interface{}))

func (*NullTrace) SetTraceInfo

func (t *NullTrace) SetTraceInfo(traceID, spanID uint64)

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.

func (*TestResolver) Init

func (r *TestResolver) Init() error

Init the resolver.

func (*TestResolver) Maintain

func (r *TestResolver) Maintain()

Maintain the resolver.

func (*TestResolver) Query

func (r *TestResolver) Query(req *dns.Msg, tr trace.Trace) (*dns.Msg, error)

Query handles the given query, returning the pre-recorded response.

type TestTrace

type TestTrace struct {
	T *testing.T
}

TestTrace implements the tracer.Trace interface, but prints using the test logging infrastructure.

func NewTestTrace

func NewTestTrace(t *testing.T) *TestTrace

func (*TestTrace) Finish

func (t *TestTrace) Finish()

func (*TestTrace) LazyLog

func (t *TestTrace) LazyLog(x fmt.Stringer, sensitive bool)

func (*TestTrace) LazyPrintf

func (t *TestTrace) LazyPrintf(format string, a ...interface{})

func (*TestTrace) SetError

func (t *TestTrace) SetError()

func (*TestTrace) SetMaxEvents

func (t *TestTrace) SetMaxEvents(m int)

func (*TestTrace) SetRecycler

func (t *TestTrace) SetRecycler(f func(interface{}))

func (*TestTrace) SetTraceInfo

func (t *TestTrace) SetTraceInfo(traceID, spanID uint64)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL