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) + } +}