consumer_metadata_response_test.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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{Err: ErrOffsetsLoadInProgress}
  17. testEncodable(t, "", response, consumerMetadataResponseError)
  18. decodedResp := &ConsumerMetadataResponse{}
  19. if err := versionedDecode(consumerMetadataResponseError, decodedResp, 0); err != nil {
  20. t.Error("could not decode: ", err)
  21. }
  22. if decodedResp.Err != ErrOffsetsLoadInProgress {
  23. t.Errorf("got %s, want %s", decodedResp.Err, ErrOffsetsLoadInProgress)
  24. }
  25. }
  26. func TestConsumerMetadataResponseSuccess(t *testing.T) {
  27. broker := NewBroker("foo:52445")
  28. broker.id = 0xAB
  29. response := ConsumerMetadataResponse{
  30. Coordinator: broker,
  31. CoordinatorID: 0xAB,
  32. CoordinatorHost: "foo",
  33. CoordinatorPort: 0xCCDD,
  34. Err: ErrNoError,
  35. }
  36. testResponse(t, "success", &response, consumerMetadataResponseSuccess)
  37. }