Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is a fake DNS server that can be used to override DNS resolution in tests. This is particularly useful for testing components that rely on DNS without needing to set up an actual DNS server. The server can be configured with a map of domain names to IP addresses, and it will respond to DNS queries accordingly. To use the fake DNS server, create an instance using NewServer, then call Hijack to redirect DNS queries to the fake server. This helper does not support running tests in parallel.
func NewServer ¶
NewServer creates a new fake DNS server. The hosts map should contain domain names as keys and their corresponding IP addresses as string values. It returns an error if any of the IP addresses are invalid.
func (*Server) Hijack ¶
Hijack takes control of the net.DefaultResolver to redirect DNS queries to the fake server. It uses t.Cleanup to automatically restore the original resolver after the test. This helper does not support running tests in parallel.
Example:
dnsServer, _ := fakedns.NewServer(hosts) dnsServer.Hijack(t)