Skip to content

Commit

Permalink
Test the framer.go sendData method (#817)
Browse files Browse the repository at this point in the history
  • Loading branch information
resoluteCoder authored Aug 15, 2023
1 parent 80b6e89 commit ff0ff07
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions pkg/framer/framer_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package framer_test

import (
"bytes"
"testing"

"github.com/ansible/receptor/pkg/framer"
)

func TestSendData(t *testing.T) {
f := framer.New()

smallBuffer := []byte{1, 2, 3, 4, 5, 6}
largeBuffer := []byte{}
for i := 1; i <= 271; i++ {
largeBuffer = append(largeBuffer, byte(i))
}

framedBufferTestCases := []struct {
name string
inputBuffer []byte
expectedBuffer []byte
}{
{
name: "small buffer",
inputBuffer: smallBuffer,
expectedBuffer: append([]byte{6, 0}, smallBuffer...),
},
{
name: "large buffer",
inputBuffer: largeBuffer,
expectedBuffer: append([]byte{15, 1}, largeBuffer...),
},
}

for _, testCase := range framedBufferTestCases {
result := f.SendData(testCase.inputBuffer)

if !bytes.Equal(testCase.expectedBuffer, result) {
t.Errorf("%s - expected: %+v, received: %+v", testCase.name, testCase.expectedBuffer, result)
}
}
}

0 comments on commit ff0ff07

Please sign in to comment.