offset_fetch_request_test.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package sarama
  2. import (
  3. "fmt"
  4. "testing"
  5. )
  6. var (
  7. offsetFetchRequestNoGroupNoPartitions = []byte{
  8. 0x00, 0x00,
  9. 0x00, 0x00, 0x00, 0x00}
  10. offsetFetchRequestNoPartitions = []byte{
  11. 0x00, 0x04, 'b', 'l', 'a', 'h',
  12. 0x00, 0x00, 0x00, 0x00}
  13. offsetFetchRequestOnePartition = []byte{
  14. 0x00, 0x04, 'b', 'l', 'a', 'h',
  15. 0x00, 0x00, 0x00, 0x01,
  16. 0x00, 0x0D, 't', 'o', 'p', 'i', 'c', 'T', 'h', 'e', 'F', 'i', 'r', 's', 't',
  17. 0x00, 0x00, 0x00, 0x01,
  18. 0x4F, 0x4F, 0x4F, 0x4F}
  19. offsetFetchRequestAllPartitions = []byte{
  20. 0x00, 0x04, 'b', 'l', 'a', 'h',
  21. 0xff, 0xff, 0xff, 0xff}
  22. )
  23. func TestOffsetFetchRequestNoPartitions(t *testing.T) {
  24. for version := 0; version <= 5; version++ {
  25. request := new(OffsetFetchRequest)
  26. request.Version = int16(version)
  27. request.ZeroPartitions()
  28. testRequest(t, fmt.Sprintf("no group, no partitions %d", version), request, offsetFetchRequestNoGroupNoPartitions)
  29. request.ConsumerGroup = "blah"
  30. testRequest(t, fmt.Sprintf("no partitions %d", version), request, offsetFetchRequestNoPartitions)
  31. }
  32. }
  33. func TestOffsetFetchRequest(t *testing.T) {
  34. for version := 0; version <= 5; version++ {
  35. request := new(OffsetFetchRequest)
  36. request.Version = int16(version)
  37. request.ConsumerGroup = "blah"
  38. request.AddPartition("topicTheFirst", 0x4F4F4F4F)
  39. testRequest(t, fmt.Sprintf("one partition %d", version), request, offsetFetchRequestOnePartition)
  40. }
  41. }
  42. func TestOffsetFetchRequestAllPartitions(t *testing.T) {
  43. for version := 2; version <= 5; version++ {
  44. request := &OffsetFetchRequest{Version: int16(version), ConsumerGroup: "blah"}
  45. testRequest(t, fmt.Sprintf("all partitions %d", version), request, offsetFetchRequestAllPartitions)
  46. }
  47. }