consumer_metadata_response_test.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package sarama
  2. import "testing"
  3. var (
  4. consumerMetadataResponseError = []byte{
  5. 0x00, 0x0E}
  6. consumerMetadataResponseSuccess = []byte{
  7. 0x00, 0x00,
  8. 0x00, 0x00, 0x00, 0xAB,
  9. 0x00, 0x03, 'f', 'o', 'o',
  10. 0x00, 0x00, 0xCC, 0xDD}
  11. )
  12. func TestConsumerMetadataResponseError(t *testing.T) {
  13. response := ConsumerMetadataResponse{}
  14. testDecodable(t, "error", &response, consumerMetadataResponseError)
  15. if response.Err != OffsetsLoadInProgress {
  16. t.Error("Decoding produced incorrect error value.")
  17. }
  18. if response.CoordinatorId != 0 {
  19. t.Error("Decoding produced ID when the message contained an error.")
  20. }
  21. if len(response.CoordinatorHost) != 0 {
  22. t.Error("Decoding produced host when the message contained an error.")
  23. }
  24. if response.CoordinatorPort != 0 {
  25. t.Error("Decoding produced port when the message contained an error.")
  26. }
  27. }
  28. func TestConsumerMetadataResponseSuccess(t *testing.T) {
  29. response := ConsumerMetadataResponse{}
  30. testDecodable(t, "success", &response, consumerMetadataResponseSuccess)
  31. if response.Err != NoError {
  32. t.Error("Decoding produced error value where there was none.")
  33. }
  34. if response.CoordinatorId != 0xAB {
  35. t.Error("Decoding produced incorrect coordinator ID.")
  36. }
  37. if response.CoordinatorHost != "foo" {
  38. t.Error("Decoding produced incorrect coordinator host.")
  39. }
  40. if response.CoordinatorPort != 0xCCDD {
  41. t.Error("Decoding produced incorrect coordinator port.")
  42. }
  43. }