mirror of
https://github.com/CPunch/gopenfusion.git
synced 2025-10-13 12:50:55 +00:00
swithed to blackbox testing
just because i am lazy
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
package protocol
|
||||
package protocol_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/CPunch/gopenfusion/internal/protocol"
|
||||
)
|
||||
|
||||
type TestPacketData struct {
|
||||
@@ -21,10 +23,23 @@ type TestPacketData struct {
|
||||
// UTF16Str: "hello world",
|
||||
// C: 3,
|
||||
// })
|
||||
var testData = [...]byte{0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x68, 0x00, 0x65, 0x00, 0x6c, 0x00, 0x6c, 0x00, 0x6f, 0x00, 0x20, 0x00, 0x77, 0x00, 0x6f, 0x00, 0x72, 0x00, 0x6c, 0x00, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00}
|
||||
var testData = [...]byte{
|
||||
0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
|
||||
0x68, 0x00, 0x65, 0x00, 0x6c, 0x00, 0x6c, 0x00,
|
||||
0x6f, 0x00, 0x20, 0x00, 0x77, 0x00, 0x6f, 0x00,
|
||||
0x72, 0x00, 0x6c, 0x00, 0x64, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
|
||||
}
|
||||
|
||||
func TestPacketEncodeDecode(t *testing.T) {
|
||||
pkt := NewPacket(&bytes.Buffer{})
|
||||
buf := &bytes.Buffer{}
|
||||
pkt := protocol.NewPacket(buf)
|
||||
|
||||
if err := pkt.Encode(TestPacketData{
|
||||
A: 1,
|
||||
B: 2,
|
||||
@@ -34,7 +49,7 @@ func TestPacketEncodeDecode(t *testing.T) {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if !bytes.Equal(pkt.readWriter.(*bytes.Buffer).Bytes(), testData[:]) {
|
||||
if !bytes.Equal(buf.Bytes(), testData[:]) {
|
||||
t.Error("packet data does not match!")
|
||||
}
|
||||
|
Reference in New Issue
Block a user