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

dnstest

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package dnstest runs an in-process DNS server for tests, so code that resolves names goes through a real *net.Resolver (NXDOMAIN, SERVFAIL, multi-string TXT) instead of a hand-built stub.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Resolver

func Resolver(tb testing.TB, zones map[string]mockdns.Zone) *net.Resolver

Resolver serves zones (keys are fully qualified, with the trailing dot) and returns a *net.Resolver wired to the server; the server stops with the test. A name outside every zone answers NXDOMAIN; a zone with Err set answers SERVFAIL.

Types

type Zone

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

Zone is an in-process DNS server whose TXT records a test edits while it runs, so a test publishes and withdraws a record (a Join domain's proof) between two calls of the code under test. Each Zone is its own server, so tests never share records.

func NewZone

func NewZone(tb testing.TB) *Zone

NewZone starts an empty zone: every name answers NXDOMAIN until a record is published. The server stops with the test.

func (*Zone) LookupTXT

func (z *Zone) LookupTXT(ctx context.Context, name string) ([]string, error)

LookupTXT resolves through the zone's server; it satisfies sending.TXTLookup.

func (*Zone) PublishTXT

func (z *Zone) PublishTXT(tb testing.TB, name, value string)

PublishTXT adds a TXT record with value at name (no trailing dot needed).

func (*Zone) WithdrawTXT

func (z *Zone) WithdrawTXT(name string)

WithdrawTXT removes every TXT record at name.

Jump to

Keyboard shortcuts

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