Add byte packing/unpacking test
This commit is contained in:
parent
3d5407e128
commit
ce1812cfaf
|
@ -1477,3 +1477,32 @@ func TestParseCAA(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPackCAA(t *testing.T) {
|
||||||
|
m := new(Msg)
|
||||||
|
record := new(CAA)
|
||||||
|
record.Hdr = RR_Header{Name: "example.com.", Rrtype: TypeCAA, Class: ClassINET, Ttl: 0}
|
||||||
|
record.Tag = "issue"
|
||||||
|
record.Value = "symantec.com"
|
||||||
|
record.Flag = 1
|
||||||
|
|
||||||
|
m.Answer = append(m.Answer, record)
|
||||||
|
bytes, err := m.Pack()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to pack msg: %v", err)
|
||||||
|
}
|
||||||
|
if err := m.Unpack(bytes); err != nil {
|
||||||
|
t.Fatalf("failed to unpack msg: %v", err)
|
||||||
|
}
|
||||||
|
if len(m.Answer) != 1 {
|
||||||
|
t.Fatalf("incorrect number of answers unpacked")
|
||||||
|
}
|
||||||
|
rr := m.Answer[0].(*CAA)
|
||||||
|
if rr.Tag != "issue" {
|
||||||
|
t.Fatalf("invalid tag for unpacked answer")
|
||||||
|
} else if rr.Value != "symantec.com" {
|
||||||
|
t.Fatalf("invalid value for unpacked answer")
|
||||||
|
} else if rr.Flag != 1 {
|
||||||
|
t.Fatalf("invalid flag for unpacked answer")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue