offset_response_test.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package sarama
  2. import "testing"
  3. var (
  4. emptyOffsetResponse = []byte{
  5. 0x00, 0x00, 0x00, 0x00}
  6. normalOffsetResponse = []byte{
  7. 0x00, 0x00, 0x00, 0x02,
  8. 0x00, 0x01, 'a',
  9. 0x00, 0x00, 0x00, 0x00,
  10. 0x00, 0x01, 'z',
  11. 0x00, 0x00, 0x00, 0x01,
  12. 0x00, 0x00, 0x00, 0x02,
  13. 0x00, 0x00,
  14. 0x00, 0x00, 0x00, 0x02,
  15. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05,
  16. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06}
  17. )
  18. func TestEmptyOffsetResponse(t *testing.T) {
  19. response := OffsetResponse{}
  20. testDecodable(t, "empty", &response, emptyOffsetResponse)
  21. if len(response.Blocks) != 0 {
  22. t.Error("Decoding produced", len(response.Blocks), "topics where there were none.")
  23. }
  24. }
  25. func TestNormalOffsetResponse(t *testing.T) {
  26. response := OffsetResponse{}
  27. testDecodable(t, "normal", &response, normalOffsetResponse)
  28. if len(response.Blocks) != 2 {
  29. t.Fatal("Decoding produced", len(response.Blocks), "topics where there were two.")
  30. }
  31. if len(response.Blocks["a"]) != 0 {
  32. t.Fatal("Decoding produced", len(response.Blocks["a"]), "partitions for topic 'a' where there were none.")
  33. }
  34. if len(response.Blocks["z"]) != 1 {
  35. t.Fatal("Decoding produced", len(response.Blocks["z"]), "partitions for topic 'z' where there was one.")
  36. }
  37. if response.Blocks["z"][2].Err != ErrNoError {
  38. t.Fatal("Decoding produced invalid error for topic z partition 2.")
  39. }
  40. if len(response.Blocks["z"][2].Offsets) != 2 {
  41. t.Fatal("Decoding produced invalid number of offsets for topic z partition 2.")
  42. }
  43. if response.Blocks["z"][2].Offsets[0] != 5 || response.Blocks["z"][2].Offsets[1] != 6 {
  44. t.Fatal("Decoding produced invalid offsets for topic z partition 2.")
  45. }
  46. }