Add tests for TXT record serialization

This commit is contained in:
Marc Capdevielle 2013-06-06 11:18:09 +02:00
parent 795a69a6ec
commit 7c80a7202f
1 changed files with 47 additions and 0 deletions

47
pack_test.go Normal file
View File

@ -0,0 +1,47 @@
package dns
import (
"testing"
)
func TestTxtPack(t *testing.T) {
// Test single entry TXT record
rr, err := NewRR(`_raop._tcp.local. 60 IN TXT "single value"`)
if err != nil {
t.Error("Failed to parse single value TXT record", err)
} else if rr, ok := rr.(*TXT); !ok {
t.Error("Wrong type, record should be of type TXT")
} else {
if len(rr.Txt) != 1 {
t.Error("Bad size of TXT value:", len(rr.Txt))
} else if rr.Txt[0] != "single value" {
t.Error("Bad single value")
}
if rr.String() != `_raop._tcp.local. 60 IN TXT "single value"` {
t.Error("Bad representation of TXT record:", rr.String())
}
if rr.len() == 10 {
t.Error("Bad size of serialized record:", rr.len())
}
}
// Test multi entries TXT record
rr, err = NewRR(`_raop._tcp.local. 60 IN TXT "a=1" "b=2" "c=3" "d=4"`)
if err != nil {
t.Error("Failed to parse multi-values TXT record", err)
} else if rr, ok := rr.(*TXT); !ok {
t.Error("Wrong type, record should be of type TXT")
} else {
if len(rr.Txt) != 4 {
t.Error("Bad size of TXT multi-value:", len(rr.Txt))
} else if rr.Txt[0] != "a=1" || rr.Txt[1] != "b=2" || rr.Txt[2] != "c=3" || rr.Txt[3] != "d=4" {
t.Error("Bad values in TXT records")
}
if rr.String() != `_raop._tcp.local. 60 IN TXT "a=1" "b=2" "c=3" "d=4"` {
t.Error("Bad representation of TXT multi value record:", rr.String())
}
if rr.len() != 43 {
t.Error("Bad size of serialized multi value record:", rr.len())
}
}
}