describe_configs_response_test.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. package sarama
  2. import (
  3. "testing"
  4. )
  5. var (
  6. describeConfigsResponseEmpty = []byte{
  7. 0, 0, 0, 0, //throttle
  8. 0, 0, 0, 0, // no configs
  9. }
  10. describeConfigsResponsePopulatedv0 = []byte{
  11. 0, 0, 0, 0, //throttle
  12. 0, 0, 0, 1, // response
  13. 0, 0, //errorcode
  14. 0, 0, //string
  15. 2, // topic
  16. 0, 3, 'f', 'o', 'o',
  17. 0, 0, 0, 1, //configs
  18. 0, 10, 's', 'e', 'g', 'm', 'e', 'n', 't', '.', 'm', 's',
  19. 0, 4, '1', '0', '0', '0',
  20. 0, // ReadOnly
  21. 0, // Default
  22. 0, // Sensitive
  23. }
  24. describeConfigsResponsePopulatedv1 = []byte{
  25. 0, 0, 0, 0, //throttle
  26. 0, 0, 0, 1, // response
  27. 0, 0, //errorcode
  28. 0, 0, //string
  29. 2, // topic
  30. 0, 3, 'f', 'o', 'o',
  31. 0, 0, 0, 1, //configs
  32. 0, 10, 's', 'e', 'g', 'm', 'e', 'n', 't', '.', 'm', 's',
  33. 0, 4, '1', '0', '0', '0',
  34. 0, // ReadOnly
  35. 4, // Source
  36. 0, // Sensitive
  37. 0, 0, 0, 0, // No Synonym
  38. }
  39. describeConfigsResponseWithSynonymv1 = []byte{
  40. 0, 0, 0, 0, //throttle
  41. 0, 0, 0, 1, // response
  42. 0, 0, //errorcode
  43. 0, 0, //string
  44. 2, // topic
  45. 0, 3, 'f', 'o', 'o',
  46. 0, 0, 0, 1, //configs
  47. 0, 10, 's', 'e', 'g', 'm', 'e', 'n', 't', '.', 'm', 's',
  48. 0, 4, '1', '0', '0', '0',
  49. 0, // ReadOnly
  50. 4, // Source
  51. 0, // Sensitive
  52. 0, 0, 0, 1, // 1 Synonym
  53. 0, 14, 'l', 'o', 'g', '.', 's', 'e', 'g', 'm', 'e', 'n', 't', '.', 'm', 's',
  54. 0, 4, '1', '0', '0', '0',
  55. 4, // Source
  56. }
  57. )
  58. func TestDescribeConfigsResponsev0(t *testing.T) {
  59. var response *DescribeConfigsResponse
  60. response = &DescribeConfigsResponse{
  61. Resources: []*ResourceResponse{},
  62. }
  63. testVersionDecodable(t, "empty", response, describeConfigsResponseEmpty, 0)
  64. if len(response.Resources) != 0 {
  65. t.Error("Expected no groups")
  66. }
  67. response = &DescribeConfigsResponse{
  68. Version: 0, Resources: []*ResourceResponse{
  69. {
  70. ErrorCode: 0,
  71. ErrorMsg: "",
  72. Type: TopicResource,
  73. Name: "foo",
  74. Configs: []*ConfigEntry{
  75. {
  76. Name: "segment.ms",
  77. Value: "1000",
  78. ReadOnly: false,
  79. Default: false,
  80. Sensitive: false,
  81. },
  82. },
  83. },
  84. },
  85. }
  86. testResponse(t, "response with error", response, describeConfigsResponsePopulatedv0)
  87. }
  88. func TestDescribeConfigsResponsev1(t *testing.T) {
  89. var response *DescribeConfigsResponse
  90. response = &DescribeConfigsResponse{
  91. Resources: []*ResourceResponse{},
  92. }
  93. testVersionDecodable(t, "empty", response, describeConfigsResponseEmpty, 0)
  94. if len(response.Resources) != 0 {
  95. t.Error("Expected no groups")
  96. }
  97. response = &DescribeConfigsResponse{
  98. Version: 1,
  99. Resources: []*ResourceResponse{
  100. {
  101. ErrorCode: 0,
  102. ErrorMsg: "",
  103. Type: TopicResource,
  104. Name: "foo",
  105. Configs: []*ConfigEntry{
  106. {
  107. Name: "segment.ms",
  108. Value: "1000",
  109. ReadOnly: false,
  110. Source: SourceStaticBroker,
  111. Sensitive: false,
  112. Synonyms: []*ConfigSynonym{},
  113. },
  114. },
  115. },
  116. },
  117. }
  118. testResponse(t, "response with error", response, describeConfigsResponsePopulatedv1)
  119. }
  120. func TestDescribeConfigsResponseWithSynonym(t *testing.T) {
  121. var response *DescribeConfigsResponse
  122. response = &DescribeConfigsResponse{
  123. Resources: []*ResourceResponse{},
  124. }
  125. testVersionDecodable(t, "empty", response, describeConfigsResponseEmpty, 0)
  126. if len(response.Resources) != 0 {
  127. t.Error("Expected no groups")
  128. }
  129. response = &DescribeConfigsResponse{
  130. Version: 1,
  131. Resources: []*ResourceResponse{
  132. {
  133. ErrorCode: 0,
  134. ErrorMsg: "",
  135. Type: TopicResource,
  136. Name: "foo",
  137. Configs: []*ConfigEntry{
  138. {
  139. Name: "segment.ms",
  140. Value: "1000",
  141. ReadOnly: false,
  142. Source: SourceStaticBroker,
  143. Sensitive: false,
  144. Synonyms: []*ConfigSynonym{
  145. {
  146. ConfigName: "log.segment.ms",
  147. ConfigValue: "1000",
  148. Source: SourceStaticBroker,
  149. },
  150. },
  151. },
  152. },
  153. },
  154. },
  155. }
  156. testResponse(t, "response with error", response, describeConfigsResponseWithSynonymv1)
  157. }