rework framer tests

This commit is contained in:
Joel Wetzell
2025-12-24 19:13:04 -06:00
parent e679bf2b46
commit 25f2ec30c2
4 changed files with 176 additions and 5 deletions

View File

@@ -7,7 +7,7 @@ import (
"github.com/jwetzell/showbridge-go/internal/framer"
)
func TestGoodRawFramer(t *testing.T) {
func TestGoodRawFramerDecode(t *testing.T) {
tests := []struct {
name string
framer framer.Framer
@@ -16,7 +16,7 @@ func TestGoodRawFramer(t *testing.T) {
}{
{
name: "basic raw framer",
framer: framer.NewRawFramer(),
framer: framer.GetFramer("RAW"),
input: []byte("Hello\nWorld\nThis is a test\n"),
expected: [][]byte{
[]byte("Hello\nWorld\nThis is a test\n"),
@@ -38,3 +38,44 @@ func TestGoodRawFramer(t *testing.T) {
})
}
}
func TestGoodRawFramerEncode(t *testing.T) {
tests := []struct {
name string
framer framer.Framer
expected []byte
input []byte
}{
{
name: "basic raw framer",
framer: framer.GetFramer("RAW"),
expected: []byte("Hello\nWorld\nThis is a test\n"),
input: []byte("Hello\nWorld\nThis is a test\n"),
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
frame := test.framer.Encode(test.input)
if len(frame) != len(test.expected) {
t.Errorf("raw framer got %d frames, expected %d", len(frame), len(test.expected))
}
if !slices.Equal(frame, test.expected) {
t.Errorf("raw frame got %s, expected %s", frame, test.expected)
}
})
}
}
func TestRawFramerBuffer(t *testing.T) {
framer := framer.GetFramer("RAW")
framer.Decode([]byte("Hello, World!"))
if !slices.Equal(framer.Buffer(), []byte{}) {
t.Errorf("raw framer buffer got %s, expected empty", framer.Buffer())
}
framer.Clear()
if !slices.Equal(framer.Buffer(), []byte{}) {
t.Errorf("raw framer buffer got %s, expected empty after clear", framer.Buffer())
}
}