metadata_request_test.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package sarama
  2. import "testing"
  3. var (
  4. metadataRequestNoTopicsV0 = []byte{
  5. 0x00, 0x00, 0x00, 0x00}
  6. metadataRequestOneTopicV0 = []byte{
  7. 0x00, 0x00, 0x00, 0x01,
  8. 0x00, 0x06, 't', 'o', 'p', 'i', 'c', '1'}
  9. metadataRequestThreeTopicsV0 = []byte{
  10. 0x00, 0x00, 0x00, 0x03,
  11. 0x00, 0x03, 'f', 'o', 'o',
  12. 0x00, 0x03, 'b', 'a', 'r',
  13. 0x00, 0x03, 'b', 'a', 'z'}
  14. metadataRequestNoTopicsV1 = []byte{
  15. 0xff, 0xff, 0xff, 0xff}
  16. )
  17. func TestMetadataRequestV0(t *testing.T) {
  18. request := new(MetadataRequest)
  19. testRequest(t, "no topics", request, metadataRequestNoTopicsV0)
  20. request.Topics = []string{"topic1"}
  21. testRequest(t, "one topic", request, metadataRequestOneTopicV0)
  22. request.Topics = []string{"foo", "bar", "baz"}
  23. testRequest(t, "three topics", request, metadataRequestThreeTopicsV0)
  24. }
  25. func TestMetadataRequestV1(t *testing.T) {
  26. request := new(MetadataRequest)
  27. request.Version = 1
  28. testRequest(t, "no topics", request, metadataRequestNoTopicsV1)
  29. request.Topics = []string{"topic1"}
  30. testRequest(t, "one topic", request, metadataRequestOneTopicV0)
  31. request.Topics = []string{"foo", "bar", "baz"}
  32. testRequest(t, "three topics", request, metadataRequestThreeTopicsV0)
  33. }