More tests lenght

This commit is contained in:
Miek Gieben 2014-02-10 12:29:33 +00:00
parent 56e0bb46d8
commit 372e3d55c3
1 changed files with 34 additions and 2 deletions

View File

@ -208,8 +208,8 @@ func TestCompressLength(t *testing.T) {
}
}
// Does the predicted length match final packed length
func TestMsgLenTest(t *testing.T) {
// Does the predicted length match final packed length?
func TestMsgCompressLenTest(t *testing.T) {
makeMsg := func(question string, ans, ns, e []RR) *Msg {
msg := new(Msg)
msg.SetQuestion(Fqdn(question), TypeANY)
@ -242,6 +242,38 @@ func TestMsgLenTest(t *testing.T) {
}
}
func TestMsgLenTest(t *testing.T) {
makeMsg := func(question string, ans, ns, e []RR) *Msg {
msg := new(Msg)
msg.SetQuestion(Fqdn(question), TypeANY)
msg.Answer = append(msg.Answer, ans...)
msg.Ns = append(msg.Ns, ns...)
msg.Extra = append(msg.Extra, e...)
return msg
}
name1 := "12345678901234567890123456789012345.12345678.123."
rrA, _ := NewRR(name1 + " 3600 IN A 192.0.2.1")
rrMx, _ := NewRR(name1 + " 3600 IN MX 10 " + name1)
tests := []*Msg{
makeMsg(name1, []RR{rrA}, nil, nil),
makeMsg(name1, []RR{rrMx, rrMx}, nil, nil)}
for _, msg := range tests {
predicted := msg.Len()
buf, err := msg.Pack()
if err != nil {
t.Error(err)
t.Fail()
}
if predicted != len(buf) {
t.Errorf("Predicted length is wrong: predicted %s (len=%d) %d, actual %d\n",
msg.Question[0].Name, len(msg.Answer), predicted, len(buf))
t.Fail()
}
}
}
func BenchmarkMsgLen(b *testing.B) {
b.StopTimer()
makeMsg := func(question string, ans, ns, e []RR) *Msg {