-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathoffset_commit_test.go
43 lines (35 loc) · 3.07 KB
/
offset_commit_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
package client
import "testing"
var emptyOffsetCommitRequestBytes = []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
var goodOffsetCommitRequestBytes = []byte{0x00, 0x11, 0x67, 0x6f, 0x2d, 0x63, 0x6f, 0x6e, 0x73, 0x75, 0x6d, 0x65, 0x72, 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, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x0b, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64}
var goodOffsetCommitResponseBytes = []byte{0x00, 0x00, 0x00, 0x01, 0x00, 0x06, 0x74, 0x65, 0x73, 0x74, 0x2d, 0x32, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
var emptyOffsetCommitResponseBytes = []byte{0x00, 0x00, 0x00, 0x00}
var invalidLengthOffsetCommitResponseBytes = []byte{0x00, 0x00, 0x00}
var invalidTopicOffsetCommitResponseBytes = []byte{0x00, 0x00, 0x00, 0x01, 0x00, 0x06, 0x74, 0x65}
var invalidPartitionsLengthOffsetCommitResponseBytes = []byte{0x00, 0x00, 0x00, 0x01, 0x00, 0x06, 0x74, 0x65, 0x73, 0x74, 0x2d, 0x32, 0x00, 0x00, 0x00}
var invalidPartitionOffsetCommitResponseBytes = []byte{0x00, 0x00, 0x00, 0x01, 0x00, 0x06, 0x74, 0x65, 0x73, 0x74, 0x2d, 0x32, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00}
var invalidErrorCodeOffsetCommitResponseBytes = []byte{0x00, 0x00, 0x00, 0x01, 0x00, 0x06, 0x74, 0x65, 0x73, 0x74, 0x2d, 0x32, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00}
func TestOffsetCommitRequest(t *testing.T) {
emptyOffsetCommitRequest := new(OffsetCommitRequest)
testRequest(t, emptyOffsetCommitRequest, emptyOffsetCommitRequestBytes)
goodOffsetCommitRequest := NewOffsetCommitRequest("go-consumer-group")
goodOffsetCommitRequest.AddOffset("test-2", 0, 4, -1, "hello world")
testRequest(t, goodOffsetCommitRequest, goodOffsetCommitRequestBytes)
}
func TestOffsetCommitResponse(t *testing.T) {
goodOffsetCommitResponse := new(OffsetCommitResponse)
decode(t, goodOffsetCommitResponse, goodOffsetCommitResponseBytes)
partitionsAndErrors, exists := goodOffsetCommitResponse.CommitStatus["test-2"]
assertFatal(t, exists, true)
err, exists := partitionsAndErrors[0]
assertFatal(t, exists, true)
assert(t, err, ErrNoError)
emptyOffsetCommitResponse := new(OffsetCommitResponse)
decode(t, emptyOffsetCommitResponse, emptyOffsetCommitResponseBytes)
assert(t, len(emptyOffsetCommitResponse.CommitStatus), 0)
decodeErr(t, new(OffsetCommitResponse), invalidLengthOffsetCommitResponseBytes, NewDecodingError(ErrEOF, reasonInvalidOffsetsMapLength))
decodeErr(t, new(OffsetCommitResponse), invalidTopicOffsetCommitResponseBytes, NewDecodingError(ErrEOF, reasonInvalidOffsetsTopic))
decodeErr(t, new(OffsetCommitResponse), invalidPartitionsLengthOffsetCommitResponseBytes, NewDecodingError(ErrEOF, reasonInvalidOffsetsPartitionsLength))
decodeErr(t, new(OffsetCommitResponse), invalidPartitionOffsetCommitResponseBytes, NewDecodingError(ErrEOF, reasonInvalidOffsetsPartition))
decodeErr(t, new(OffsetCommitResponse), invalidErrorCodeOffsetCommitResponseBytes, NewDecodingError(ErrEOF, reasonInvalidOffsetsErrorCode))
}