forked from mostafa/xk6-kafka
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bytearray_test.go
34 lines (29 loc) · 1.12 KB
/
bytearray_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package kafka
import (
"testing"
"github.com/stretchr/testify/assert"
)
// TestSerializeByteArray tests the serialization of a byte array into binary
func TestSerializeByteArray(t *testing.T) {
var data int64 = 98
originalData := []interface{}{data}
result, err := SerializeByteArray(Configuration{}, "", originalData, "", "", 0)
assert.Nil(t, err)
assert.Equal(t, []byte{0x62}, result)
}
// TestSerializeByteArrayFails tests the serialization of a byte array into binary and fails
// on invalid data type
func TestSerializeByteArrayFails(t *testing.T) {
originalData := "test"
_, err := SerializeByteArray(Configuration{}, "", originalData, "", "", 0)
assert.NotNil(t, err)
assert.Equal(t, err.Message, "Invalid data type provided for byte array serializer (requires []byte)")
assert.Equal(t, err.Code, invalidDataType)
}
// TestDeserializeByteArray tests the deserialization of a byte array into binary
func TestDeserializeByteArray(t *testing.T) {
originalData := []byte{1, 2, 3}
result, err := DeserializeByteArray(Configuration{}, "", originalData, "", "", 0)
assert.Equal(t, []byte{1, 2, 3}, result)
assert.Nil(t, err)
}