-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for all new request types.
- Loading branch information
1 parent
b9eb8ac
commit 9a8900b
Showing
6 changed files
with
160 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package sarama | ||
|
||
import "testing" | ||
|
||
var ( | ||
emptyDescribeGroupsRequest = []byte{0, 0, 0, 0} | ||
|
||
singleDescribeGroupsRequest = []byte{ | ||
0, 0, 0, 1, // 1 group | ||
0, 3, 'f', 'o', 'o', // group name: foo | ||
} | ||
|
||
doubleDescribeGroupsRequest = []byte{ | ||
0, 0, 0, 2, // 2 groups | ||
0, 3, 'f', 'o', 'o', // group name: foo | ||
0, 3, 'b', 'a', 'r', // group name: foo | ||
} | ||
) | ||
|
||
func TestDescribeGroupsRequest(t *testing.T) { | ||
var request *DescribeGroupsRequest | ||
|
||
request = new(DescribeGroupsRequest) | ||
testRequest(t, "no groups", request, emptyDescribeGroupsRequest) | ||
|
||
request = new(DescribeGroupsRequest) | ||
request.AddGroup("foo") | ||
testRequest(t, "one group", request, singleDescribeGroupsRequest) | ||
|
||
request = new(DescribeGroupsRequest) | ||
request.AddGroup("foo") | ||
request.AddGroup("bar") | ||
testRequest(t, "two groups", request, doubleDescribeGroupsRequest) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package sarama | ||
|
||
import "testing" | ||
|
||
var ( | ||
basicHeartbeatRequest = []byte{ | ||
0, 3, 'f', 'o', 'o', | ||
0, 3, 'b', 'a', 'r', | ||
0, 3, 'b', 'a', 'z', | ||
} | ||
) | ||
|
||
func TestHeartbeatRequest(t *testing.T) { | ||
var request *HeartbeatRequest | ||
|
||
request = new(HeartbeatRequest) | ||
request.GroupId = "foo" | ||
request.GenerationId = "bar" | ||
request.MemberId = "baz" | ||
testRequest(t, "basic", request, basicHeartbeatRequest) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package sarama | ||
|
||
import "testing" | ||
|
||
var ( | ||
joinGroupRequestNoProtocols = []byte{ | ||
0, 9, 'T', 'e', 's', 't', 'G', 'r', 'o', 'u', 'p', // Group ID | ||
0, 0, 0, 100, // Session timeout | ||
0, 0, // Member ID | ||
0, 8, 'c', 'o', 'n', 's', 'u', 'm', 'e', 'r', // Protocol Type | ||
0, 0, 0, 0, // 0 protocol groups | ||
} | ||
|
||
joinGroupRequestOneProtocol = []byte{ | ||
0, 9, 'T', 'e', 's', 't', 'G', 'r', 'o', 'u', 'p', // Group ID | ||
0, 0, 0, 100, // Session timeout | ||
0, 11, 'O', 'n', 'e', 'P', 'r', 'o', 't', 'o', 'c', 'o', 'l', // Member ID | ||
0, 8, 'c', 'o', 'n', 's', 'u', 'm', 'e', 'r', // Protocol Type | ||
0, 0, 0, 1, // 1 group protocol | ||
0, 3, 'o', 'n', 'e', // Protocol name | ||
0, 0, 0, 3, 0x01, 0x02, 0x03, // protocol metadata | ||
} | ||
) | ||
|
||
func TestJoinGroupRequest(t *testing.T) { | ||
var request *JoinGroupRequest | ||
|
||
request = new(JoinGroupRequest) | ||
request.GroupId = "TestGroup" | ||
request.SessionTimeout = 100 | ||
request.ProtocolType = "consumer" | ||
testRequest(t, "no protocols", request, joinGroupRequestNoProtocols) | ||
|
||
request = new(JoinGroupRequest) | ||
request.GroupId = "TestGroup" | ||
request.SessionTimeout = 100 | ||
request.MemberId = "OneProtocol" | ||
request.ProtocolType = "consumer" | ||
request.AddGroupProtocol("one", []byte{0x01, 0x02, 0x03}) | ||
testRequest(t, "one protocol", request, joinGroupRequestOneProtocol) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package sarama | ||
|
||
import "testing" | ||
|
||
var ( | ||
basicLeaveGroupRequest = []byte{ | ||
0, 3, 'f', 'o', 'o', | ||
0, 3, 'b', 'a', 'r', | ||
} | ||
) | ||
|
||
func TestLeaveGroupRequest(t *testing.T) { | ||
var request *LeaveGroupRequest | ||
|
||
request = new(LeaveGroupRequest) | ||
request.GroupId = "foo" | ||
request.MemberId = "bar" | ||
testRequest(t, "basic", request, basicLeaveGroupRequest) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package sarama | ||
|
||
import "testing" | ||
|
||
func TestListGroupsRequest(t *testing.T) { | ||
testRequest(t, "ListGroupsRequest", &ListGroupsRequest{}, []byte{}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package sarama | ||
|
||
import "testing" | ||
|
||
var ( | ||
emptySyncGroupRequest = []byte{ | ||
0, 3, 'f', 'o', 'o', // Group ID | ||
0, 3, 'b', 'a', 'r', // Generation ID | ||
0, 3, 'b', 'a', 'z', // Member ID | ||
0, 0, 0, 0, // no assignments | ||
} | ||
|
||
populatedSyncGroupRequest = []byte{ | ||
0, 3, 'f', 'o', 'o', // Group ID | ||
0, 3, 'b', 'a', 'r', // Generation ID | ||
0, 3, 'b', 'a', 'z', // Member ID | ||
0, 0, 0, 1, // one assignment | ||
0, 3, 'b', 'a', 'z', // Member ID | ||
0, 0, 0, 3, 'f', 'o', 'o', // Member assignment | ||
} | ||
) | ||
|
||
func TestSyncGroupRequest(t *testing.T) { | ||
var request *SyncGroupRequest | ||
|
||
request = new(SyncGroupRequest) | ||
request.GroupId = "foo" | ||
request.GenerationId = "bar" | ||
request.MemberId = "baz" | ||
testRequest(t, "empty", request, emptySyncGroupRequest) | ||
|
||
request = new(SyncGroupRequest) | ||
request.GroupId = "foo" | ||
request.GenerationId = "bar" | ||
request.MemberId = "baz" | ||
request.AddGroupAssignment("baz", []byte("foo")) | ||
testRequest(t, "populated", request, populatedSyncGroupRequest) | ||
} |