describe_configs_response_test.go 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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. describeConfigsResponseWithDefaultv0 = []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. 1, // Default
  36. 0, // Sensitive
  37. }
  38. describeConfigsResponsePopulatedv1 = []byte{
  39. 0, 0, 0, 0, //throttle
  40. 0, 0, 0, 1, // response
  41. 0, 0, //errorcode
  42. 0, 0, //string
  43. 2, // topic
  44. 0, 3, 'f', 'o', 'o',
  45. 0, 0, 0, 1, //configs
  46. 0, 10, 's', 'e', 'g', 'm', 'e', 'n', 't', '.', 'm', 's',
  47. 0, 4, '1', '0', '0', '0',
  48. 0, // ReadOnly
  49. 4, // Source
  50. 0, // Sensitive
  51. 0, 0, 0, 0, // No Synonym
  52. }
  53. describeConfigsResponseWithSynonymv1 = []byte{
  54. 0, 0, 0, 0, //throttle
  55. 0, 0, 0, 1, // response
  56. 0, 0, //errorcode
  57. 0, 0, //string
  58. 2, // topic
  59. 0, 3, 'f', 'o', 'o',
  60. 0, 0, 0, 1, //configs
  61. 0, 10, 's', 'e', 'g', 'm', 'e', 'n', 't', '.', 'm', 's',
  62. 0, 4, '1', '0', '0', '0',
  63. 0, // ReadOnly
  64. 4, // Source
  65. 0, // Sensitive
  66. 0, 0, 0, 1, // 1 Synonym
  67. 0, 14, 'l', 'o', 'g', '.', 's', 'e', 'g', 'm', 'e', 'n', 't', '.', 'm', 's',
  68. 0, 4, '1', '0', '0', '0',
  69. 4, // Source
  70. }
  71. describeConfigsResponseWithDefaultv1 = []byte{
  72. 0, 0, 0, 0, //throttle
  73. 0, 0, 0, 1, // response
  74. 0, 0, //errorcode
  75. 0, 0, //string
  76. 2, // topic
  77. 0, 3, 'f', 'o', 'o',
  78. 0, 0, 0, 1, //configs
  79. 0, 10, 's', 'e', 'g', 'm', 'e', 'n', 't', '.', 'm', 's',
  80. 0, 4, '1', '0', '0', '0',
  81. 0, // ReadOnly
  82. 5, // Source
  83. 0, // Sensitive
  84. 0, 0, 0, 0, // No Synonym
  85. }
  86. )
  87. func TestDescribeConfigsResponsev0(t *testing.T) {
  88. var response *DescribeConfigsResponse
  89. response = &DescribeConfigsResponse{
  90. Resources: []*ResourceResponse{},
  91. }
  92. testVersionDecodable(t, "empty", response, describeConfigsResponseEmpty, 0)
  93. if len(response.Resources) != 0 {
  94. t.Error("Expected no groups")
  95. }
  96. response = &DescribeConfigsResponse{
  97. Version: 0, Resources: []*ResourceResponse{
  98. {
  99. ErrorCode: 0,
  100. ErrorMsg: "",
  101. Type: TopicResource,
  102. Name: "foo",
  103. Configs: []*ConfigEntry{
  104. {
  105. Name: "segment.ms",
  106. Value: "1000",
  107. ReadOnly: false,
  108. Default: false,
  109. Sensitive: false,
  110. Source: SourceUnknown,
  111. },
  112. },
  113. },
  114. },
  115. }
  116. testResponse(t, "response with error", response, describeConfigsResponsePopulatedv0)
  117. }
  118. func TestDescribeConfigsResponseWithDefaultv0(t *testing.T) {
  119. var response *DescribeConfigsResponse
  120. response = &DescribeConfigsResponse{
  121. Resources: []*ResourceResponse{},
  122. }
  123. testVersionDecodable(t, "empty", response, describeConfigsResponseEmpty, 0)
  124. if len(response.Resources) != 0 {
  125. t.Error("Expected no groups")
  126. }
  127. response = &DescribeConfigsResponse{
  128. Version: 0, Resources: []*ResourceResponse{
  129. {
  130. ErrorCode: 0,
  131. ErrorMsg: "",
  132. Type: TopicResource,
  133. Name: "foo",
  134. Configs: []*ConfigEntry{
  135. {
  136. Name: "segment.ms",
  137. Value: "1000",
  138. ReadOnly: false,
  139. Default: true,
  140. Sensitive: false,
  141. Source: SourceDefault,
  142. },
  143. },
  144. },
  145. },
  146. }
  147. testResponse(t, "response with default", response, describeConfigsResponseWithDefaultv0)
  148. }
  149. func TestDescribeConfigsResponsev1(t *testing.T) {
  150. var response *DescribeConfigsResponse
  151. response = &DescribeConfigsResponse{
  152. Resources: []*ResourceResponse{},
  153. }
  154. testVersionDecodable(t, "empty", response, describeConfigsResponseEmpty, 0)
  155. if len(response.Resources) != 0 {
  156. t.Error("Expected no groups")
  157. }
  158. response = &DescribeConfigsResponse{
  159. Version: 1,
  160. Resources: []*ResourceResponse{
  161. {
  162. ErrorCode: 0,
  163. ErrorMsg: "",
  164. Type: TopicResource,
  165. Name: "foo",
  166. Configs: []*ConfigEntry{
  167. {
  168. Name: "segment.ms",
  169. Value: "1000",
  170. ReadOnly: false,
  171. Source: SourceStaticBroker,
  172. Default: false,
  173. Sensitive: false,
  174. Synonyms: []*ConfigSynonym{},
  175. },
  176. },
  177. },
  178. },
  179. }
  180. testResponse(t, "response with error", response, describeConfigsResponsePopulatedv1)
  181. }
  182. func TestDescribeConfigsResponseWithSynonym(t *testing.T) {
  183. var response *DescribeConfigsResponse
  184. response = &DescribeConfigsResponse{
  185. Resources: []*ResourceResponse{},
  186. }
  187. testVersionDecodable(t, "empty", response, describeConfigsResponseEmpty, 0)
  188. if len(response.Resources) != 0 {
  189. t.Error("Expected no groups")
  190. }
  191. response = &DescribeConfigsResponse{
  192. Version: 1,
  193. Resources: []*ResourceResponse{
  194. {
  195. ErrorCode: 0,
  196. ErrorMsg: "",
  197. Type: TopicResource,
  198. Name: "foo",
  199. Configs: []*ConfigEntry{
  200. {
  201. Name: "segment.ms",
  202. Value: "1000",
  203. ReadOnly: false,
  204. Source: SourceStaticBroker,
  205. Default: false,
  206. Sensitive: false,
  207. Synonyms: []*ConfigSynonym{
  208. {
  209. ConfigName: "log.segment.ms",
  210. ConfigValue: "1000",
  211. Source: SourceStaticBroker,
  212. },
  213. },
  214. },
  215. },
  216. },
  217. },
  218. }
  219. testResponse(t, "response with error", response, describeConfigsResponseWithSynonymv1)
  220. }
  221. func TestDescribeConfigsResponseWithDefaultv1(t *testing.T) {
  222. var response *DescribeConfigsResponse
  223. response = &DescribeConfigsResponse{
  224. Resources: []*ResourceResponse{},
  225. }
  226. testVersionDecodable(t, "empty", response, describeConfigsResponseEmpty, 0)
  227. if len(response.Resources) != 0 {
  228. t.Error("Expected no groups")
  229. }
  230. response = &DescribeConfigsResponse{
  231. Version: 1,
  232. Resources: []*ResourceResponse{
  233. {
  234. ErrorCode: 0,
  235. ErrorMsg: "",
  236. Type: TopicResource,
  237. Name: "foo",
  238. Configs: []*ConfigEntry{
  239. {
  240. Name: "segment.ms",
  241. Value: "1000",
  242. ReadOnly: false,
  243. Source: SourceDefault,
  244. Default: true,
  245. Sensitive: false,
  246. Synonyms: []*ConfigSynonym{},
  247. },
  248. },
  249. },
  250. },
  251. }
  252. testResponse(t, "response with error", response, describeConfigsResponseWithDefaultv1)
  253. }