From b9cf4611bd2b7d16cea3d0d09aa5152bb535c822 Mon Sep 17 00:00:00 2001 From: resoluteCoder Date: Mon, 14 Aug 2023 20:34:10 -0500 Subject: [PATCH] Test the framer.go sendData method --- pkg/framer/framer_test.go | 43 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 pkg/framer/framer_test.go diff --git a/pkg/framer/framer_test.go b/pkg/framer/framer_test.go new file mode 100644 index 000000000..c94550983 --- /dev/null +++ b/pkg/framer/framer_test.go @@ -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) + } + } +}