dns/resolverEdns_test.go

46 lines
931 B
Go

package dns
import (
"testing"
)
func TestResolverEdns(t *testing.T) {
res := new(Resolver)
ch := NewQuerier(res)
res.Servers = []string{"127.0.0.1"}
res.Timeout = 2
res.Attempts = 1
m := new(Msg)
m.MsgHdr.Recursion_desired = true //only set this bit
m.Question = make([]Question, 1)
m.Ns = make([]RR, 1)
// Add EDNS rr
edns := new(RR_OPT)
edns.Hdr.Name = "." // must . be for edns
edns.Hdr.Rrtype = TypeOPT
edns.Hdr.Class = ClassINET
edns.Hdr.Ttl = 3600
// no options for now
// edns.Option = make([]Option, 1)
// edns.Option[0].Code = OptionCodeNSID
// edns.Option[0].Data = "lalalala"
// ask something
m.Question[0] = Question{"miek.nl", TypeSOA, ClassINET}
m.Ns[0] = edns
ch <- DnsMsg{m, nil}
in := <-ch
if in.Dns.Rcode != RcodeSuccess {
t.Logf("Recv: %v\n", in.Dns)
t.Log("Failed to get an valid answer")
t.Fail()
}
ch <- DnsMsg{nil, nil}
<-ch
}