testutil

package
v0.0.0-...-da8986d Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2024 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 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.

Jump to

Keyboard shortcuts

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