create_partitions_response_test.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package sarama
  2. import (
  3. "reflect"
  4. "testing"
  5. "time"
  6. )
  7. var (
  8. createPartitionResponseSuccess = []byte{
  9. 0, 0, 0, 100, // throttleTimeMs
  10. 0, 0, 0, 1,
  11. 0, 5, 't', 'o', 'p', 'i', 'c',
  12. 0, 0, // no error
  13. 255, 255, // no error message
  14. }
  15. createPartitionResponseFail = []byte{
  16. 0, 0, 0, 100, // throttleTimeMs
  17. 0, 0, 0, 1,
  18. 0, 5, 't', 'o', 'p', 'i', 'c',
  19. 0, 37, // partition error
  20. 0, 5, 'e', 'r', 'r', 'o', 'r',
  21. }
  22. )
  23. func TestCreatePartitionsResponse(t *testing.T) {
  24. resp := &CreatePartitionsResponse{
  25. ThrottleTime: 100 * time.Millisecond,
  26. TopicPartitionErrors: map[string]*TopicPartitionError{
  27. "topic": &TopicPartitionError{},
  28. },
  29. }
  30. testResponse(t, "success", resp, createPartitionResponseSuccess)
  31. decodedresp := new(CreatePartitionsResponse)
  32. testVersionDecodable(t, "success", decodedresp, createPartitionResponseSuccess, 0)
  33. if !reflect.DeepEqual(decodedresp, resp) {
  34. t.Errorf("Decoding error: expected %v but got %v", decodedresp, resp)
  35. }
  36. errMsg := "error"
  37. resp.TopicPartitionErrors["topic"].Err = ErrInvalidPartitions
  38. resp.TopicPartitionErrors["topic"].ErrMsg = &errMsg
  39. testResponse(t, "with errors", resp, createPartitionResponseFail)
  40. decodedresp = new(CreatePartitionsResponse)
  41. testVersionDecodable(t, "with errors", decodedresp, createPartitionResponseFail, 0)
  42. if !reflect.DeepEqual(decodedresp, resp) {
  43. t.Errorf("Decoding error: expected %v but got %v", decodedresp, resp)
  44. }
  45. }