forked from mostafa/xk6-kafka
-
Notifications
You must be signed in to change notification settings - Fork 0
/
serde_test.go
87 lines (75 loc) · 3.48 KB
/
serde_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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package kafka
import (
"testing"
"github.com/stretchr/testify/assert"
)
// TestUseSerializer tests whether a serializer should be used based on the configuration
func TestUseSerializer(t *testing.T) {
config := Configuration{
Producer: ProducerConfiguration{
ValueSerializer: AvroSerializer,
KeySerializer: AvroSerializer,
},
}
assert.True(t, useSerializer(config, Key))
assert.True(t, useSerializer(config, Value))
}
type UseSerializerTest struct {
config Configuration
element Element
result bool
}
// TestUseSerializerFails tests whether a serializer should be used based on the configuration
// and fails if the configuration is invalid.
func TestUseSerializerFails(t *testing.T) {
params := []UseSerializerTest{
{config: Configuration{}, element: Key, result: false},
{config: Configuration{}, element: Value, result: false},
{config: Configuration{Producer: ProducerConfiguration{}}, element: Key, result: false},
{config: Configuration{Producer: ProducerConfiguration{}}, element: Value, result: false},
{config: Configuration{Consumer: ConsumerConfiguration{}}, element: Key, result: false},
{config: Configuration{Consumer: ConsumerConfiguration{}}, element: Value, result: false},
{config: Configuration{SchemaRegistry: SchemaRegistryConfiguration{}}, element: Key, result: false},
{config: Configuration{SchemaRegistry: SchemaRegistryConfiguration{}}, element: Value, result: false},
{config: Configuration{Producer: ProducerConfiguration{ValueSerializer: "unknown codec"}}, element: Key, result: false},
{config: Configuration{Producer: ProducerConfiguration{KeySerializer: "unknown codec"}}, element: Value, result: false},
}
for _, param := range params {
assert.Equal(t, param.result, useSerializer(param.config, param.element))
}
}
// TestUseDeserializer tests whether a deserializer should be used based on the configuration
func TestUseDeserializer(t *testing.T) {
config := Configuration{
Consumer: ConsumerConfiguration{
ValueDeserializer: AvroDeserializer,
KeyDeserializer: AvroDeserializer,
},
}
assert.True(t, useDeserializer(config, Key))
assert.True(t, useDeserializer(config, Value))
}
type UseDeserializerTest struct {
config Configuration
element Element
result bool
}
// TestUseDeserializerFails tests whether a deserializer should be used based on the configuration
// and fails if the configuration is invalid.
func TestUseDeserializerFails(t *testing.T) {
params := []UseDeserializerTest{
{config: Configuration{}, element: Key, result: false},
{config: Configuration{}, element: Value, result: false},
{config: Configuration{Producer: ProducerConfiguration{}}, element: Key, result: false},
{config: Configuration{Producer: ProducerConfiguration{}}, element: Value, result: false},
{config: Configuration{Consumer: ConsumerConfiguration{}}, element: Key, result: false},
{config: Configuration{Consumer: ConsumerConfiguration{}}, element: Value, result: false},
{config: Configuration{SchemaRegistry: SchemaRegistryConfiguration{}}, element: Key, result: false},
{config: Configuration{SchemaRegistry: SchemaRegistryConfiguration{}}, element: Value, result: false},
{config: Configuration{Consumer: ConsumerConfiguration{ValueDeserializer: "unknown codec"}}, element: Key, result: false},
{config: Configuration{Consumer: ConsumerConfiguration{KeyDeserializer: "unknown codec"}}, element: Value, result: false},
}
for _, param := range params {
assert.Equal(t, param.result, useDeserializer(param.config, param.element))
}
}