Add packet tests
1 files changed, 47 insertions(+), 0 deletions(-)

A => packet_test.go
A => packet_test.go +47 -0
@@ 0,0 1,47 @@ 
+package kgp
+
+import (
+	"bytes"
+	"testing"
+)
+
+func TestPacket(t *testing.T) {
+	var buf bytes.Buffer
+	var p = NewPacket()
+
+	p.header.ConnectionId = 1234
+	p.header.Sequence = 1234
+	p.header.Ack = 1234
+	p.header.Control = 1234
+	p.Payload = []byte("1234")
+	var n, err = p.WriteTo(&buf)
+	if err != nil {
+		t.Fatal(err.Error())
+	}
+
+	// check output
+	var expected = []byte{
+		0, 0, 4, 210, // ConnectionId
+		0, 0, 4, 210, // Sequence
+		0, 0, 4, 210, // Ack
+		4, 210, // Control
+		0, 4, // len == 4
+		49, 50, 51, 52,
+	}
+	if int(n) != len(expected) {
+		t.Fatalf("%d != %d", n, len(expected))
+	}
+	if !bytes.Equal(buf.Bytes(), expected) {
+		t.Fatalf("\n%d\n!=\n%d", buf.Bytes(), expected)
+	}
+
+	var other = NewPacket()
+	n, err = other.ReadFrom(&buf)
+	if err != nil {
+		t.Fatal(err.Error())
+	}
+
+	if int(n) != len(expected) {
+		t.Fatalf("%d != %d", n, len(expected))
+	}
+}