create_topics_response_test.go 905 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package sarama
  2. import (
  3. "testing"
  4. "time"
  5. )
  6. var (
  7. createTopicsResponseV0 = []byte{
  8. 0, 0, 0, 1,
  9. 0, 5, 't', 'o', 'p', 'i', 'c',
  10. 0, 42,
  11. }
  12. createTopicsResponseV1 = []byte{
  13. 0, 0, 0, 1,
  14. 0, 5, 't', 'o', 'p', 'i', 'c',
  15. 0, 42,
  16. 0, 3, 'm', 's', 'g',
  17. }
  18. createTopicsResponseV2 = []byte{
  19. 0, 0, 0, 100,
  20. 0, 0, 0, 1,
  21. 0, 5, 't', 'o', 'p', 'i', 'c',
  22. 0, 42,
  23. 0, 3, 'm', 's', 'g',
  24. }
  25. )
  26. func TestCreateTopicsResponse(t *testing.T) {
  27. resp := &CreateTopicsResponse{
  28. TopicErrors: map[string]*TopicError{
  29. "topic": &TopicError{
  30. Err: ErrInvalidRequest,
  31. },
  32. },
  33. }
  34. testResponse(t, "version 0", resp, createTopicsResponseV0)
  35. resp.Version = 1
  36. msg := "msg"
  37. resp.TopicErrors["topic"].ErrMsg = &msg
  38. testResponse(t, "version 1", resp, createTopicsResponseV1)
  39. resp.Version = 2
  40. resp.ThrottleTime = 100 * time.Millisecond
  41. testResponse(t, "version 2", resp, createTopicsResponseV2)
  42. }