Skip to content

Commit

Permalink
Add tests for all new request types.
Browse files Browse the repository at this point in the history
  • Loading branch information
wvanbergen committed Dec 8, 2015
1 parent b9eb8ac commit 9a8900b
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 0 deletions.
34 changes: 34 additions & 0 deletions describe_groups_request_test.go
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)
}
21 changes: 21 additions & 0 deletions heartbeat_request_test.go
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)
}
41 changes: 41 additions & 0 deletions join_group_request_test.go
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)
}
19 changes: 19 additions & 0 deletions leave_group_request_test.go
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)
}
7 changes: 7 additions & 0 deletions list_groups_request_test.go
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{})
}
38 changes: 38 additions & 0 deletions sync_group_request_test.go
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)
}

0 comments on commit 9a8900b

Please sign in to comment.