offset_commit_response_test.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package protocol
  2. import "testing"
  3. import "sarama/types"
  4. var (
  5. emptyOffsetCommitResponse = []byte{
  6. 0xFF, 0xFF,
  7. 0x00, 0x00, 0x00, 0x00}
  8. normalOffsetCommitResponse = []byte{
  9. 0x00, 0x02, 'a', 'z',
  10. 0x00, 0x00, 0x00, 0x02,
  11. 0x00, 0x01, 'm',
  12. 0x00, 0x00, 0x00, 0x00,
  13. 0x00, 0x01, 't',
  14. 0x00, 0x00, 0x00, 0x01,
  15. 0x00, 0x00, 0x00, 0x00,
  16. 0x00, 0x06}
  17. )
  18. func TestEmptyOffsetCommitResponse(t *testing.T) {
  19. response := OffsetCommitResponse{}
  20. testDecodable(t, "empty", &response, emptyOffsetCommitResponse)
  21. if response.ClientID != "" {
  22. t.Error("Decoding produced client ID where there was none.")
  23. }
  24. if len(response.Errors) != 0 {
  25. t.Error("Decoding produced errors where there were none.")
  26. }
  27. }
  28. func TestNormalOffsetCommitResponse(t *testing.T) {
  29. response := OffsetCommitResponse{}
  30. testDecodable(t, "normal", &response, normalOffsetCommitResponse)
  31. if response.ClientID != "az" {
  32. t.Error("Decoding produced wrong client ID.")
  33. }
  34. if len(response.Errors) == 2 {
  35. if len(response.Errors["m"]) != 0 {
  36. t.Error("Decoding produced errors for topic 'm' where there were none.")
  37. }
  38. if len(response.Errors["t"]) == 1 {
  39. if response.Errors["t"][0] != types.NOT_LEADER_FOR_PARTITION {
  40. t.Error("Decoding produced wrong error for topic 't' partition 0.")
  41. }
  42. } else {
  43. t.Error("Decoding produced wrong number of errors for topic 't'.")
  44. }
  45. } else {
  46. t.Error("Decoding produced wrong number of errors.")
  47. }
  48. }