Skip to content

Commit

Permalink
Add tests for JoinGroupRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
wvanbergen committed Dec 8, 2015
1 parent 7941729 commit 44e849a
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions join_group_request_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
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
}

joinGroupRequestTwoProtocols = []byte{
0, 9, 'T', 'e', 's', 't', 'G', 'r', 'o', 'u', 'p', // Group ID
0, 0, 0, 100, // Session timeout
0, 12, 'T', 'w', 'o', 'P', 'r', 'o', 't', 'o', 'c', 'o', 'l', 's', // Member ID
0, 8, 'c', 'o', 'n', 's', 'u', 'm', 'e', 'r', // Protocol Type
0, 0, 0, 2, // 2 group protocol
0, 3, 't', 'w', 'o', // Protocol name
0, 0, 0, 3, 0x04, 0x05, 0x06, // protocol metadata
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)

request = new(JoinGroupRequest)
request.GroupId = "TestGroup"
request.SessionTimeout = 100
request.MemberId = "TwoProtocols"
request.ProtocolType = "consumer"
request.AddGroupProtocol("one", []byte{0x01, 0x02, 0x03})
request.AddGroupProtocol("two", []byte{0x04, 0x05, 0x06})
testRequest(t, "two protocols", request, joinGroupRequestTwoProtocols)
}

0 comments on commit 44e849a

Please sign in to comment.