offset_request_test.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package sarama
  2. import "testing"
  3. var (
  4. offsetRequestNoBlocks = []byte{
  5. 0xFF, 0xFF, 0xFF, 0xFF,
  6. 0x00, 0x00, 0x00, 0x00}
  7. offsetRequestOneBlock = []byte{
  8. 0xFF, 0xFF, 0xFF, 0xFF,
  9. 0x00, 0x00, 0x00, 0x01,
  10. 0x00, 0x03, 'f', 'o', 'o',
  11. 0x00, 0x00, 0x00, 0x01,
  12. 0x00, 0x00, 0x00, 0x04,
  13. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
  14. 0x00, 0x00, 0x00, 0x02}
  15. offsetRequestOneBlockV1 = []byte{
  16. 0xFF, 0xFF, 0xFF, 0xFF,
  17. 0x00, 0x00, 0x00, 0x01,
  18. 0x00, 0x03, 'b', 'a', 'r',
  19. 0x00, 0x00, 0x00, 0x01,
  20. 0x00, 0x00, 0x00, 0x04,
  21. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}
  22. )
  23. func TestOffsetRequest(t *testing.T) {
  24. request := new(OffsetRequest)
  25. testRequest(t, "no blocks", request, offsetRequestNoBlocks)
  26. request.AddBlock("foo", 4, 1, 2)
  27. testRequest(t, "one block", request, offsetRequestOneBlock)
  28. }
  29. func TestOffsetRequestV1(t *testing.T) {
  30. request := new(OffsetRequest)
  31. request.Version = 1
  32. testRequest(t, "no blocks", request, offsetRequestNoBlocks)
  33. request.AddBlock("bar", 4, 1, 2) // Last argument is ignored for V1
  34. testRequest(t, "one block", request, offsetRequestOneBlockV1)
  35. }