offset_commit_response_test.go 1.4 KB

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