aghtest

package
v0.105.2 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2021 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

Package aghtest contains utilities for testing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DiscardLogOutput

func DiscardLogOutput(m *testing.M)

DiscardLogOutput runs tests with discarded logger output.

func PrepareTestDir

func PrepareTestDir(t *testing.T) (dir string)

PrepareTestDir returns the full path to temporary created directory and registers the appropriate cleanup for *t.

func ReplaceLogLevel

func ReplaceLogLevel(t *testing.T, l int)

ReplaceLogLevel sets logging level to l and uses Cleanup method of t to revert changes.

func ReplaceLogWriter

func ReplaceLogWriter(t *testing.T, w io.Writer)

ReplaceLogWriter moves logger output to w and uses Cleanup method of t to revert changes.

Types

type TestBlockUpstream

type TestBlockUpstream struct {
	Hostname string
	Block    bool
	// contains filtered or unexported fields
}

TestBlockUpstream implements upstream.Upstream interface for replacing real upstream in tests.

func (*TestBlockUpstream) Address

func (u *TestBlockUpstream) Address() string

Address always returns an empty string.

func (*TestBlockUpstream) Exchange

func (u *TestBlockUpstream) Exchange(r *dns.Msg) (*dns.Msg, error)

Exchange returns a message unique for TestBlockUpstream's Hostname-Block pair.

func (*TestBlockUpstream) RequestsCount

func (u *TestBlockUpstream) RequestsCount() int

RequestsCount returns the number of handled requests. It's safe for concurrent use.

type TestErrUpstream

type TestErrUpstream struct{}

TestErrUpstream implements upstream.Upstream interface for replacing real upstream in tests.

func (*TestErrUpstream) Address

func (u *TestErrUpstream) Address() string

Address always returns an empty string.

func (*TestErrUpstream) Exchange

func (u *TestErrUpstream) Exchange(*dns.Msg) (*dns.Msg, error)

Exchange always returns nil Msg and non-nil error.

type TestResolver

type TestResolver struct {
	// contains filtered or unexported fields
}

TestResolver is a Resolver for tests.

func (*TestResolver) Counter

func (r *TestResolver) Counter() int

Counter returns the number of requests handled.

func (*TestResolver) HostToIPs

func (r *TestResolver) HostToIPs(host string) (ipv4, ipv6 net.IP)

HostToIPs generates IPv4 and IPv6 from host.

TODO(e.burkov): Replace with LookupIP after upgrading go to v1.15.

func (*TestResolver) LookupHost

func (r *TestResolver) LookupHost(host string) (addrs []string, err error)

LookupHost implements Resolver interface for *testResolver. It returns the slice of IPv4 and IPv6 instances converted to strings.

func (*TestResolver) LookupIPAddr

func (r *TestResolver) LookupIPAddr(_ context.Context, host string) (ips []net.IPAddr, err error)

LookupIPAddr implements Resolver interface for *testResolver. It returns the slice of net.IPAddr with IPv4 and IPv6 instances.

type TestUpstream

type TestUpstream struct {
	// Addr is the address for Address method.
	Addr string
	// CName is a map of hostname to canonical name.
	CName map[string]string
	// IPv4 is a map of hostname to IPv4.
	IPv4 map[string][]net.IP
	// IPv6 is a map of hostname to IPv6.
	IPv6 map[string][]net.IP
	// Reverse is a map of address to domain name.
	Reverse map[string][]string
}

TestUpstream is a mock of real upstream.

func (*TestUpstream) Address

func (u *TestUpstream) Address() string

Address implements upstream.Upstream interface for *TestUpstream.

func (*TestUpstream) Exchange

func (u *TestUpstream) Exchange(m *dns.Msg) (resp *dns.Msg, err error)

Exchange implements upstream.Upstream interface for *TestUpstream.

Jump to

Keyboard shortcuts

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