-
Notifications
You must be signed in to change notification settings - Fork 32
/
netmsg_test.go
41 lines (32 loc) · 648 Bytes
/
netmsg_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package kademlia
import (
"bytes"
"net"
"testing"
"github.com/stretchr/testify/assert"
)
func TestSerializeNetMsg(t *testing.T) {
netMsgInit()
var conn bytes.Buffer
node := newNode(&NetworkNode{})
id, _ := newID()
node.ID = id
node.Port = 3000
node.IP = net.ParseIP("0.0.0.0")
msg := &message{}
msg.Type = messageTypeFindNode
msg.Receiver = node.NetworkNode
msg.Data = &queryDataFindNode{
Target: id,
}
serialized, err := serializeMessage(msg)
if err != nil {
panic(err)
}
conn.Write(serialized)
deserialized, err := deserializeMessage(&conn)
if err != nil {
panic(err)
}
assert.Equal(t, msg, deserialized)
}