consumer_group_members_test.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package sarama
  2. import (
  3. "bytes"
  4. "reflect"
  5. "testing"
  6. )
  7. var (
  8. groupMemberMetadata = []byte{
  9. 0, 1, // Version
  10. 0, 0, 0, 2, // Topic array length
  11. 0, 3, 'o', 'n', 'e', // Topic one
  12. 0, 3, 't', 'w', 'o', // Topic two
  13. 0, 0, 0, 3, 0x01, 0x02, 0x03, // Userdata
  14. }
  15. groupMemberAssignment = []byte{
  16. 0, 1, // Version
  17. 0, 0, 0, 1, // Topic array length
  18. 0, 3, 'o', 'n', 'e', // Topic one
  19. 0, 0, 0, 3, // Topic one, partition array length
  20. 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 4, // 0, 2, 4
  21. 0, 0, 0, 3, 0x01, 0x02, 0x03, // Userdata
  22. }
  23. )
  24. func TestConsumerGroupMemberMetadata(t *testing.T) {
  25. meta := &ConsumerGroupMemberMetadata{
  26. Version: 1,
  27. Topics: []string{"one", "two"},
  28. UserData: []byte{0x01, 0x02, 0x03},
  29. }
  30. buf, err := encode(meta, nil)
  31. if err != nil {
  32. t.Error("Failed to encode data", err)
  33. } else if !bytes.Equal(groupMemberMetadata, buf) {
  34. t.Errorf("Encoded data does not match expectation\nexpected: %v\nactual: %v", groupMemberMetadata, buf)
  35. }
  36. meta2 := new(ConsumerGroupMemberMetadata)
  37. err = decode(buf, meta2)
  38. if err != nil {
  39. t.Error("Failed to decode data", err)
  40. } else if !reflect.DeepEqual(meta, meta2) {
  41. t.Errorf("Encoded data does not match expectation\nexpected: %v\nactual: %v", meta, meta2)
  42. }
  43. }
  44. func TestConsumerGroupMemberAssignment(t *testing.T) {
  45. amt := &ConsumerGroupMemberAssignment{
  46. Version: 1,
  47. Topics: map[string][]int32{
  48. "one": {0, 2, 4},
  49. },
  50. UserData: []byte{0x01, 0x02, 0x03},
  51. }
  52. buf, err := encode(amt, nil)
  53. if err != nil {
  54. t.Error("Failed to encode data", err)
  55. } else if !bytes.Equal(groupMemberAssignment, buf) {
  56. t.Errorf("Encoded data does not match expectation\nexpected: %v\nactual: %v", groupMemberAssignment, buf)
  57. }
  58. amt2 := new(ConsumerGroupMemberAssignment)
  59. err = decode(buf, amt2)
  60. if err != nil {
  61. t.Error("Failed to decode data", err)
  62. } else if !reflect.DeepEqual(amt, amt2) {
  63. t.Errorf("Encoded data does not match expectation\nexpected: %v\nactual: %v", amt, amt2)
  64. }
  65. }