forked from mostafa/xk6-kafka
-
Notifications
You must be signed in to change notification settings - Fork 0
/
string_test.go
33 lines (28 loc) · 1.07 KB
/
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
package kafka
import (
"testing"
"github.com/stretchr/testify/assert"
)
// TestSerializeString tests the serialization of a string
func TestSerializeString(t *testing.T) {
originalData := "test"
result, err := SerializeString(Configuration{}, "", originalData, "", "", 0)
assert.Nil(t, err)
assert.Equal(t, []byte(originalData), result)
}
// TestSerializeStringFails tests the serialization of a string and
// fails if the given type is not string.
func TestSerializeStringFails(t *testing.T) {
originalData := 123
_, err := SerializeString(Configuration{}, "", originalData, "", "", 0)
assert.EqualErrorf(
t, err, "Invalid data type provided for string serializer (requires string), OriginalError: %!w(*errors.errorString=&{Expected: string, got: int})",
"Expected error message is correct")
}
// TestDeserializeString tests the deserialization of a string
func TestDeserializeString(t *testing.T) {
originalData := "test"
result, err := DeserializeString(Configuration{}, "", []byte(originalData), "", "", 0)
assert.Equal(t, originalData, result)
assert.Nil(t, err)
}