describe_groups_response_test.go 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package sarama
  2. import (
  3. "reflect"
  4. "testing"
  5. )
  6. var (
  7. describeGroupsResponseEmpty = []byte{
  8. 0, 0, 0, 0, // no groups
  9. }
  10. describeGroupsResponsePopulated = []byte{
  11. 0, 0, 0, 2, // 2 groups
  12. 0, 0, // no error
  13. 0, 3, 'f', 'o', 'o', // Group ID
  14. 0, 3, 'b', 'a', 'r', // State
  15. 0, 8, 'c', 'o', 'n', 's', 'u', 'm', 'e', 'r', // ConsumerProtocol type
  16. 0, 3, 'b', 'a', 'z', // Protocol name
  17. 0, 0, 0, 1, // 1 member
  18. 0, 2, 'i', 'd', // Member ID
  19. 0, 6, 's', 'a', 'r', 'a', 'm', 'a', // Client ID
  20. 0, 9, 'l', 'o', 'c', 'a', 'l', 'h', 'o', 's', 't', // Client Host
  21. 0, 0, 0, 3, 0x01, 0x02, 0x03, // MemberMetadata
  22. 0, 0, 0, 3, 0x04, 0x05, 0x06, // MemberAssignment
  23. 0, 30, // ErrGroupAuthorizationFailed
  24. 0, 0,
  25. 0, 0,
  26. 0, 0,
  27. 0, 0,
  28. 0, 0, 0, 0,
  29. }
  30. )
  31. func TestDescribeGroupsResponse(t *testing.T) {
  32. var response *DescribeGroupsResponse
  33. response = new(DescribeGroupsResponse)
  34. testVersionDecodable(t, "empty", response, describeGroupsResponseEmpty, 0)
  35. if len(response.Groups) != 0 {
  36. t.Error("Expected no groups")
  37. }
  38. response = new(DescribeGroupsResponse)
  39. testVersionDecodable(t, "populated", response, describeGroupsResponsePopulated, 0)
  40. if len(response.Groups) != 2 {
  41. t.Error("Expected two groups")
  42. }
  43. group0 := response.Groups[0]
  44. if group0.Err != ErrNoError {
  45. t.Error("Unxpected groups[0].Err, found", group0.Err)
  46. }
  47. if group0.GroupId != "foo" {
  48. t.Error("Unxpected groups[0].GroupId, found", group0.GroupId)
  49. }
  50. if group0.State != "bar" {
  51. t.Error("Unxpected groups[0].State, found", group0.State)
  52. }
  53. if group0.ProtocolType != "consumer" {
  54. t.Error("Unxpected groups[0].ProtocolType, found", group0.ProtocolType)
  55. }
  56. if group0.Protocol != "baz" {
  57. t.Error("Unxpected groups[0].Protocol, found", group0.Protocol)
  58. }
  59. if len(group0.Members) != 1 {
  60. t.Error("Unxpected groups[0].Members, found", group0.Members)
  61. }
  62. if group0.Members["id"].ClientId != "sarama" {
  63. t.Error("Unxpected groups[0].Members[id].ClientId, found", group0.Members["id"].ClientId)
  64. }
  65. if group0.Members["id"].ClientHost != "localhost" {
  66. t.Error("Unxpected groups[0].Members[id].ClientHost, found", group0.Members["id"].ClientHost)
  67. }
  68. if !reflect.DeepEqual(group0.Members["id"].MemberMetadata, []byte{0x01, 0x02, 0x03}) {
  69. t.Error("Unxpected groups[0].Members[id].MemberMetadata, found", group0.Members["id"].MemberMetadata)
  70. }
  71. if !reflect.DeepEqual(group0.Members["id"].MemberAssignment, []byte{0x04, 0x05, 0x06}) {
  72. t.Error("Unxpected groups[0].Members[id].MemberAssignment, found", group0.Members["id"].MemberAssignment)
  73. }
  74. group1 := response.Groups[1]
  75. if group1.Err != ErrGroupAuthorizationFailed {
  76. t.Error("Unxpected groups[1].Err, found", group0.Err)
  77. }
  78. if len(group1.Members) != 0 {
  79. t.Error("Unxpected groups[1].Members, found", group0.Members)
  80. }
  81. }