-
Notifications
You must be signed in to change notification settings - Fork 69
/
string_test.go
35 lines (30 loc) · 935 Bytes
/
string_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
package kafka
import (
"testing"
"github.com/stretchr/testify/assert"
)
// TestSerializeString tests the serialization of a string.
func TestSerializeString(t *testing.T) {
stringSerde := &StringSerde{}
expected := []byte("test")
actual, err := stringSerde.Serialize("test", nil)
assert.Nil(t, err)
assert.Equal(t, expected, actual)
}
// TestSerializeStringFails tests the serialization of a string
// and fails on invalid data type.
func TestSerializeStringFails(t *testing.T) {
stringSerde := &StringSerde{}
actual, err := stringSerde.Serialize(1, nil)
assert.Nil(t, actual)
assert.NotNil(t, err)
assert.Equal(t, ErrInvalidDataType, err)
}
// TestDeserializeString tests the deserialization of a string.
func TestDeserializeString(t *testing.T) {
stringSerde := &StringSerde{}
expected := "test"
actual, err := stringSerde.Deserialize([]byte("test"), nil)
assert.Nil(t, err)
assert.Equal(t, expected, actual)
}