43 lines
611 B
Go
43 lines
611 B
Go
package node
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestPacketPing(t *testing.T) {
|
|
sharedKey := make([]byte, 32)
|
|
rand.Read(sharedKey)
|
|
|
|
buf := make([]byte, bufferSize)
|
|
|
|
p := newPingPacket(sharedKey)
|
|
out := p.Marshal(buf)
|
|
|
|
p2, err := parsePingPacket(out)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if !reflect.DeepEqual(p, p2) {
|
|
t.Fatal(p, p2)
|
|
}
|
|
}
|
|
|
|
func TestPacketPong(t *testing.T) {
|
|
buf := make([]byte, bufferSize)
|
|
|
|
p := newPongPacket(123566)
|
|
out := p.Marshal(buf)
|
|
|
|
p2, err := parsePongPacket(out)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if !reflect.DeepEqual(p, p2) {
|
|
t.Fatal(p, p2)
|
|
}
|
|
}
|