join_group_response_test.go 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package sarama
  2. import (
  3. "reflect"
  4. "testing"
  5. )
  6. var (
  7. joinGroupResponseNoError = []byte{
  8. 0x00, 0x00, // No error
  9. 0x00, 0x01, 0x02, 0x03, // Generation ID
  10. 0, 8, 'p', 'r', 'o', 't', 'o', 'c', 'o', 'l', // Protocol name chosen
  11. 0, 3, 'f', 'o', 'o', // Leader ID
  12. 0, 3, 'b', 'a', 'r', // Member ID
  13. 0, 0, 0, 0, // No member info
  14. }
  15. joinGroupResponseWithError = []byte{
  16. 0, 23, // Error: inconsistent group protocol
  17. 0x00, 0x00, 0x00, 0x00, // Generation ID
  18. 0, 0, // Protocol name chosen
  19. 0, 0, // Leader ID
  20. 0, 0, // Member ID
  21. 0, 0, 0, 0, // No member info
  22. }
  23. joinGroupResponseLeader = []byte{
  24. 0x00, 0x00, // No error
  25. 0x00, 0x01, 0x02, 0x03, // Generation ID
  26. 0, 8, 'p', 'r', 'o', 't', 'o', 'c', 'o', 'l', // Protocol name chosen
  27. 0, 3, 'f', 'o', 'o', // Leader ID
  28. 0, 3, 'f', 'o', 'o', // Member ID == Leader ID
  29. 0, 0, 0, 1, // 1 member
  30. 0, 3, 'f', 'o', 'o', // Member ID
  31. 0, 0, 0, 3, 0x01, 0x02, 0x03, // Member metadata
  32. }
  33. )
  34. func TestJoinGroupResponse(t *testing.T) {
  35. var response *JoinGroupResponse
  36. response = new(JoinGroupResponse)
  37. testVersionDecodable(t, "no error", response, joinGroupResponseNoError, 0)
  38. if response.Err != ErrNoError {
  39. t.Error("Decoding Err failed: no error expected but found", response.Err)
  40. }
  41. if response.GenerationId != 66051 {
  42. t.Error("Decoding GenerationId failed, found:", response.GenerationId)
  43. }
  44. if response.LeaderId != "foo" {
  45. t.Error("Decoding LeaderId failed, found:", response.LeaderId)
  46. }
  47. if response.MemberId != "bar" {
  48. t.Error("Decoding MemberId failed, found:", response.MemberId)
  49. }
  50. if len(response.Members) != 0 {
  51. t.Error("Decoding Members failed, found:", response.Members)
  52. }
  53. response = new(JoinGroupResponse)
  54. testVersionDecodable(t, "with error", response, joinGroupResponseWithError, 0)
  55. if response.Err != ErrInconsistentGroupProtocol {
  56. t.Error("Decoding Err failed: ErrInconsistentGroupProtocol expected but found", response.Err)
  57. }
  58. if response.GenerationId != 0 {
  59. t.Error("Decoding GenerationId failed, found:", response.GenerationId)
  60. }
  61. if response.LeaderId != "" {
  62. t.Error("Decoding LeaderId failed, found:", response.LeaderId)
  63. }
  64. if response.MemberId != "" {
  65. t.Error("Decoding MemberId failed, found:", response.MemberId)
  66. }
  67. if len(response.Members) != 0 {
  68. t.Error("Decoding Members failed, found:", response.Members)
  69. }
  70. response = new(JoinGroupResponse)
  71. testVersionDecodable(t, "with error", response, joinGroupResponseLeader, 0)
  72. if response.Err != ErrNoError {
  73. t.Error("Decoding Err failed: ErrNoError expected but found", response.Err)
  74. }
  75. if response.GenerationId != 66051 {
  76. t.Error("Decoding GenerationId failed, found:", response.GenerationId)
  77. }
  78. if response.LeaderId != "foo" {
  79. t.Error("Decoding LeaderId failed, found:", response.LeaderId)
  80. }
  81. if response.MemberId != "foo" {
  82. t.Error("Decoding MemberId failed, found:", response.MemberId)
  83. }
  84. if len(response.Members) != 1 {
  85. t.Error("Decoding Members failed, found:", response.Members)
  86. }
  87. if !reflect.DeepEqual(response.Members["foo"], []byte{0x01, 0x02, 0x03}) {
  88. t.Error("Decoding foo member failed, found:", response.Members["foo"])
  89. }
  90. }