list_groups_response_test.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package sarama
  2. import (
  3. "testing"
  4. )
  5. var (
  6. listGroupsResponseEmpty = []byte{
  7. 0, 0, // no error
  8. 0, 0, 0, 0, // no groups
  9. }
  10. listGroupsResponseError = []byte{
  11. 0, 31, // no error
  12. 0, 0, 0, 0, // ErrClusterAuthorizationFailed
  13. }
  14. listGroupsResponseWithConsumer = []byte{
  15. 0, 0, // no error
  16. 0, 0, 0, 1, // 1 group
  17. 0, 3, 'f', 'o', 'o', // group name
  18. 0, 8, 'c', 'o', 'n', 's', 'u', 'm', 'e', 'r', // protocol type
  19. }
  20. )
  21. func TestListGroupsResponse(t *testing.T) {
  22. var response *ListGroupsResponse
  23. response = new(ListGroupsResponse)
  24. testVersionDecodable(t, "no error", response, listGroupsResponseEmpty, 0)
  25. if response.Err != ErrNoError {
  26. t.Error("Expected no gerror, found:", response.Err)
  27. }
  28. if len(response.Groups) != 0 {
  29. t.Error("Expected no groups")
  30. }
  31. response = new(ListGroupsResponse)
  32. testVersionDecodable(t, "no error", response, listGroupsResponseError, 0)
  33. if response.Err != ErrClusterAuthorizationFailed {
  34. t.Error("Expected no gerror, found:", response.Err)
  35. }
  36. if len(response.Groups) != 0 {
  37. t.Error("Expected no groups")
  38. }
  39. response = new(ListGroupsResponse)
  40. testVersionDecodable(t, "no error", response, listGroupsResponseWithConsumer, 0)
  41. if response.Err != ErrNoError {
  42. t.Error("Expected no gerror, found:", response.Err)
  43. }
  44. if len(response.Groups) != 1 {
  45. t.Error("Expected one group")
  46. }
  47. if response.Groups["foo"] != "consumer" {
  48. t.Error("Expected foo group to use consumer protocol")
  49. }
  50. }