mirror of
https://github.com/gortc/stun.git
synced 2025-09-26 20:41:36 +08:00
message: add GobDecode test
This commit is contained in:
@@ -1037,3 +1037,32 @@ func TestMessage_MarshalBinary(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMessage_GobDecode(t *testing.T) {
|
||||
m := MustBuild(
|
||||
NewSoftware("software"),
|
||||
&XORMappedAddress{
|
||||
IP: net.IPv4(213, 1, 223, 5),
|
||||
},
|
||||
)
|
||||
data, err := m.GobEncode()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Reset m.Raw to check retention.
|
||||
for i := range m.Raw {
|
||||
m.Raw[i] = 0
|
||||
}
|
||||
if err := m.GobDecode(data); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Reset data to check retention.
|
||||
for i := range data {
|
||||
data[i] = 0
|
||||
}
|
||||
if err := m.Decode(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user