forked from segmentio/kafka-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathread_test.go
72 lines (63 loc) · 1.37 KB
/
read_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
package kafka
import (
"bufio"
"bytes"
"reflect"
"testing"
)
func TestReadStringArray(t *testing.T) {
testCases := map[string]struct {
Value []string
}{
"nil": {
Value: nil,
},
"multiple elements": {
Value: []string{"a", "b", "c"},
},
}
for label, test := range testCases {
t.Run(label, func(t *testing.T) {
buf := bytes.NewBuffer(nil)
w := bufio.NewWriter(buf)
writeStringArray(w, test.Value)
w.Flush()
var actual []string
readStringArray(bufio.NewReader(buf), buf.Len(), &actual)
if !reflect.DeepEqual(test.Value, actual) {
t.Errorf("expected %v; got %v", test.Value, actual)
}
})
}
}
func TestReadMapStringInt32(t *testing.T) {
testCases := map[string]struct {
Data map[string][]int32
}{
"empty": {
Data: map[string][]int32{},
},
"single element": {
Data: map[string][]int32{
"key": {0, 1, 2},
},
},
}
for label, test := range testCases {
t.Run(label, func(t *testing.T) {
buf := bytes.NewBuffer(nil)
w := bufio.NewWriter(buf)
writeInt32(w, int32(len(test.Data)))
for key, values := range test.Data {
writeString(w, key)
writeInt32Array(w, values)
}
w.Flush()
var actual map[string][]int32
readMapStringInt32(bufio.NewReader(buf), buf.Len(), &actual)
if !reflect.DeepEqual(test.Data, actual) {
t.Errorf("expected %#v; got %#v", test.Data, actual)
}
})
}
}