-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathoffset_fetch_test.go
49 lines (41 loc) · 3.75 KB
/
offset_fetch_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
package client
import "testing"
var emptyOffsetFetchRequestBytes = []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
var goodOffsetFetchRequestBytes = []byte{0x00, 0x0e, 0x6f, 0x74, 0x68, 0x65, 0x72, 0x2d, 0x67, 0x6f, 0x2d, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x00, 0x00, 0x00, 0x01, 0x00, 0x06, 0x74, 0x65, 0x73, 0x74, 0x2d, 0x32, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00}
var emptyOffsetFetchResponseBytes = []byte{0x00, 0x00, 0x00, 0x00}
var goodOffsetFetchResponseBytes = []byte{0x00, 0x00, 0x00, 0x01, 0x00, 0x06, 0x74, 0x65, 0x73, 0x74, 0x2d, 0x32, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00}
var invalidOffsetsLengthOffsetFetchResponseBytes = []byte{0x00, 0x00, 0x00}
var invalidTopicOffsetFetchResponseBytes = []byte{0x00, 0x00, 0x00, 0x01, 0x00, 0x06, 0x74, 0x65}
var invalidPartitionsLengthFetchResponseBytes = []byte{0x00, 0x00, 0x00, 0x01, 0x00, 0x06, 0x74, 0x65, 0x73, 0x74, 0x2d, 0x32, 0x00, 0x00, 0x00}
var invalidPartitionFetchResponseBytes = []byte{0x00, 0x00, 0x00, 0x01, 0x00, 0x06, 0x74, 0x65, 0x73, 0x74, 0x2d, 0x32, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00}
var invalidOffsetFetchResponseBytes = []byte{0x00, 0x00, 0x00, 0x01, 0x00, 0x06, 0x74, 0x65, 0x73, 0x74, 0x2d, 0x32, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
var invalidMetadataFetchResponseBytes = []byte{0x00, 0x00, 0x00, 0x01, 0x00, 0x06, 0x74, 0x65, 0x73, 0x74, 0x2d, 0x32, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00}
var invalidErrorCodeFetchResponseBytes = []byte{0x00, 0x00, 0x00, 0x01, 0x00, 0x06, 0x74, 0x65, 0x73, 0x74, 0x2d, 0x32, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00}
func TestOffsetFetchRequest(t *testing.T) {
emptyOffsetFetchRequest := new(OffsetFetchRequest)
testRequest(t, emptyOffsetFetchRequest, emptyOffsetFetchRequestBytes)
goodOffsetFetchRequest := NewOffsetFetchRequest("other-go-group")
goodOffsetFetchRequest.AddOffset("test-2", 0)
testRequest(t, goodOffsetFetchRequest, goodOffsetFetchRequestBytes)
}
func TestOffsetFetchResponse(t *testing.T) {
emptyOffsetFetchResponse := new(OffsetFetchResponse)
decode(t, emptyOffsetFetchResponse, emptyOffsetFetchResponseBytes)
assert(t, len(emptyOffsetFetchResponse.Offsets), 0)
goodOffsetFetchResponse := new(OffsetFetchResponse)
decode(t, goodOffsetFetchResponse, goodOffsetFetchResponseBytes)
offsetsForTopic, exists := goodOffsetFetchResponse.Offsets["test-2"]
assertFatal(t, exists, true)
offsetsForPartition, exists := offsetsForTopic[0]
assertFatal(t, exists, true)
assert(t, offsetsForPartition.Error, ErrNoError)
assert(t, offsetsForPartition.Metadata, "")
assert(t, offsetsForPartition.Offset, int64(7))
decodeErr(t, new(OffsetFetchResponse), invalidOffsetsLengthOffsetFetchResponseBytes, NewDecodingError(ErrEOF, reasonInvalidOffsetsMapLength))
decodeErr(t, new(OffsetFetchResponse), invalidTopicOffsetFetchResponseBytes, NewDecodingError(ErrEOF, reasonInvalidOffsetFetchResponseTopic))
decodeErr(t, new(OffsetFetchResponse), invalidPartitionsLengthFetchResponseBytes, NewDecodingError(ErrEOF, reasonInvalidOffsetFetchResponsePartitionsLength))
decodeErr(t, new(OffsetFetchResponse), invalidPartitionFetchResponseBytes, NewDecodingError(ErrEOF, reasonInvalidOffsetFetchResponsePartition))
decodeErr(t, new(OffsetFetchResponse), invalidOffsetFetchResponseBytes, NewDecodingError(ErrEOF, reasonInvalidOffsetFetchResponseOffset))
decodeErr(t, new(OffsetFetchResponse), invalidMetadataFetchResponseBytes, NewDecodingError(ErrEOF, reasonInvalidOffsetFetchResponseMetadata))
decodeErr(t, new(OffsetFetchResponse), invalidErrorCodeFetchResponseBytes, NewDecodingError(ErrEOF, reasonInvalidOffsetFetchResponseErrorCode))
}