offset_commit_response_test.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package sarama
  2. import "testing"
  3. var (
  4. emptyOffsetCommitResponse = []byte{
  5. 0x00, 0x00, 0x00, 0x00}
  6. normalOffsetCommitResponse = []byte{
  7. 0x00, 0x00, 0x00, 0x02,
  8. 0x00, 0x01, 'm',
  9. 0x00, 0x00, 0x00, 0x00,
  10. 0x00, 0x01, 't',
  11. 0x00, 0x00, 0x00, 0x01,
  12. 0x00, 0x00, 0x00, 0x00,
  13. 0x00, 0x06}
  14. )
  15. func TestEmptyOffsetCommitResponse(t *testing.T) {
  16. response := OffsetCommitResponse{}
  17. testDecodable(t, "empty", &response, emptyOffsetCommitResponse)
  18. if len(response.Errors) != 0 {
  19. t.Error("Decoding produced errors where there were none.")
  20. }
  21. }
  22. func TestNormalOffsetCommitResponse(t *testing.T) {
  23. response := OffsetCommitResponse{}
  24. testDecodable(t, "normal", &response, normalOffsetCommitResponse)
  25. if len(response.Errors) != 2 {
  26. t.Fatal("Decoding produced wrong number of errors.")
  27. }
  28. if len(response.Errors["m"]) != 0 {
  29. t.Error("Decoding produced errors for topic 'm' where there were none.")
  30. }
  31. if len(response.Errors["t"]) != 1 {
  32. t.Fatal("Decoding produced wrong number of errors for topic 't'.")
  33. }
  34. if response.Errors["t"][0] != ErrNotLeaderForPartition {
  35. t.Error("Decoding produced wrong error for topic 't' partition 0.")
  36. }
  37. }