offset_fetch_request_expectation_test.go 710 B

123456789101112131415161718192021222324252627
  1. package sarama
  2. import (
  3. "bytes"
  4. "testing"
  5. )
  6. func TestOffsetFetchRequestSerialization(t *testing.T) {
  7. exp := new(OffsetFetchRequestExpectation).
  8. AddTopicPartition("my_topic", 0, 0x010101)
  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 partition
  13. 0x00, 0x00, 0x00, 0x00, // partition id
  14. 0x00, 0x00, // error
  15. 0x00, 0x00, 0x00, 0x01, // number of offsets
  16. 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, // offset
  17. }
  18. actual := exp.ResponseBytes()
  19. if bytes.Compare(actual, expected) != 0 {
  20. t.Error("\nExpected\n", expected, "\nbut got\n", actual)
  21. }
  22. }