dnsproxytest

package
v0.82.0 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package dnsproxytest provides a set of test utilities for the dnsproxy module.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewFreePort added in v0.82.0

func NewFreePort(tb testing.TB) (p uint)

NewFreePort is a best-effort helper function that returns a free TCP port that can be used for testing. Note that there is theoretically a TOCTTOU race here: the port may be reoccupied between the time it is released and the time the caller binds to it.

Types

type MessageConstructor

type MessageConstructor struct {
	OnNewMsgNXDOMAIN       func(req *dns.Msg) (resp *dns.Msg)
	OnNewMsgSERVFAIL       func(req *dns.Msg) (resp *dns.Msg)
	OnNewMsgNOTIMPLEMENTED func(req *dns.Msg) (resp *dns.Msg)
	OnNewMsgNODATA         func(req *dns.Msg) (resp *dns.Msg)
	OnNewMsgFORMERR        func(req *dns.Msg) (resp *dns.Msg)
}

MessageConstructor is a mock dnsmsg.MessageConstructor implementation for tests.

func NewMessageConstructor

func NewMessageConstructor() (c *MessageConstructor)

NewMessageConstructor creates a new *TestMessageConstructor with all it's methods set to panic.

func (*MessageConstructor) NewMsgFORMERR added in v0.82.0

func (c *MessageConstructor) NewMsgFORMERR(req *dns.Msg) (resp *dns.Msg)

NewMsgFORMERR implements the [proxy.MessageConstructor] interface for *MessageConstructor.

func (*MessageConstructor) NewMsgNODATA

func (c *MessageConstructor) NewMsgNODATA(req *dns.Msg) (resp *dns.Msg)

NewMsgNODATA implements the [proxy.MessageConstructor] interface for *MessageConstructor.

func (*MessageConstructor) NewMsgNOTIMPLEMENTED

func (c *MessageConstructor) NewMsgNOTIMPLEMENTED(req *dns.Msg) (resp *dns.Msg)

NewMsgNOTIMPLEMENTED implements the [proxy.MessageConstructor] interface for *MessageConstructor.

func (*MessageConstructor) NewMsgNXDOMAIN

func (c *MessageConstructor) NewMsgNXDOMAIN(req *dns.Msg) (resp *dns.Msg)

NewMsgNXDOMAIN implements the [proxy.MessageConstructor] interface for *MessageConstructor.

func (*MessageConstructor) NewMsgSERVFAIL

func (c *MessageConstructor) NewMsgSERVFAIL(req *dns.Msg) (resp *dns.Msg)

NewMsgSERVFAIL implements the [proxy.MessageConstructor] interface for *MessageConstructor.

type Upstream

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

Upstream is a mock upstream.Upstream implementation for tests.

TODO(e.burkov): Move to golibs.

func (*Upstream) Address

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

Address implements the upstream.Upstream interface for *Upstream.

func (*Upstream) Close

func (u *Upstream) Close() (err error)

Close implements the upstream.Upstream interface for *Upstream.

func (*Upstream) Exchange

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

Exchange implements the upstream.Upstream interface for *Upstream.

Jump to

Keyboard shortcuts

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