Documentation
¶
Overview ¶
Package dnstest allows for easy testing of DNS client against a test server.
Index ¶
- Constants
- func A(rr string) *dns.A
- func AAAA(rr string) *dns.AAAA
- func CAA(rr string) *dns.CAA
- func CNAME(rr string) *dns.CNAME
- func CNAMEOrder(res *dns.Msg) error
- func DNAME(rr string) *dns.DNAME
- func DNSKEY(rr string) *dns.DNSKEY
- func DS(rr string) *dns.DS
- func HINFO(rr string) *dns.HINFO
- func Header(tc Case, resp *dns.Msg) error
- func MX(rr string) *dns.MX
- func NS(rr string) *dns.NS
- func NSEC(rr string) *dns.NSEC
- func OPT(bufsize int, do bool) *dns.OPT
- func PTR(rr string) *dns.PTR
- func RRSIG(rr string) *dns.RRSIG
- func SOA(rr string) *dns.SOA
- func SRV(rr string) *dns.SRV
- func Section(tc Case, sec sect, rr []dns.RR) error
- func SortAndCheck(resp *dns.Msg, tc Case) error
- func TLSA(rr string) *dns.TLSA
- func TXT(rr string) *dns.TXT
- type Case
- type Handler
- type HandlerFunc
- type RRSet
- type Recorder
- type ResponseWriter
- func (t *ResponseWriter) Close() error
- func (t *ResponseWriter) Hijack()
- func (t *ResponseWriter) LocalAddr() net.Addr
- func (t *ResponseWriter) RemoteAddr() net.Addr
- func (t *ResponseWriter) TsigStatus() error
- func (t *ResponseWriter) TsigTimersOnly(bool)
- func (t *ResponseWriter) Write(buf []byte) (int, error)
- func (t *ResponseWriter) WriteMsg(m *dns.Msg) error
- type ResponseWriter6
Constants ¶
const ( // Answer is the answer section in an Msg. Answer sect = iota // Ns is the authoritative section in an Msg. Ns // Extra is the additional section in an Msg. Extra )
Variables ¶
This section is empty.
Functions ¶
func CNAMEOrder ¶
CNAMEOrder makes sure that CNAMES do not appear after their target records
func SortAndCheck ¶
SortAndCheck sorts resp and the checks the header and three sections against the testcase in tc.
Types ¶
type Case ¶
type Case struct { Desc string Qname string Qtype uint16 Rcode int Do bool Answer []dns.RR Ns []dns.RR Extra []dns.RR Error error }
Case represents a test case that encapsulates various data from a query and response. Note that is the TTL of a record is 303 we don't compare it with the TTL.
type Handler ¶
type Handler interface { ServeDNS(context.Context, dns.ResponseWriter, *dns.Msg) (int, error) Name() string }
Handler interface defines a plugin.
func ErrorHandler ¶
func ErrorHandler() Handler
ErrorHandler returns a Handler that returns ServerFailure error when called.
func NextHandler ¶
NextHandler returns a Handler that returns rcode and err.
type HandlerFunc ¶
HandlerFunc is a convenience type like dns.HandlerFunc, except ServeDNS returns an rcode and an error.
type Recorder ¶
Recorder is a type of ResponseWriter that captures the rcode code written to it and also the size of the message written in the response. A rcode code does not have to be written, however, in which case 0 must be assumed. It is best to have the constructor initialize this type with that default status code.
func NewRecorder ¶
func NewRecorder(w dns.ResponseWriter) *Recorder
NewRecorder makes and returns a new Recorder, which captures the DNS rcode from the ResponseWriter and also the length of the response message written through it.
type ResponseWriter ¶
type ResponseWriter struct {
TCP bool // if TCP is true we return an TCP connection instead of an UDP one.
}
ResponseWriter is useful for writing tests. It uses some fixed values for the client. The remote will always be 10.240.0.1 and port 40212. The local address is always 127.0.0.1 and port 53.
func (*ResponseWriter) Close ¶
func (t *ResponseWriter) Close() error
Close implement dns.ResponseWriter interface.
func (*ResponseWriter) Hijack ¶
func (t *ResponseWriter) Hijack()
Hijack implement dns.ResponseWriter interface.
func (*ResponseWriter) LocalAddr ¶
func (t *ResponseWriter) LocalAddr() net.Addr
LocalAddr returns the local address, 127.0.0.1:53 (UDP, TCP if t.TCP is true).
func (*ResponseWriter) RemoteAddr ¶
func (t *ResponseWriter) RemoteAddr() net.Addr
RemoteAddr returns the remote address, always 10.240.0.1:40212 (UDP, TCP is t.TCP is true).
func (*ResponseWriter) TsigStatus ¶
func (t *ResponseWriter) TsigStatus() error
TsigStatus implement dns.ResponseWriter interface.
func (*ResponseWriter) TsigTimersOnly ¶
func (t *ResponseWriter) TsigTimersOnly(bool)
TsigTimersOnly implement dns.ResponseWriter interface.
type ResponseWriter6 ¶
type ResponseWriter6 struct {
ResponseWriter
}
ResponseWriter6 returns fixed client and remote address in IPv6. The remote address is always fe80::42:ff:feca:4c65 and port 40212. The local address is always ::1 and port 53.
func (*ResponseWriter6) LocalAddr ¶
func (t *ResponseWriter6) LocalAddr() net.Addr
LocalAddr returns the local address, always ::1, port 53 (UDP, TCP is t.TCP is true).
func (*ResponseWriter6) RemoteAddr ¶
func (t *ResponseWriter6) RemoteAddr() net.Addr
RemoteAddr returns the remote address, always fe80::42:ff:feca:4c65 port 40212 (UDP, TCP is t.TCP is true).