dnstest

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package dnstest provides a configurable DNS server simulator for tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Key

func Key(name string, qtype uint16) string

Key returns a map key for the given question name and type.

Types

type Response

type Response struct {
	// Msg is sent as the response if non-nil. The Question and Id are set from
	// the incoming request before sending.
	Msg *dns.Msg
	// Rcode is used if Msg is nil to set the reply code in the generated
	// message. Defaults to RcodeSuccess.
	Rcode int
	// Raw is written directly on the wire instead of Msg/Rcode allowing
	// responses with malformed DNS packets.
	Raw []byte
	// Drop causes the server to ignore the request simulating a timeout.
	Drop bool
	// Delay adds an optional delay before processing the response.
	Delay time.Duration
}

Response defines how the server should answer a specific DNS question.

type Server

type Server struct {
	// Addr is the address the server is listening on.
	Addr string
	// contains filtered or unexported fields
}

Server simulates a DNS server for use in tests.

func NewServer

func NewServer(addr string, responses map[string]Response) (*Server, error)

NewServer starts a new DNS server on addr serving the provided responses. The same address and port are used for both UDP and TCP. If the port in addr is "0" an available port will be chosen automatically.

func (*Server) Close

func (s *Server) Close()

Close shuts down the server.

Jump to

Keyboard shortcuts

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