add tests for decoding packet header chunk

This commit is contained in:
2025-10-17 12:34:27 -05:00
parent 4c508c37f3
commit a0ba854fee
@@ -0,0 +1,51 @@
package decoders
import (
"fmt"
"reflect"
"testing"
)
func TestGoodPacketHeaderChunkDecoding(t *testing.T) {
testCases := []struct {
description string
bytes []byte
expected PacketHeaderChunk
}{
{
description: "PacketHeaderChunk",
bytes: []byte{
0, 0, 12, 0, 210, 2, 150, 73, 0, 0, 0, 0, 2, 3, 1, 123,
},
expected: PacketHeaderChunk{
Chunk: Chunk{
ChunkData: []byte{210, 2, 150, 73, 0, 0, 0, 0, 2, 3, 1, 123},
Header: ChunkHeader{DataLen: 12, Id: 0, HasSubchunks: false},
},
Data: PacketHeaderChunkData{
PacketTimestamp: 1234567890,
VersionHigh: 2,
VersionLow: 3,
FrameId: 1,
FramePacketCount: 123,
},
},
},
}
for _, testCase := range testCases {
actual, err := DecodePacketHeaderChunk(testCase.bytes)
if err != nil {
t.Errorf("Test '%s' failed to decode chunk properly", testCase.description)
fmt.Println(err)
}
if !reflect.DeepEqual(actual, testCase.expected) {
t.Errorf("Test '%s' failed to decode chunk properly", testCase.description)
fmt.Printf("expected: %+v\n", testCase.expected)
fmt.Printf("actual: %+v\n", actual)
}
}
}