Help us shape the future of Go! Take the 2026 Go Developer Survey

dnsproxytest

package
v0.86.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package dnsproxytest provides utilities for testing dnsproxy module.

Index

Constants

View Source
const (
	// Timeout is the common timeout for tests and contexts.
	Timeout = 1 * time.Second

	// CacheSize is the default size of the cache in bytes.
	CacheSize = 64 * 1024

	// MessageCount is the default number of messages used in tests requiring
	// multiple DNS requests.
	MessageCount = 10

	// TLSServerName is a common TLS server name value for tests.
	TLSServerName = "testdns.adguard.com"

	// Host is a common host for tests.
	Host = "test.example"

	// TTL is a common time-to-live value in seconds for tests.
	TTL = 300
)

Variables

View Source
var (
	// LocalhostAnyPort is a [netip.AddrPort] having a value of 127.0.0.1:0.
	LocalhostAnyPort = netip.AddrPortFrom(netutil.IPv4Localhost(), 0)

	// IPv4 is a common IPv4 address for tests.
	IPv4 = net.IPv4(192, 0, 2, 1)
)
View Source
var DefaultTrustedProxies = netutil.SliceSubnetSet{
	netip.MustParsePrefix("0.0.0.0/0"),
	netip.MustParsePrefix("::/0"),
}

DefaultTrustedProxies is a set of trusted proxies that includes all possible IP addresses.

Functions

func NewTLSConfig added in v0.85.0

func NewTLSConfig(tb testing.TB) (conf *tls.Config, certPem []byte)

NewTLSConfig is a test helper that generates new TLS config.

func NewTestRequest added in v0.85.0

func NewTestRequest() (msg *dns.Msg)

NewTestRequest returns common DNS request for tests. This helper must not be used in IPv6-related tests.

func NewTestRequestWithHost added in v0.85.0

func NewTestRequestWithHost(host string) (req *dns.Msg)

NewTestRequestWithHost returns DNS request with common values and given host. This helper must not be used in IPv6-related tests.

func NewTestResponse added in v0.85.0

func NewTestResponse(req *dns.Msg) (resp *dns.Msg)

NewTestResponse is a helper that returns new default response for given request. Response will contain single A record with IPv4 value. req must not be nil. This helper must not be used in IPv6-related tests.

func RequireResponse added in v0.85.0

func RequireResponse(tb testing.TB, req, reply *dns.Msg)

RequireResponse is a test helper that ensures that the DNS reply matches the request and contains an A record with IPv4. It is intended to be used alongside NewTestRequest or NewTestRequestWithHost. This helper must not be used in IPv6-related tests.

Types

This section is empty.

Jump to

Keyboard shortcuts

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