describe_configs_request_test.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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, // all configs
  35. }
  36. singleDescribeConfigsRequestAllConfigsv1 = []byte{
  37. 0, 0, 0, 1, // 1 config
  38. 2, // a topic
  39. 0, 3, 'f', 'o', 'o', // topic name: foo
  40. 255, 255, 255, 255, // no configs
  41. 1, //synoms
  42. }
  43. )
  44. func TestDescribeConfigsRequestv0(t *testing.T) {
  45. var request *DescribeConfigsRequest
  46. request = &DescribeConfigsRequest{
  47. Version: 0,
  48. Resources: []*ConfigResource{},
  49. }
  50. testRequest(t, "no requests", request, emptyDescribeConfigsRequest)
  51. configs := []string{"segment.ms"}
  52. request = &DescribeConfigsRequest{
  53. Version: 0,
  54. Resources: []*ConfigResource{
  55. {
  56. Type: TopicResource,
  57. Name: "foo",
  58. ConfigNames: configs,
  59. },
  60. },
  61. }
  62. testRequest(t, "one config", request, singleDescribeConfigsRequest)
  63. request = &DescribeConfigsRequest{
  64. Version: 0,
  65. Resources: []*ConfigResource{
  66. {
  67. Type: TopicResource,
  68. Name: "foo",
  69. ConfigNames: []string{"segment.ms", "retention.ms"},
  70. },
  71. {
  72. Type: TopicResource,
  73. Name: "bar",
  74. ConfigNames: []string{"segment.ms"},
  75. },
  76. },
  77. }
  78. testRequest(t, "two configs", request, doubleDescribeConfigsRequest)
  79. request = &DescribeConfigsRequest{
  80. Version: 0,
  81. Resources: []*ConfigResource{
  82. {
  83. Type: TopicResource,
  84. Name: "foo",
  85. },
  86. },
  87. }
  88. testRequest(t, "one topic, all configs", request, singleDescribeConfigsRequestAllConfigs)
  89. }
  90. func TestDescribeConfigsRequestv1(t *testing.T) {
  91. var request *DescribeConfigsRequest
  92. request = &DescribeConfigsRequest{
  93. Version: 1,
  94. Resources: []*ConfigResource{
  95. {
  96. Type: TopicResource,
  97. Name: "foo",
  98. },
  99. },
  100. IncludeSynonyms: true,
  101. }
  102. testRequest(t, "one topic, all configs", request, singleDescribeConfigsRequestAllConfigsv1)
  103. }