diff --git a/client_test.go b/broken/client_test.go similarity index 100% rename from client_test.go rename to broken/client_test.go diff --git a/server_test.go b/broken/server_test.go similarity index 100% rename from server_test.go rename to broken/server_test.go diff --git a/dyn_test.go b/dyn_test.go new file mode 100644 index 00000000..d634ba89 --- /dev/null +++ b/dyn_test.go @@ -0,0 +1,58 @@ +package dns + +import ( + "net" + "testing" +) + +func sendit(u *Msg) (r *Msg, e error) { + c := NewClient() + r, e = c.Exchange(u, "127.0.0.1:53") + return r, e +} + +func TestUpdateAdd(t *testing.T) { + u := NewUpdate("dyn.atoom.net.", ClassINET) + a := new(RR_A) + a.Hdr = RR_Header{"miek2.dyn.atoom.net.", TypeA, ClassINET, 1000, 0} + a.A = net.IPv4(127, 0, 0, 1) + rr := make([]RR, 1) + rr[0] = a + u.RRsetAddRdata(rr) + t.Log(u.String()) + + r, e := sendit(u) + if e != nil { + t.Log("Failed: " + e.Error()) + t.Fail() + } + if r != nil && r.Rcode != RcodeSuccess { + t.Log("Failed: " + r.String()) + t.Fail() + } + t.Log(r.String()) +} + +func TestUpdateDelete(t *testing.T) { + u := NewUpdate("dyn.atoom.net.", ClassINET) + a := new(RR_A) + a.Hdr = RR_Header{"miek2.dyn.atoom.net.", TypeA, ClassINET, 1000, 0} + a.A = nil + rr := make([]RR, 1) + rr[0] = a + u.RRsetDelete(rr) + t.Log(u.String()) + + r, e := sendit(u) + if e != nil { + t.Log("Failed: " + e.Error()) + t.Fail() + return + } + if r != nil && r.Rcode != RcodeSuccess { + t.Log("Failed: " + r.String()) + t.Fail() + return + } + t.Log(r.String()) +} diff --git a/parse_test.go b/parse_test.go index 8d24bc99..b4107365 100644 --- a/parse_test.go +++ b/parse_test.go @@ -77,7 +77,7 @@ Activate: 20110302104537` func TestDotInName(t *testing.T) { buf := make([]byte, 20) - packDomainName("aa\\.bb.nl.", buf, 0) + PackDomainName("aa\\.bb.nl.", buf, 0) // index 3 must be a real dot if buf[3] != '.' { t.Log("Dot should be a real dot") @@ -88,7 +88,7 @@ func TestDotInName(t *testing.T) { t.Log("This must have the value 2") t.Fail() } - dom, _, _ := unpackDomainName(buf, 0) + dom, _, _ := UnpackDomainName(buf, 0) // printing it should yield the backspace again if dom != "aa\\.bb.nl." { t.Log("Dot should have been escaped: " + dom) diff --git a/update.go b/update.go index 363e6926..83a31196 100644 --- a/update.go +++ b/update.go @@ -50,9 +50,10 @@ func (u *Msg) Additional() []RR { return u.Extra } -// NewUpdate creats a new DNS update packet. +// NewUpdate creates a new DNS update packet, which is a normal DNS message. func NewUpdate(zone string, class uint16) *Msg { u := new(Msg) + u.MsgHdr.Response = false u.MsgHdr.Opcode = OpcodeUpdate u.Question = make([]Question, 1) u.Question[0] = Question{zone, TypeSOA, class}