join_group_request_test.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package sarama
  2. import "testing"
  3. var (
  4. joinGroupRequestNoProtocols = []byte{
  5. 0, 9, 'T', 'e', 's', 't', 'G', 'r', 'o', 'u', 'p', // Group ID
  6. 0, 0, 0, 100, // Session timeout
  7. 0, 0, // Member ID
  8. 0, 8, 'c', 'o', 'n', 's', 'u', 'm', 'e', 'r', // Protocol Type
  9. 0, 0, 0, 0, // 0 protocol groups
  10. }
  11. joinGroupRequestOneProtocol = []byte{
  12. 0, 9, 'T', 'e', 's', 't', 'G', 'r', 'o', 'u', 'p', // Group ID
  13. 0, 0, 0, 100, // Session timeout
  14. 0, 11, 'O', 'n', 'e', 'P', 'r', 'o', 't', 'o', 'c', 'o', 'l', // Member ID
  15. 0, 8, 'c', 'o', 'n', 's', 'u', 'm', 'e', 'r', // Protocol Type
  16. 0, 0, 0, 1, // 1 group protocol
  17. 0, 3, 'o', 'n', 'e', // Protocol name
  18. 0, 0, 0, 3, 0x01, 0x02, 0x03, // protocol metadata
  19. }
  20. )
  21. func TestJoinGroupRequest(t *testing.T) {
  22. request := new(JoinGroupRequest)
  23. request.GroupId = "TestGroup"
  24. request.SessionTimeout = 100
  25. request.ProtocolType = "consumer"
  26. testRequest(t, "no protocols", request, joinGroupRequestNoProtocols)
  27. }
  28. func TestJoinGroupRequestOneProtocol(t *testing.T) {
  29. request := new(JoinGroupRequest)
  30. request.GroupId = "TestGroup"
  31. request.SessionTimeout = 100
  32. request.MemberId = "OneProtocol"
  33. request.ProtocolType = "consumer"
  34. request.AddGroupProtocol("one", []byte{0x01, 0x02, 0x03})
  35. packet := testRequestEncode(t, "one protocol", request, joinGroupRequestOneProtocol)
  36. request.GroupProtocols = make(map[string][]byte)
  37. request.GroupProtocols["one"] = []byte{0x01, 0x02, 0x03}
  38. testRequestDecode(t, "one protocol", request, packet)
  39. }
  40. func TestJoinGroupRequestDeprecatedEncode(t *testing.T) {
  41. request := new(JoinGroupRequest)
  42. request.GroupId = "TestGroup"
  43. request.SessionTimeout = 100
  44. request.MemberId = "OneProtocol"
  45. request.ProtocolType = "consumer"
  46. request.GroupProtocols = make(map[string][]byte)
  47. request.GroupProtocols["one"] = []byte{0x01, 0x02, 0x03}
  48. packet := testRequestEncode(t, "one protocol", request, joinGroupRequestOneProtocol)
  49. request.AddGroupProtocol("one", []byte{0x01, 0x02, 0x03})
  50. testRequestDecode(t, "one protocol", request, packet)
  51. }