-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test the framer.go sendData method (#817)
- Loading branch information
1 parent
80b6e89
commit ff0ff07
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} |