aghtest

package
v0.107.11 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2022 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package aghtest contains utilities for testing.

Index

Constants

View Source
const ErrUpstream errors.Error = "test upstream error"

ErrUpstream is the error returned from the *UpstreamMock created by NewErrorUpstream.

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.TB, l log.Level)

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

func ReplaceLogWriter

func ReplaceLogWriter(t testing.TB, w io.Writer)

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

func RespondTo added in v0.107.10

func RespondTo(t testing.TB, req *dns.Msg, cl, qt uint16, targ, answer string) (resp *dns.Msg)

RespondTo returns a response with answer if req has class cl, question type qt, and target targ.

Types

type FS added in v0.107.0

type FS struct {
	OnOpen func(name string) (fs.File, error)
}

FS is a mock fs.FS implementation for tests.

func (*FS) Open added in v0.107.0

func (fsys *FS) Open(name string) (fs.File, error)

Open implements the fs.FS interface for *FS.

type FSWatcher added in v0.107.0

type FSWatcher struct {
	OnEvents func() (e <-chan struct{})
	OnAdd    func(name string) (err error)
	OnClose  func() (err error)
}

FSWatcher is a mock aghos.FSWatcher implementation for tests.

func (*FSWatcher) Add added in v0.107.0

func (w *FSWatcher) Add(name string) (err error)

Add implements the aghos.FSWatcher interface for *FSWatcher.

func (*FSWatcher) Close added in v0.107.0

func (w *FSWatcher) Close() (err error)

Close implements the aghos.FSWatcher interface for *FSWatcher.

func (*FSWatcher) Events added in v0.107.0

func (w *FSWatcher) Events() (e <-chan struct{})

Events implements the aghos.FSWatcher interface for *FSWatcher.

type GlobFS added in v0.107.0

type GlobFS struct {
	// FS is embedded here to avoid implementing all it's methods.
	FS
	OnGlob func(pattern string) ([]string, error)
}

GlobFS is a mock fs.GlobFS implementation for tests.

func (*GlobFS) Glob added in v0.107.0

func (fsys *GlobFS) Glob(pattern string) ([]string, error)

Glob implements the fs.GlobFS interface for *GlobFS.

type Listener added in v0.107.10

type Listener struct {
	OnAccept func() (conn net.Conn, err error)
	OnAddr   func() (addr net.Addr)
	OnClose  func() (err error)
}

Listener is a mock net.Listener implementation for tests.

func (*Listener) Accept added in v0.107.10

func (l *Listener) Accept() (conn net.Conn, err error)

Accept implements the net.Listener interface for *Listener.

func (*Listener) Addr added in v0.107.10

func (l *Listener) Addr() (addr net.Addr)

Addr implements the net.Listener interface for *Listener.

func (*Listener) Close added in v0.107.10

func (l *Listener) Close() (err error)

Close implements the net.Listener interface for *Listener.

type StatFS added in v0.107.0

type StatFS struct {
	// FS is embedded here to avoid implementing all it's methods.
	FS
	OnStat func(name string) (fs.FileInfo, error)
}

StatFS is a mock fs.StatFS implementation for tests.

func (*StatFS) Stat added in v0.107.0

func (fsys *StatFS) Stat(name string) (fs.FileInfo, error)

Stat implements the fs.StatFS interface for *StatFS.

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 Upstream added in v0.107.7

type Upstream 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
}

Upstream is a mock implementation of upstream.Upstream.

TODO(a.garipov): Replace with UpstreamMock and rename it to just Upstream.

func (*Upstream) Address added in v0.107.7

func (u *Upstream) Address() string

Address implements upstream.Upstream interface for *Upstream.

func (*Upstream) Exchange added in v0.107.7

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

Exchange implements the upstream.Upstream interface for *Upstream.

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

type UpstreamMock added in v0.107.10

type UpstreamMock struct {
	OnAddress  func() (addr string)
	OnExchange func(req *dns.Msg) (resp *dns.Msg, err error)
}

UpstreamMock is a mock upstream.Upstream implementation for tests.

TODO(a.garipov): Replace with all uses of Upstream with UpstreamMock and rename it to just Upstream.

func NewBlockUpstream added in v0.107.10

func NewBlockUpstream(hostname string, shouldBlock bool) (u *UpstreamMock)

NewBlockUpstream returns an *UpstreamMock that works like an upstream that supports hash-based safe-browsing/adult-blocking feature. If shouldBlock is true, hostname's actual hash is returned, blocking it. Otherwise, it returns a different hash.

func NewErrorUpstream added in v0.107.10

func NewErrorUpstream() (u *UpstreamMock)

NewErrorUpstream returns an *UpstreamMock that returns ErrUpstream from its Exchange method.

func (*UpstreamMock) Address added in v0.107.10

func (u *UpstreamMock) Address() (addr string)

Address implements the upstream.Upstream interface for *UpstreamMock.

func (*UpstreamMock) Exchange added in v0.107.10

func (u *UpstreamMock) Exchange(req *dns.Msg) (resp *dns.Msg, err error)

Exchange implements the upstream.Upstream interface for *UpstreamMock.

Jump to

Keyboard shortcuts

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