dns/pack_test.go

51 lines
925 B
Go
Raw Normal View History

2010-12-21 08:19:34 +11:00
package dns
import (
"testing"
"net"
)
2010-12-21 08:20:13 +11:00
func TestPackUnpack(t *testing.T) {
out := new(Msg)
r := new(RR_AAAA)
2010-12-21 08:19:34 +11:00
r.AAAA = net.ParseIP("2001:7b8:206:1:200:39ff:fe59:b187").To16()
2010-12-25 01:53:17 +11:00
r.Hdr = RR_Header{Name: "a.miek.nl", Rrtype: TypeAAAA, Class: ClassINET, Ttl: 3600}
2010-12-21 08:20:13 +11:00
out.Answer = make([]RR, 1)
2010-12-21 08:19:34 +11:00
out.Answer[0] = r
2010-12-21 08:20:13 +11:00
msg, ok := out.Pack()
2010-12-25 01:53:17 +11:00
if !ok {
2010-12-21 08:19:34 +11:00
t.Log("Failed to pack msg with AAAA")
t.Fail()
}
2010-12-21 08:20:13 +11:00
in := new(Msg)
2010-12-25 01:53:17 +11:00
if !in.Unpack(msg) {
2010-12-21 08:19:34 +11:00
t.Log("Failed to unpack msg with AAAA")
t.Fail()
}
2010-12-25 01:53:17 +11:00
edns := new(RR_OPT)
edns.Hdr.Name = "."
edns.Hdr.Rrtype = TypeOPT
edns.Hdr.Class = ClassINET
edns.Hdr.Ttl = 3600
edns.Option = make([]Option, 1)
edns.Option[0].Code = OptionCodeNSID
edns.Option[0].Data = "lalalala"
2010-12-22 22:26:50 +11:00
2010-12-25 01:53:17 +11:00
_, ok = packRR(edns, msg, 0)
if !ok {
t.Logf("%v\n", edns)
t.Log("Failed")
t.Fail()
}
2010-12-25 01:53:17 +11:00
unpacked, _, ok := unpackRR(msg, 0)
if !ok {
t.Logf("%v\n", unpacked)
t.Log("Failed")
t.Fail()
}
2010-12-21 08:19:34 +11:00
}