From 43f5cb9d2792d0a16cefd1563ea44bdac51395e0 Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Fri, 5 Oct 2012 09:49:31 +0200 Subject: [PATCH] add test --- parse_test.go | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/parse_test.go b/parse_test.go index a202b9b3..ca9fc514 100644 --- a/parse_test.go +++ b/parse_test.go @@ -3,7 +3,9 @@ package dns import ( "crypto/rsa" "fmt" + "net" "os" + "strconv" "strings" "testing" "time" @@ -584,3 +586,42 @@ func ExampleGenerate() { } } } + +func TestSRVPacking(t *testing.T) { + msg := Msg{} + + things := []string{"1.2.3.4:8484", + "45.45.45.45:8484", + "84.84.84.84:8484", + } + + for i, n := range things { + h, p, err := net.SplitHostPort(n) + if err != nil { + continue + } + port := 8484 + tmp, err := strconv.Atoi(p) + if err == nil { + port = tmp + } + + rr := &RR_SRV{ + Hdr: RR_Header{Name: "somename.", + Rrtype: TypeSRV, + Class: ClassINET, + Ttl: 5}, + Priority: uint16(i), + Weight: 5, + Port: uint16(port), + Target: h + ".", + } + + msg.Answer = append(msg.Answer, rr) + } + + _, ok := msg.Pack() + if !ok { + t.Fatalf("Couldn't pack %v\n", msg) + } +}