aghtest

package
v0.107.0-b.7 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2021 License: GPL-3.0 Imports: 13 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 ReplaceLogLevel

func ReplaceLogLevel(t *testing.T, l log.Level)

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 Exchanger added in v0.106.0

type Exchanger struct {
	Ups upstream.Upstream
}

Exchanger is a mock aghnet.Exchanger implementation for tests.

func (*Exchanger) Exchange added in v0.106.0

func (e *Exchanger) Exchange(req *dns.Msg) (resp *dns.Msg, err error)

Exchange implements aghnet.Exchanger interface for *Exchanger.

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 {
	// The error returned by Exchange may be unwraped to the Err.
	Err error
}

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.

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) LookupIP added in v0.106.0

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

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

type TestUpstream

type TestUpstream struct {
	// 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
	// Addr is the address for Address method.
	Addr 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.

TODO(a.garipov): Split further into handlers.

Jump to

Keyboard shortcuts

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