fetch_request_expectation_test.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. package sarama
  2. import (
  3. "bytes"
  4. "testing"
  5. )
  6. func TestFetchRequestSerialization(t *testing.T) {
  7. exp := new(FetchRequestExpectation).
  8. AddMessage("my_topic", 0, nil, ByteEncoder([]byte{0x00, 0xEE}), 3)
  9. expected := []byte{
  10. 0x00, 0x00, 0x00, 0x01, // number of topics
  11. 0x00, 0x08, 'm', 'y', '_', 't', 'o', 'p', 'i', 'c', // topic name
  12. 0x00, 0x00, 0x00, 0x01, // number of blocks for this topic
  13. 0x00, 0x00, 0x00, 0x00, // partition id
  14. 0x00, 0x00, // error
  15. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // high water mark offset
  16. // messageSet
  17. 0x00, 0x00, 0x00, 0x1C, // messageset size
  18. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, // offset
  19. // message
  20. 0x00, 0x00, 0x00, 0x10, // length of message (?)
  21. 0x23, 0x96, 0x4a, 0xf7, // CRC32
  22. 0x00, // format
  23. 0x00, // attribute (compression)
  24. 0xFF, 0xFF, 0xFF, 0xFF, // key (nil)
  25. 0x00, 0x00, 0x00, 0x02, 0x00, 0xEE, // value
  26. }
  27. actual := exp.ResponseBytes()
  28. if bytes.Compare(actual, expected) != 0 {
  29. t.Error("\nExpected\n", expected, "\nbut got\n", actual)
  30. }
  31. }