forked from IBM/sarama
-
Notifications
You must be signed in to change notification settings - Fork 0
/
offset_fetch_response_test.go
61 lines (45 loc) · 1.44 KB
/
offset_fetch_response_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
package sarama
import "testing"
var (
emptyOffsetFetchResponse = []byte{
0x00, 0x00, 0x00, 0x00}
normalOffsetFetchResponse = []byte{
0x00, 0x00, 0x00, 0x02,
0x00, 0x01, 'm',
0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 't',
0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x02, 'm', 'd',
0x00, 0x07}
)
func TestEmptyOffsetFetchResponse(t *testing.T) {
response := OffsetFetchResponse{}
testDecodable(t, "empty", &response, emptyOffsetFetchResponse)
if len(response.Blocks) != 0 {
t.Error("Decoding produced topic blocks where there were none.")
}
}
func TestNormalOffsetFetchResponse(t *testing.T) {
response := OffsetFetchResponse{}
testDecodable(t, "normal", &response, normalOffsetFetchResponse)
if len(response.Blocks) != 2 {
t.Fatal("Decoding produced wrong number of blocks.")
}
if len(response.Blocks["m"]) != 0 {
t.Error("Decoding produced partitions for topic 'm' where there were none.")
}
if len(response.Blocks["t"]) != 1 {
t.Fatal("Decoding produced wrong number of blocks for topic 't'.")
}
if response.Blocks["t"][0].Offset != 0 {
t.Error("Decoding produced wrong offset for topic 't' partition 0.")
}
if response.Blocks["t"][0].Metadata != "md" {
t.Error("Decoding produced wrong metadata for topic 't' partition 0.")
}
if response.Blocks["t"][0].Err != RequestTimedOut {
t.Error("Decoding produced wrong error for topic 't' partition 0.")
}
}