-
Notifications
You must be signed in to change notification settings - Fork 69
/
bytearray_test.go
54 lines (47 loc) · 1.68 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package kafka
import (
"testing"
"github.com/stretchr/testify/assert"
)
// TestSerializeByteArray tests the serialization of a byte array.
func TestSerializeByteArray(t *testing.T) {
byteArraySerde := &ByteArraySerde{}
expected := []byte{1, 2, 3}
actual, err := byteArraySerde.Serialize([]byte{1, 2, 3}, nil)
assert.Nil(t, err)
assert.Equal(t, expected, actual)
}
// TestSerializeInterfaceArray tests the serialization of an interface array.
func TestSerializeInterfaceArray(t *testing.T) {
byteArraySerde := &ByteArraySerde{}
expected := []byte{0x41, 0x42, 0x43}
actual, err := byteArraySerde.Serialize([]interface{}{65.0, 66.0, 67.0}, nil)
assert.Nil(t, err)
assert.Equal(t, expected, actual)
}
// TestSerializeInterfaceArrayFails tests the serialization of an interface array
// and fails on mixed data type.
func TestSerializeInterfaceArrayFails(t *testing.T) {
byteArraySerde := &ByteArraySerde{}
actual, err := byteArraySerde.Serialize([]interface{}{65.0, 66.0, "a"}, nil)
assert.Nil(t, actual)
assert.NotNil(t, err)
assert.Equal(t, ErrFailedTypeCast, err)
}
// TestSerializeByteArrayFails tests the serialization of a byte array
// and fails on invalid data type.
func TestSerializeByteArrayFails(t *testing.T) {
byteArraySerde := &ByteArraySerde{}
actual, err := byteArraySerde.Serialize(1, nil)
assert.Nil(t, actual)
assert.NotNil(t, err)
assert.Equal(t, ErrInvalidDataType, err)
}
// TestDeserializeByteArray tests the deserialization of a byte array.
func TestDeserializeByteArray(t *testing.T) {
byteArraySerde := &ByteArraySerde{}
expected := []byte{1, 2, 3}
actual, err := byteArraySerde.Deserialize([]byte{1, 2, 3}, nil)
assert.Nil(t, err)
assert.Equal(t, expected, actual)
}