Add unit tests for node encoding/decoding

This commit is contained in:
kaiyou 2020-05-07 11:52:50 +02:00 committed by Leo Antunes
parent 46da51b7aa
commit 622cfce1ad
1 changed files with 28 additions and 0 deletions

28
common/node_test.go Normal file
View File

@ -0,0 +1,28 @@
package common
import (
"net"
"reflect"
"testing"
)
func Test_Node_Encode_Decode(t *testing.T) {
pubKey := "abcdefghijklmnopkqstuvwxyzABCDEF"
_, ipv4, _ := net.ParseCIDR("10.0.0.1/32")
_, ipv6, _ := net.ParseCIDR("2001:db8::1/128")
for _, ip := range []*net.IPNet{ipv4, ipv6} {
node := Node{
nodeMeta: nodeMeta{
OverlayAddr: *ip,
PubKey: pubKey,
},
}
encoded, _ := node.Encode(1024)
new := Node{Meta: encoded}
new.Decode()
if !reflect.DeepEqual(node.nodeMeta, new.nodeMeta) {
t.Errorf("node encoding then decoding mismatch: %s / %s", node.nodeMeta, new.nodeMeta)
}
}
}