Added test to Packets and more

This commit is contained in:
Pablu23
2023-12-06 17:13:37 +01:00
parent 38876f6577
commit 5ccd83c9da
7 changed files with 68 additions and 7 deletions

View File

@@ -0,0 +1,29 @@
package common
import (
"testing"
"github.com/google/go-cmp/cmp"
)
func TestPacketFromBytes(t *testing.T) {
sid := [8]byte{255, 255, 255, 255, 255, 255, 255, 255}
data := []byte{1, 0, 1}
dataLength := len(data)
want := Packet{
Flag: Request,
Sync: 0,
Data: data,
Sid: sid,
DataLength: uint32(dataLength),
}
bytes := []byte{0, 0, 0, 0, 0, 1, 0, 1}
pck := PacketFromBytes(bytes, uint32(dataLength), sid)
if !cmp.Equal(pck, want) {
t.Fail()
}
}