consumer_metadata_response_test.go 1.4 KB

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