mirror of
https://github.com/jwetzell/psn-go.git
synced 2026-09-02 12:59:12 +00:00
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:
@@ -3,10 +3,11 @@ package decoders
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestChunkDecoding(t *testing.T) {
|
func TestGoodChunkDecoding(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
description string
|
description string
|
||||||
bytes []byte
|
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())
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user