Merge pull request #3 from jwetzell/chore/chunk-decoder-testing

add test case to check error scenario in chunk decoder
This commit is contained in:
2025-10-16 13:23:34 -05:00
committed by GitHub
+32 -1
View File
@@ -3,10 +3,11 @@ package decoders
import (
"fmt"
"reflect"
"strings"
"testing"
)
func TestChunkDecoding(t *testing.T) {
func TestGoodChunkDecoding(t *testing.T) {
testCases := []struct {
description string
bytes []byte
@@ -70,3 +71,33 @@ func TestChunkDecoding(t *testing.T) {
}
}
}
func TestBadChunkDecoding(t *testing.T) {
testCases := []struct {
description string
bytes []byte
errorShouldContain string
}{
{
description: "empty packet",
bytes: []byte{},
errorShouldContain: "must be at least 4 bytes",
},
}
for _, testCase := range testCases {
_, err := DecodeChunk(testCase.bytes)
if err == nil {
t.Errorf("Test '%s' should have failed fail to decode chunk properly", testCase.description)
}
if !strings.Contains(err.Error(), testCase.errorShouldContain) {
t.Errorf("Test '%s' did not return the correct error", testCase.description)
fmt.Printf("expected: %v\n", testCase.errorShouldContain)
fmt.Printf("actual: %v\n", err.Error())
}
}
}