describe_configs_request_test.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package sarama
  2. import "testing"
  3. var (
  4. emptyDescribeConfigsRequest = []byte{
  5. 0, 0, 0, 0, // 0 configs
  6. }
  7. singleDescribeConfigsRequest = []byte{
  8. 0, 0, 0, 1, // 1 config
  9. 2, // a topic
  10. 0, 3, 'f', 'o', 'o', // topic name: foo
  11. 0, 0, 0, 1, //1 config name
  12. 0, 10, // 10 chars
  13. 's', 'e', 'g', 'm', 'e', 'n', 't', '.', 'm', 's',
  14. }
  15. doubleDescribeConfigsRequest = []byte{
  16. 0, 0, 0, 2, // 2 configs
  17. 2, // a topic
  18. 0, 3, 'f', 'o', 'o', // topic name: foo
  19. 0, 0, 0, 2, //2 config name
  20. 0, 10, // 10 chars
  21. 's', 'e', 'g', 'm', 'e', 'n', 't', '.', 'm', 's',
  22. 0, 12, // 12 chars
  23. 'r', 'e', 't', 'e', 'n', 't', 'i', 'o', 'n', '.', 'm', 's',
  24. 2, // a topic
  25. 0, 3, 'b', 'a', 'r', // topic name: foo
  26. 0, 0, 0, 1, // 1 config
  27. 0, 10, // 10 chars
  28. 's', 'e', 'g', 'm', 'e', 'n', 't', '.', 'm', 's',
  29. }
  30. singleDescribeConfigsRequestAllConfigs = []byte{
  31. 0, 0, 0, 1, // 1 config
  32. 2, // a topic
  33. 0, 3, 'f', 'o', 'o', // topic name: foo
  34. 255, 255, 255, 255, // no configs
  35. }
  36. )
  37. func TestDescribeConfigsRequest(t *testing.T) {
  38. var request *DescribeConfigsRequest
  39. request = &DescribeConfigsRequest{
  40. Resources: []*ConfigResource{},
  41. }
  42. testRequest(t, "no requests", request, emptyDescribeConfigsRequest)
  43. configs := []string{"segment.ms"}
  44. request = &DescribeConfigsRequest{
  45. Resources: []*ConfigResource{
  46. &ConfigResource{
  47. Type: TopicResource,
  48. Name: "foo",
  49. ConfigNames: configs,
  50. },
  51. },
  52. }
  53. testRequest(t, "one config", request, singleDescribeConfigsRequest)
  54. request = &DescribeConfigsRequest{
  55. Resources: []*ConfigResource{
  56. &ConfigResource{
  57. Type: TopicResource,
  58. Name: "foo",
  59. ConfigNames: []string{"segment.ms", "retention.ms"},
  60. },
  61. &ConfigResource{
  62. Type: TopicResource,
  63. Name: "bar",
  64. ConfigNames: []string{"segment.ms"},
  65. },
  66. },
  67. }
  68. testRequest(t, "two configs", request, doubleDescribeConfigsRequest)
  69. request = &DescribeConfigsRequest{
  70. Resources: []*ConfigResource{
  71. &ConfigResource{
  72. Type: TopicResource,
  73. Name: "foo",
  74. },
  75. },
  76. }
  77. testRequest(t, "one topic, all configs", request, singleDescribeConfigsRequestAllConfigs)
  78. }