fluentd 1.14.4-x64-mingw-ucrt

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of fluentd might be problematic. Click here for more details.

Files changed (558) hide show
  1. checksums.yaml +7 -0
  2. data/.deepsource.toml +13 -0
  3. data/.drone.yml +35 -0
  4. data/.github/ISSUE_TEMPLATE/bug_report.yaml +70 -0
  5. data/.github/ISSUE_TEMPLATE/config.yml +5 -0
  6. data/.github/ISSUE_TEMPLATE/feature_request.yaml +38 -0
  7. data/.github/ISSUE_TEMPLATE.md +17 -0
  8. data/.github/PULL_REQUEST_TEMPLATE.md +14 -0
  9. data/.github/workflows/issue-auto-closer.yml +12 -0
  10. data/.github/workflows/linux-test.yaml +36 -0
  11. data/.github/workflows/macos-test.yaml +30 -0
  12. data/.github/workflows/stale-actions.yml +22 -0
  13. data/.github/workflows/windows-test.yaml +46 -0
  14. data/.gitignore +30 -0
  15. data/.gitlab-ci.yml +103 -0
  16. data/ADOPTERS.md +5 -0
  17. data/AUTHORS +2 -0
  18. data/CHANGELOG.md +2409 -0
  19. data/CONTRIBUTING.md +45 -0
  20. data/GOVERNANCE.md +55 -0
  21. data/Gemfile +9 -0
  22. data/GithubWorkflow.md +78 -0
  23. data/LICENSE +202 -0
  24. data/MAINTAINERS.md +11 -0
  25. data/README.md +97 -0
  26. data/Rakefile +79 -0
  27. data/SECURITY.md +18 -0
  28. data/bin/fluent-binlog-reader +7 -0
  29. data/bin/fluent-ca-generate +6 -0
  30. data/bin/fluent-cap-ctl +7 -0
  31. data/bin/fluent-cat +5 -0
  32. data/bin/fluent-ctl +7 -0
  33. data/bin/fluent-debug +5 -0
  34. data/bin/fluent-gem +9 -0
  35. data/bin/fluent-plugin-config-format +5 -0
  36. data/bin/fluent-plugin-generate +5 -0
  37. data/bin/fluentd +15 -0
  38. data/code-of-conduct.md +3 -0
  39. data/docs/SECURITY_AUDIT.pdf +0 -0
  40. data/example/copy_roundrobin.conf +39 -0
  41. data/example/counter.conf +18 -0
  42. data/example/filter_stdout.conf +22 -0
  43. data/example/in_forward.conf +14 -0
  44. data/example/in_forward_client.conf +37 -0
  45. data/example/in_forward_shared_key.conf +15 -0
  46. data/example/in_forward_tls.conf +14 -0
  47. data/example/in_forward_users.conf +24 -0
  48. data/example/in_forward_workers.conf +21 -0
  49. data/example/in_http.conf +16 -0
  50. data/example/in_out_forward.conf +17 -0
  51. data/example/in_sample_blocks.conf +17 -0
  52. data/example/in_sample_with_compression.conf +23 -0
  53. data/example/in_syslog.conf +15 -0
  54. data/example/in_tail.conf +14 -0
  55. data/example/in_tcp.conf +13 -0
  56. data/example/in_udp.conf +13 -0
  57. data/example/logevents.conf +25 -0
  58. data/example/multi_filters.conf +61 -0
  59. data/example/out_copy.conf +20 -0
  60. data/example/out_exec_filter.conf +42 -0
  61. data/example/out_file.conf +13 -0
  62. data/example/out_forward.conf +35 -0
  63. data/example/out_forward_buf_file.conf +23 -0
  64. data/example/out_forward_client.conf +109 -0
  65. data/example/out_forward_heartbeat_none.conf +16 -0
  66. data/example/out_forward_sd.conf +17 -0
  67. data/example/out_forward_shared_key.conf +36 -0
  68. data/example/out_forward_tls.conf +18 -0
  69. data/example/out_forward_users.conf +65 -0
  70. data/example/out_null.conf +36 -0
  71. data/example/sd.yaml +8 -0
  72. data/example/secondary_file.conf +42 -0
  73. data/example/suppress_config_dump.conf +7 -0
  74. data/example/v0_12_filter.conf +78 -0
  75. data/example/v1_literal_example.conf +36 -0
  76. data/example/worker_section.conf +36 -0
  77. data/fluent.conf +139 -0
  78. data/fluentd.gemspec +55 -0
  79. data/lib/fluent/agent.rb +168 -0
  80. data/lib/fluent/capability.rb +87 -0
  81. data/lib/fluent/clock.rb +66 -0
  82. data/lib/fluent/command/binlog_reader.rb +244 -0
  83. data/lib/fluent/command/bundler_injection.rb +45 -0
  84. data/lib/fluent/command/ca_generate.rb +184 -0
  85. data/lib/fluent/command/cap_ctl.rb +174 -0
  86. data/lib/fluent/command/cat.rb +365 -0
  87. data/lib/fluent/command/ctl.rb +177 -0
  88. data/lib/fluent/command/debug.rb +103 -0
  89. data/lib/fluent/command/fluentd.rb +374 -0
  90. data/lib/fluent/command/plugin_config_formatter.rb +308 -0
  91. data/lib/fluent/command/plugin_generator.rb +365 -0
  92. data/lib/fluent/compat/call_super_mixin.rb +76 -0
  93. data/lib/fluent/compat/detach_process_mixin.rb +33 -0
  94. data/lib/fluent/compat/exec_util.rb +129 -0
  95. data/lib/fluent/compat/file_util.rb +54 -0
  96. data/lib/fluent/compat/filter.rb +68 -0
  97. data/lib/fluent/compat/formatter.rb +111 -0
  98. data/lib/fluent/compat/formatter_utils.rb +85 -0
  99. data/lib/fluent/compat/handle_tag_and_time_mixin.rb +62 -0
  100. data/lib/fluent/compat/handle_tag_name_mixin.rb +53 -0
  101. data/lib/fluent/compat/input.rb +49 -0
  102. data/lib/fluent/compat/output.rb +721 -0
  103. data/lib/fluent/compat/output_chain.rb +60 -0
  104. data/lib/fluent/compat/parser.rb +310 -0
  105. data/lib/fluent/compat/parser_utils.rb +40 -0
  106. data/lib/fluent/compat/propagate_default.rb +62 -0
  107. data/lib/fluent/compat/record_filter_mixin.rb +34 -0
  108. data/lib/fluent/compat/set_tag_key_mixin.rb +50 -0
  109. data/lib/fluent/compat/set_time_key_mixin.rb +69 -0
  110. data/lib/fluent/compat/socket_util.rb +165 -0
  111. data/lib/fluent/compat/string_util.rb +34 -0
  112. data/lib/fluent/compat/structured_format_mixin.rb +26 -0
  113. data/lib/fluent/compat/type_converter.rb +90 -0
  114. data/lib/fluent/config/basic_parser.rb +123 -0
  115. data/lib/fluent/config/configure_proxy.rb +424 -0
  116. data/lib/fluent/config/dsl.rb +152 -0
  117. data/lib/fluent/config/element.rb +265 -0
  118. data/lib/fluent/config/error.rb +32 -0
  119. data/lib/fluent/config/literal_parser.rb +286 -0
  120. data/lib/fluent/config/parser.rb +107 -0
  121. data/lib/fluent/config/section.rb +272 -0
  122. data/lib/fluent/config/types.rb +249 -0
  123. data/lib/fluent/config/v1_parser.rb +192 -0
  124. data/lib/fluent/config.rb +76 -0
  125. data/lib/fluent/configurable.rb +201 -0
  126. data/lib/fluent/counter/base_socket.rb +44 -0
  127. data/lib/fluent/counter/client.rb +297 -0
  128. data/lib/fluent/counter/error.rb +86 -0
  129. data/lib/fluent/counter/mutex_hash.rb +163 -0
  130. data/lib/fluent/counter/server.rb +273 -0
  131. data/lib/fluent/counter/store.rb +205 -0
  132. data/lib/fluent/counter/validator.rb +145 -0
  133. data/lib/fluent/counter.rb +23 -0
  134. data/lib/fluent/daemon.rb +15 -0
  135. data/lib/fluent/daemonizer.rb +88 -0
  136. data/lib/fluent/engine.rb +253 -0
  137. data/lib/fluent/env.rb +40 -0
  138. data/lib/fluent/error.rb +34 -0
  139. data/lib/fluent/event.rb +326 -0
  140. data/lib/fluent/event_router.rb +297 -0
  141. data/lib/fluent/ext_monitor_require.rb +28 -0
  142. data/lib/fluent/filter.rb +21 -0
  143. data/lib/fluent/fluent_log_event_router.rb +141 -0
  144. data/lib/fluent/formatter.rb +23 -0
  145. data/lib/fluent/input.rb +21 -0
  146. data/lib/fluent/label.rb +46 -0
  147. data/lib/fluent/load.rb +34 -0
  148. data/lib/fluent/log.rb +713 -0
  149. data/lib/fluent/match.rb +187 -0
  150. data/lib/fluent/mixin.rb +31 -0
  151. data/lib/fluent/msgpack_factory.rb +106 -0
  152. data/lib/fluent/oj_options.rb +62 -0
  153. data/lib/fluent/output.rb +29 -0
  154. data/lib/fluent/output_chain.rb +23 -0
  155. data/lib/fluent/parser.rb +23 -0
  156. data/lib/fluent/plugin/bare_output.rb +104 -0
  157. data/lib/fluent/plugin/base.rb +197 -0
  158. data/lib/fluent/plugin/buf_file.rb +213 -0
  159. data/lib/fluent/plugin/buf_file_single.rb +225 -0
  160. data/lib/fluent/plugin/buf_memory.rb +34 -0
  161. data/lib/fluent/plugin/buffer/chunk.rb +240 -0
  162. data/lib/fluent/plugin/buffer/file_chunk.rb +413 -0
  163. data/lib/fluent/plugin/buffer/file_single_chunk.rb +311 -0
  164. data/lib/fluent/plugin/buffer/memory_chunk.rb +91 -0
  165. data/lib/fluent/plugin/buffer.rb +918 -0
  166. data/lib/fluent/plugin/compressable.rb +96 -0
  167. data/lib/fluent/plugin/exec_util.rb +22 -0
  168. data/lib/fluent/plugin/file_util.rb +22 -0
  169. data/lib/fluent/plugin/file_wrapper.rb +187 -0
  170. data/lib/fluent/plugin/filter.rb +127 -0
  171. data/lib/fluent/plugin/filter_grep.rb +189 -0
  172. data/lib/fluent/plugin/filter_parser.rb +130 -0
  173. data/lib/fluent/plugin/filter_record_transformer.rb +324 -0
  174. data/lib/fluent/plugin/filter_stdout.rb +53 -0
  175. data/lib/fluent/plugin/formatter.rb +75 -0
  176. data/lib/fluent/plugin/formatter_csv.rb +78 -0
  177. data/lib/fluent/plugin/formatter_hash.rb +35 -0
  178. data/lib/fluent/plugin/formatter_json.rb +59 -0
  179. data/lib/fluent/plugin/formatter_ltsv.rb +44 -0
  180. data/lib/fluent/plugin/formatter_msgpack.rb +33 -0
  181. data/lib/fluent/plugin/formatter_out_file.rb +53 -0
  182. data/lib/fluent/plugin/formatter_single_value.rb +36 -0
  183. data/lib/fluent/plugin/formatter_stdout.rb +76 -0
  184. data/lib/fluent/plugin/formatter_tsv.rb +40 -0
  185. data/lib/fluent/plugin/in_debug_agent.rb +71 -0
  186. data/lib/fluent/plugin/in_dummy.rb +18 -0
  187. data/lib/fluent/plugin/in_exec.rb +110 -0
  188. data/lib/fluent/plugin/in_forward.rb +473 -0
  189. data/lib/fluent/plugin/in_gc_stat.rb +72 -0
  190. data/lib/fluent/plugin/in_http.rb +667 -0
  191. data/lib/fluent/plugin/in_monitor_agent.rb +412 -0
  192. data/lib/fluent/plugin/in_object_space.rb +93 -0
  193. data/lib/fluent/plugin/in_sample.rb +141 -0
  194. data/lib/fluent/plugin/in_syslog.rb +276 -0
  195. data/lib/fluent/plugin/in_tail/position_file.rb +269 -0
  196. data/lib/fluent/plugin/in_tail.rb +1228 -0
  197. data/lib/fluent/plugin/in_tcp.rb +181 -0
  198. data/lib/fluent/plugin/in_udp.rb +92 -0
  199. data/lib/fluent/plugin/in_unix.rb +195 -0
  200. data/lib/fluent/plugin/input.rb +75 -0
  201. data/lib/fluent/plugin/metrics.rb +119 -0
  202. data/lib/fluent/plugin/metrics_local.rb +96 -0
  203. data/lib/fluent/plugin/multi_output.rb +195 -0
  204. data/lib/fluent/plugin/out_copy.rb +120 -0
  205. data/lib/fluent/plugin/out_exec.rb +105 -0
  206. data/lib/fluent/plugin/out_exec_filter.rb +319 -0
  207. data/lib/fluent/plugin/out_file.rb +334 -0
  208. data/lib/fluent/plugin/out_forward/ack_handler.rb +161 -0
  209. data/lib/fluent/plugin/out_forward/connection_manager.rb +113 -0
  210. data/lib/fluent/plugin/out_forward/error.rb +28 -0
  211. data/lib/fluent/plugin/out_forward/failure_detector.rb +84 -0
  212. data/lib/fluent/plugin/out_forward/handshake_protocol.rb +125 -0
  213. data/lib/fluent/plugin/out_forward/load_balancer.rb +114 -0
  214. data/lib/fluent/plugin/out_forward/socket_cache.rb +140 -0
  215. data/lib/fluent/plugin/out_forward.rb +826 -0
  216. data/lib/fluent/plugin/out_http.rb +275 -0
  217. data/lib/fluent/plugin/out_null.rb +74 -0
  218. data/lib/fluent/plugin/out_relabel.rb +32 -0
  219. data/lib/fluent/plugin/out_roundrobin.rb +84 -0
  220. data/lib/fluent/plugin/out_secondary_file.rb +131 -0
  221. data/lib/fluent/plugin/out_stdout.rb +74 -0
  222. data/lib/fluent/plugin/out_stream.rb +130 -0
  223. data/lib/fluent/plugin/output.rb +1556 -0
  224. data/lib/fluent/plugin/owned_by_mixin.rb +42 -0
  225. data/lib/fluent/plugin/parser.rb +275 -0
  226. data/lib/fluent/plugin/parser_apache.rb +28 -0
  227. data/lib/fluent/plugin/parser_apache2.rb +88 -0
  228. data/lib/fluent/plugin/parser_apache_error.rb +26 -0
  229. data/lib/fluent/plugin/parser_csv.rb +114 -0
  230. data/lib/fluent/plugin/parser_json.rb +96 -0
  231. data/lib/fluent/plugin/parser_ltsv.rb +51 -0
  232. data/lib/fluent/plugin/parser_msgpack.rb +50 -0
  233. data/lib/fluent/plugin/parser_multiline.rb +152 -0
  234. data/lib/fluent/plugin/parser_nginx.rb +28 -0
  235. data/lib/fluent/plugin/parser_none.rb +36 -0
  236. data/lib/fluent/plugin/parser_regexp.rb +68 -0
  237. data/lib/fluent/plugin/parser_syslog.rb +496 -0
  238. data/lib/fluent/plugin/parser_tsv.rb +42 -0
  239. data/lib/fluent/plugin/sd_file.rb +156 -0
  240. data/lib/fluent/plugin/sd_srv.rb +135 -0
  241. data/lib/fluent/plugin/sd_static.rb +58 -0
  242. data/lib/fluent/plugin/service_discovery.rb +65 -0
  243. data/lib/fluent/plugin/socket_util.rb +22 -0
  244. data/lib/fluent/plugin/storage.rb +84 -0
  245. data/lib/fluent/plugin/storage_local.rb +162 -0
  246. data/lib/fluent/plugin/string_util.rb +22 -0
  247. data/lib/fluent/plugin.rb +206 -0
  248. data/lib/fluent/plugin_helper/cert_option.rb +191 -0
  249. data/lib/fluent/plugin_helper/child_process.rb +366 -0
  250. data/lib/fluent/plugin_helper/compat_parameters.rb +343 -0
  251. data/lib/fluent/plugin_helper/counter.rb +51 -0
  252. data/lib/fluent/plugin_helper/event_emitter.rb +100 -0
  253. data/lib/fluent/plugin_helper/event_loop.rb +170 -0
  254. data/lib/fluent/plugin_helper/extract.rb +104 -0
  255. data/lib/fluent/plugin_helper/formatter.rb +147 -0
  256. data/lib/fluent/plugin_helper/http_server/app.rb +79 -0
  257. data/lib/fluent/plugin_helper/http_server/compat/server.rb +92 -0
  258. data/lib/fluent/plugin_helper/http_server/compat/ssl_context_extractor.rb +52 -0
  259. data/lib/fluent/plugin_helper/http_server/compat/webrick_handler.rb +58 -0
  260. data/lib/fluent/plugin_helper/http_server/methods.rb +35 -0
  261. data/lib/fluent/plugin_helper/http_server/request.rb +42 -0
  262. data/lib/fluent/plugin_helper/http_server/router.rb +54 -0
  263. data/lib/fluent/plugin_helper/http_server/server.rb +93 -0
  264. data/lib/fluent/plugin_helper/http_server/ssl_context_builder.rb +41 -0
  265. data/lib/fluent/plugin_helper/http_server.rb +135 -0
  266. data/lib/fluent/plugin_helper/inject.rb +154 -0
  267. data/lib/fluent/plugin_helper/metrics.rb +129 -0
  268. data/lib/fluent/plugin_helper/parser.rb +147 -0
  269. data/lib/fluent/plugin_helper/record_accessor.rb +207 -0
  270. data/lib/fluent/plugin_helper/retry_state.rb +209 -0
  271. data/lib/fluent/plugin_helper/server.rb +801 -0
  272. data/lib/fluent/plugin_helper/service_discovery/manager.rb +146 -0
  273. data/lib/fluent/plugin_helper/service_discovery/round_robin_balancer.rb +43 -0
  274. data/lib/fluent/plugin_helper/service_discovery.rb +125 -0
  275. data/lib/fluent/plugin_helper/socket.rb +277 -0
  276. data/lib/fluent/plugin_helper/socket_option.rb +98 -0
  277. data/lib/fluent/plugin_helper/storage.rb +349 -0
  278. data/lib/fluent/plugin_helper/thread.rb +180 -0
  279. data/lib/fluent/plugin_helper/timer.rb +92 -0
  280. data/lib/fluent/plugin_helper.rb +75 -0
  281. data/lib/fluent/plugin_id.rb +93 -0
  282. data/lib/fluent/process.rb +22 -0
  283. data/lib/fluent/registry.rb +116 -0
  284. data/lib/fluent/root_agent.rb +372 -0
  285. data/lib/fluent/rpc.rb +94 -0
  286. data/lib/fluent/static_config_analysis.rb +194 -0
  287. data/lib/fluent/supervisor.rb +1054 -0
  288. data/lib/fluent/system_config.rb +187 -0
  289. data/lib/fluent/test/base.rb +78 -0
  290. data/lib/fluent/test/driver/base.rb +225 -0
  291. data/lib/fluent/test/driver/base_owned.rb +83 -0
  292. data/lib/fluent/test/driver/base_owner.rb +135 -0
  293. data/lib/fluent/test/driver/event_feeder.rb +98 -0
  294. data/lib/fluent/test/driver/filter.rb +57 -0
  295. data/lib/fluent/test/driver/formatter.rb +30 -0
  296. data/lib/fluent/test/driver/input.rb +31 -0
  297. data/lib/fluent/test/driver/multi_output.rb +53 -0
  298. data/lib/fluent/test/driver/output.rb +102 -0
  299. data/lib/fluent/test/driver/parser.rb +30 -0
  300. data/lib/fluent/test/driver/storage.rb +30 -0
  301. data/lib/fluent/test/driver/test_event_router.rb +45 -0
  302. data/lib/fluent/test/filter_test.rb +77 -0
  303. data/lib/fluent/test/formatter_test.rb +65 -0
  304. data/lib/fluent/test/helpers.rb +134 -0
  305. data/lib/fluent/test/input_test.rb +174 -0
  306. data/lib/fluent/test/log.rb +79 -0
  307. data/lib/fluent/test/output_test.rb +156 -0
  308. data/lib/fluent/test/parser_test.rb +70 -0
  309. data/lib/fluent/test/startup_shutdown.rb +46 -0
  310. data/lib/fluent/test.rb +58 -0
  311. data/lib/fluent/time.rb +512 -0
  312. data/lib/fluent/timezone.rb +171 -0
  313. data/lib/fluent/tls.rb +81 -0
  314. data/lib/fluent/unique_id.rb +39 -0
  315. data/lib/fluent/variable_store.rb +40 -0
  316. data/lib/fluent/version.rb +21 -0
  317. data/lib/fluent/winsvc.rb +103 -0
  318. data/templates/new_gem/Gemfile +3 -0
  319. data/templates/new_gem/README.md.erb +43 -0
  320. data/templates/new_gem/Rakefile +13 -0
  321. data/templates/new_gem/fluent-plugin.gemspec.erb +27 -0
  322. data/templates/new_gem/lib/fluent/plugin/filter.rb.erb +14 -0
  323. data/templates/new_gem/lib/fluent/plugin/formatter.rb.erb +14 -0
  324. data/templates/new_gem/lib/fluent/plugin/input.rb.erb +11 -0
  325. data/templates/new_gem/lib/fluent/plugin/output.rb.erb +11 -0
  326. data/templates/new_gem/lib/fluent/plugin/parser.rb.erb +15 -0
  327. data/templates/new_gem/lib/fluent/plugin/storage.rb.erb +40 -0
  328. data/templates/new_gem/test/helper.rb.erb +8 -0
  329. data/templates/new_gem/test/plugin/test_filter.rb.erb +18 -0
  330. data/templates/new_gem/test/plugin/test_formatter.rb.erb +18 -0
  331. data/templates/new_gem/test/plugin/test_input.rb.erb +18 -0
  332. data/templates/new_gem/test/plugin/test_output.rb.erb +18 -0
  333. data/templates/new_gem/test/plugin/test_parser.rb.erb +18 -0
  334. data/templates/new_gem/test/plugin/test_storage.rb.erb +18 -0
  335. data/templates/plugin_config_formatter/param.md-compact.erb +25 -0
  336. data/templates/plugin_config_formatter/param.md-table.erb +10 -0
  337. data/templates/plugin_config_formatter/param.md.erb +34 -0
  338. data/templates/plugin_config_formatter/section.md.erb +12 -0
  339. data/test/command/test_binlog_reader.rb +362 -0
  340. data/test/command/test_ca_generate.rb +70 -0
  341. data/test/command/test_cap_ctl.rb +100 -0
  342. data/test/command/test_cat.rb +128 -0
  343. data/test/command/test_ctl.rb +57 -0
  344. data/test/command/test_fluentd.rb +1106 -0
  345. data/test/command/test_plugin_config_formatter.rb +398 -0
  346. data/test/command/test_plugin_generator.rb +109 -0
  347. data/test/compat/test_calls_super.rb +166 -0
  348. data/test/compat/test_parser.rb +92 -0
  349. data/test/config/assertions.rb +42 -0
  350. data/test/config/test_config_parser.rb +551 -0
  351. data/test/config/test_configurable.rb +1784 -0
  352. data/test/config/test_configure_proxy.rb +604 -0
  353. data/test/config/test_dsl.rb +415 -0
  354. data/test/config/test_element.rb +518 -0
  355. data/test/config/test_literal_parser.rb +309 -0
  356. data/test/config/test_plugin_configuration.rb +56 -0
  357. data/test/config/test_section.rb +191 -0
  358. data/test/config/test_system_config.rb +199 -0
  359. data/test/config/test_types.rb +408 -0
  360. data/test/counter/test_client.rb +563 -0
  361. data/test/counter/test_error.rb +44 -0
  362. data/test/counter/test_mutex_hash.rb +179 -0
  363. data/test/counter/test_server.rb +589 -0
  364. data/test/counter/test_store.rb +258 -0
  365. data/test/counter/test_validator.rb +137 -0
  366. data/test/helper.rb +155 -0
  367. data/test/helpers/fuzzy_assert.rb +89 -0
  368. data/test/helpers/process_extenstion.rb +33 -0
  369. data/test/plugin/data/2010/01/20100102-030405.log +0 -0
  370. data/test/plugin/data/2010/01/20100102-030406.log +0 -0
  371. data/test/plugin/data/2010/01/20100102.log +0 -0
  372. data/test/plugin/data/log/bar +0 -0
  373. data/test/plugin/data/log/foo/bar.log +0 -0
  374. data/test/plugin/data/log/foo/bar2 +0 -0
  375. data/test/plugin/data/log/test.log +0 -0
  376. data/test/plugin/data/sd_file/config +11 -0
  377. data/test/plugin/data/sd_file/config.json +17 -0
  378. data/test/plugin/data/sd_file/config.yaml +11 -0
  379. data/test/plugin/data/sd_file/config.yml +11 -0
  380. data/test/plugin/data/sd_file/invalid_config.yml +7 -0
  381. data/test/plugin/in_tail/test_fifo.rb +121 -0
  382. data/test/plugin/in_tail/test_io_handler.rb +140 -0
  383. data/test/plugin/in_tail/test_position_file.rb +379 -0
  384. data/test/plugin/out_forward/test_ack_handler.rb +101 -0
  385. data/test/plugin/out_forward/test_connection_manager.rb +145 -0
  386. data/test/plugin/out_forward/test_handshake_protocol.rb +112 -0
  387. data/test/plugin/out_forward/test_load_balancer.rb +106 -0
  388. data/test/plugin/out_forward/test_socket_cache.rb +149 -0
  389. data/test/plugin/test_bare_output.rb +131 -0
  390. data/test/plugin/test_base.rb +115 -0
  391. data/test/plugin/test_buf_file.rb +1275 -0
  392. data/test/plugin/test_buf_file_single.rb +833 -0
  393. data/test/plugin/test_buf_memory.rb +42 -0
  394. data/test/plugin/test_buffer.rb +1383 -0
  395. data/test/plugin/test_buffer_chunk.rb +198 -0
  396. data/test/plugin/test_buffer_file_chunk.rb +871 -0
  397. data/test/plugin/test_buffer_file_single_chunk.rb +611 -0
  398. data/test/plugin/test_buffer_memory_chunk.rb +339 -0
  399. data/test/plugin/test_compressable.rb +87 -0
  400. data/test/plugin/test_file_util.rb +96 -0
  401. data/test/plugin/test_file_wrapper.rb +126 -0
  402. data/test/plugin/test_filter.rb +368 -0
  403. data/test/plugin/test_filter_grep.rb +697 -0
  404. data/test/plugin/test_filter_parser.rb +731 -0
  405. data/test/plugin/test_filter_record_transformer.rb +577 -0
  406. data/test/plugin/test_filter_stdout.rb +207 -0
  407. data/test/plugin/test_formatter_csv.rb +136 -0
  408. data/test/plugin/test_formatter_hash.rb +38 -0
  409. data/test/plugin/test_formatter_json.rb +61 -0
  410. data/test/plugin/test_formatter_ltsv.rb +70 -0
  411. data/test/plugin/test_formatter_msgpack.rb +28 -0
  412. data/test/plugin/test_formatter_out_file.rb +116 -0
  413. data/test/plugin/test_formatter_single_value.rb +44 -0
  414. data/test/plugin/test_formatter_tsv.rb +76 -0
  415. data/test/plugin/test_in_debug_agent.rb +49 -0
  416. data/test/plugin/test_in_exec.rb +261 -0
  417. data/test/plugin/test_in_forward.rb +1180 -0
  418. data/test/plugin/test_in_gc_stat.rb +62 -0
  419. data/test/plugin/test_in_http.rb +1080 -0
  420. data/test/plugin/test_in_monitor_agent.rb +923 -0
  421. data/test/plugin/test_in_object_space.rb +60 -0
  422. data/test/plugin/test_in_sample.rb +190 -0
  423. data/test/plugin/test_in_syslog.rb +505 -0
  424. data/test/plugin/test_in_tail.rb +2363 -0
  425. data/test/plugin/test_in_tcp.rb +243 -0
  426. data/test/plugin/test_in_udp.rb +268 -0
  427. data/test/plugin/test_in_unix.rb +181 -0
  428. data/test/plugin/test_input.rb +137 -0
  429. data/test/plugin/test_metadata.rb +89 -0
  430. data/test/plugin/test_metrics.rb +294 -0
  431. data/test/plugin/test_metrics_local.rb +96 -0
  432. data/test/plugin/test_multi_output.rb +204 -0
  433. data/test/plugin/test_out_copy.rb +308 -0
  434. data/test/plugin/test_out_exec.rb +312 -0
  435. data/test/plugin/test_out_exec_filter.rb +606 -0
  436. data/test/plugin/test_out_file.rb +1037 -0
  437. data/test/plugin/test_out_forward.rb +1348 -0
  438. data/test/plugin/test_out_http.rb +428 -0
  439. data/test/plugin/test_out_null.rb +105 -0
  440. data/test/plugin/test_out_relabel.rb +28 -0
  441. data/test/plugin/test_out_roundrobin.rb +146 -0
  442. data/test/plugin/test_out_secondary_file.rb +458 -0
  443. data/test/plugin/test_out_stdout.rb +205 -0
  444. data/test/plugin/test_out_stream.rb +103 -0
  445. data/test/plugin/test_output.rb +1065 -0
  446. data/test/plugin/test_output_as_buffered.rb +2024 -0
  447. data/test/plugin/test_output_as_buffered_backup.rb +363 -0
  448. data/test/plugin/test_output_as_buffered_compress.rb +165 -0
  449. data/test/plugin/test_output_as_buffered_overflow.rb +250 -0
  450. data/test/plugin/test_output_as_buffered_retries.rb +919 -0
  451. data/test/plugin/test_output_as_buffered_secondary.rb +882 -0
  452. data/test/plugin/test_output_as_standard.rb +374 -0
  453. data/test/plugin/test_owned_by.rb +35 -0
  454. data/test/plugin/test_parser.rb +399 -0
  455. data/test/plugin/test_parser_apache.rb +42 -0
  456. data/test/plugin/test_parser_apache2.rb +47 -0
  457. data/test/plugin/test_parser_apache_error.rb +45 -0
  458. data/test/plugin/test_parser_csv.rb +200 -0
  459. data/test/plugin/test_parser_json.rb +138 -0
  460. data/test/plugin/test_parser_labeled_tsv.rb +160 -0
  461. data/test/plugin/test_parser_multiline.rb +111 -0
  462. data/test/plugin/test_parser_nginx.rb +88 -0
  463. data/test/plugin/test_parser_none.rb +52 -0
  464. data/test/plugin/test_parser_regexp.rb +289 -0
  465. data/test/plugin/test_parser_syslog.rb +650 -0
  466. data/test/plugin/test_parser_tsv.rb +122 -0
  467. data/test/plugin/test_sd_file.rb +228 -0
  468. data/test/plugin/test_sd_srv.rb +230 -0
  469. data/test/plugin/test_storage.rb +167 -0
  470. data/test/plugin/test_storage_local.rb +335 -0
  471. data/test/plugin/test_string_util.rb +26 -0
  472. data/test/plugin_helper/data/cert/cert-key.pem +27 -0
  473. data/test/plugin_helper/data/cert/cert-with-CRLF.pem +19 -0
  474. data/test/plugin_helper/data/cert/cert-with-no-newline.pem +19 -0
  475. data/test/plugin_helper/data/cert/cert.pem +19 -0
  476. data/test/plugin_helper/data/cert/cert_chains/ca-cert-key.pem +27 -0
  477. data/test/plugin_helper/data/cert/cert_chains/ca-cert.pem +20 -0
  478. data/test/plugin_helper/data/cert/cert_chains/cert-key.pem +27 -0
  479. data/test/plugin_helper/data/cert/cert_chains/cert.pem +40 -0
  480. data/test/plugin_helper/data/cert/empty.pem +0 -0
  481. data/test/plugin_helper/data/cert/generate_cert.rb +125 -0
  482. data/test/plugin_helper/data/cert/with_ca/ca-cert-key-pass.pem +30 -0
  483. data/test/plugin_helper/data/cert/with_ca/ca-cert-key.pem +27 -0
  484. data/test/plugin_helper/data/cert/with_ca/ca-cert-pass.pem +20 -0
  485. data/test/plugin_helper/data/cert/with_ca/ca-cert.pem +20 -0
  486. data/test/plugin_helper/data/cert/with_ca/cert-key-pass.pem +30 -0
  487. data/test/plugin_helper/data/cert/with_ca/cert-key.pem +27 -0
  488. data/test/plugin_helper/data/cert/with_ca/cert-pass.pem +21 -0
  489. data/test/plugin_helper/data/cert/with_ca/cert.pem +21 -0
  490. data/test/plugin_helper/data/cert/without_ca/cert-key-pass.pem +30 -0
  491. data/test/plugin_helper/data/cert/without_ca/cert-key.pem +27 -0
  492. data/test/plugin_helper/data/cert/without_ca/cert-pass.pem +20 -0
  493. data/test/plugin_helper/data/cert/without_ca/cert.pem +20 -0
  494. data/test/plugin_helper/http_server/test_app.rb +65 -0
  495. data/test/plugin_helper/http_server/test_route.rb +32 -0
  496. data/test/plugin_helper/service_discovery/test_manager.rb +93 -0
  497. data/test/plugin_helper/service_discovery/test_round_robin_balancer.rb +21 -0
  498. data/test/plugin_helper/test_cert_option.rb +25 -0
  499. data/test/plugin_helper/test_child_process.rb +840 -0
  500. data/test/plugin_helper/test_compat_parameters.rb +358 -0
  501. data/test/plugin_helper/test_event_emitter.rb +80 -0
  502. data/test/plugin_helper/test_event_loop.rb +52 -0
  503. data/test/plugin_helper/test_extract.rb +194 -0
  504. data/test/plugin_helper/test_formatter.rb +255 -0
  505. data/test/plugin_helper/test_http_server_helper.rb +372 -0
  506. data/test/plugin_helper/test_inject.rb +561 -0
  507. data/test/plugin_helper/test_metrics.rb +137 -0
  508. data/test/plugin_helper/test_parser.rb +264 -0
  509. data/test/plugin_helper/test_record_accessor.rb +238 -0
  510. data/test/plugin_helper/test_retry_state.rb +442 -0
  511. data/test/plugin_helper/test_server.rb +1823 -0
  512. data/test/plugin_helper/test_service_discovery.rb +165 -0
  513. data/test/plugin_helper/test_socket.rb +146 -0
  514. data/test/plugin_helper/test_storage.rb +542 -0
  515. data/test/plugin_helper/test_thread.rb +164 -0
  516. data/test/plugin_helper/test_timer.rb +130 -0
  517. data/test/scripts/exec_script.rb +32 -0
  518. data/test/scripts/fluent/plugin/formatter1/formatter_test1.rb +7 -0
  519. data/test/scripts/fluent/plugin/formatter2/formatter_test2.rb +7 -0
  520. data/test/scripts/fluent/plugin/formatter_known.rb +8 -0
  521. data/test/scripts/fluent/plugin/out_test.rb +81 -0
  522. data/test/scripts/fluent/plugin/out_test2.rb +80 -0
  523. data/test/scripts/fluent/plugin/parser_known.rb +4 -0
  524. data/test/test_capability.rb +74 -0
  525. data/test/test_clock.rb +164 -0
  526. data/test/test_config.rb +202 -0
  527. data/test/test_configdsl.rb +148 -0
  528. data/test/test_daemonizer.rb +91 -0
  529. data/test/test_engine.rb +203 -0
  530. data/test/test_event.rb +531 -0
  531. data/test/test_event_router.rb +331 -0
  532. data/test/test_event_time.rb +199 -0
  533. data/test/test_filter.rb +121 -0
  534. data/test/test_fluent_log_event_router.rb +99 -0
  535. data/test/test_formatter.rb +366 -0
  536. data/test/test_input.rb +31 -0
  537. data/test/test_log.rb +994 -0
  538. data/test/test_logger_initializer.rb +46 -0
  539. data/test/test_match.rb +148 -0
  540. data/test/test_mixin.rb +351 -0
  541. data/test/test_msgpack_factory.rb +18 -0
  542. data/test/test_oj_options.rb +55 -0
  543. data/test/test_output.rb +278 -0
  544. data/test/test_plugin.rb +251 -0
  545. data/test/test_plugin_classes.rb +370 -0
  546. data/test/test_plugin_helper.rb +81 -0
  547. data/test/test_plugin_id.rb +119 -0
  548. data/test/test_process.rb +14 -0
  549. data/test/test_root_agent.rb +951 -0
  550. data/test/test_static_config_analysis.rb +177 -0
  551. data/test/test_supervisor.rb +601 -0
  552. data/test/test_test_drivers.rb +136 -0
  553. data/test/test_time_formatter.rb +301 -0
  554. data/test/test_time_parser.rb +362 -0
  555. data/test/test_tls.rb +65 -0
  556. data/test/test_unique_id.rb +47 -0
  557. data/test/test_variable_store.rb +65 -0
  558. metadata +1261 -0
@@ -0,0 +1,1784 @@
1
+ require_relative '../helper'
2
+ require 'fluent/configurable'
3
+ require 'fluent/config/element'
4
+ require 'fluent/config/section'
5
+
6
+ module ConfigurableSpec
7
+ class Base1
8
+ include Fluent::Configurable
9
+
10
+ config_param :node, :string, default: "node"
11
+ config_param :flag1, :bool, default: false
12
+ config_param :flag2, :bool, default: true
13
+
14
+ config_param :name1, :string
15
+ config_param :name2, :string
16
+ config_param :name3, :string, default: "base1"
17
+ config_param :name4, :string, default: "base1"
18
+
19
+ config_param :opt1, :enum, list: [:foo, :bar, :baz]
20
+ config_param :opt2, :enum, list: [:foo, :bar, :baz], default: :foo
21
+
22
+ def get_all
23
+ [@node, @flag1, @flag2, @name1, @name2, @name3, @name4]
24
+ end
25
+ end
26
+
27
+ class Base1Safe < Base1
28
+ config_set_default :name1, "basex1"
29
+ config_set_default :name2, "basex2"
30
+ config_set_default :opt1, :baz
31
+ end
32
+
33
+ class Base1Nil < Base1
34
+ config_set_default :name1, nil
35
+ config_set_default :name2, nil
36
+ config_set_default :opt1, nil
37
+ config_param :name5, :string, default: nil
38
+ end
39
+
40
+ class Base2 < Base1
41
+ config_set_default :name2, "base2"
42
+ config_set_default :name4, "base2"
43
+ config_set_default :opt1, :bar
44
+ config_param :name5, :string
45
+ config_param :name6, :string, default: "base2"
46
+ config_param :opt3, :enum, list: [:a, :b]
47
+
48
+ def get_all
49
+ ary = super
50
+ ary + [@name5, @name6]
51
+ end
52
+ end
53
+
54
+ class Base3 < Base2
55
+ config_set_default :opt3, :a
56
+ config_section :node do
57
+ config_param :name, :string, default: "node"
58
+ config_param :type, :string
59
+ end
60
+ config_section :branch, required: true, multi: true do
61
+ config_argument :name, :string
62
+ config_param :size, :integer, default: 10
63
+ config_section :leaf, required: false, multi: true do
64
+ config_param :weight, :integer
65
+ config_section :worm, param_name: 'worms', multi: true do
66
+ config_param :type, :string, default: 'ladybird'
67
+ end
68
+ end
69
+ end
70
+
71
+ def get_all
72
+ ary = super
73
+ ary + [@branch]
74
+ end
75
+ end
76
+
77
+ class Base4 < Base2
78
+ config_set_default :opt3, :a
79
+ config_section :node, param_name: :nodes do
80
+ config_argument :num, :integer
81
+ config_param :name, :string, default: "node"
82
+ config_param :type, :string, default: "b4"
83
+ end
84
+ config_section :description1, required: false, multi: false do
85
+ config_argument :note, :string, default: "desc1"
86
+ config_param :text, :string
87
+ end
88
+ config_section :description2, required: true, multi: false do
89
+ config_argument :note, :string, default: "desc2"
90
+ config_param :text, :string
91
+ end
92
+ config_section :description3, required: true, multi: true do
93
+ config_argument :note, default: "desc3" do |val|
94
+ "desc3: #{val}"
95
+ end
96
+ config_param :text, :string
97
+ end
98
+
99
+ def get_all
100
+ ary = super
101
+ ary + [@nodes, @description1, @description2, @description3]
102
+ end
103
+ end
104
+
105
+ class Base4Safe < Base4
106
+ # config_section :node, param_name: :nodes do
107
+ # config_argument :num, :integer
108
+ # config_param :name, :string, default: "node"
109
+ # config_param :type, :string, default: "b4"
110
+ # end
111
+ # config_section :description1, required: false, multi: false do
112
+ # config_argument :note, :string, default: "desc1"
113
+ # config_param :text, :string
114
+ # end
115
+ # config_section :description2, required: true, multi: false do
116
+ # config_argument :note, :string, default: "desc2"
117
+ # config_param :text, :string
118
+ # end
119
+ # config_section :description3, required: true, multi: true do
120
+ # config_argument :note, default: "desc3" do |val|
121
+ # "desc3: #{val}"
122
+ # end
123
+ # config_param :text, :string
124
+ # end
125
+ config_section :node do
126
+ config_set_default :num, 0
127
+ end
128
+ config_section :description1 do
129
+ config_set_default :text, "teeeext"
130
+ end
131
+ config_section :description2 do
132
+ config_set_default :text, nil
133
+ end
134
+ config_section :description3 do
135
+ config_set_default :text, "yay"
136
+ end
137
+ end
138
+
139
+ class Init0
140
+ include Fluent::Configurable
141
+ config_section :sec1, init: true, multi: false do
142
+ config_param :name, :string, default: 'sec1'
143
+ end
144
+ config_section :sec2, init: true, multi: true do
145
+ config_param :name, :string, default: 'sec1'
146
+ end
147
+ end
148
+
149
+ class Example0
150
+ include Fluent::Configurable
151
+
152
+ config_param :stringvalue, :string
153
+ config_param :boolvalue, :bool
154
+ config_param :integervalue, :integer
155
+ config_param :sizevalue, :size
156
+ config_param :timevalue, :time
157
+ config_param :floatvalue, :float
158
+ config_param :hashvalue, :hash
159
+ config_param :arrayvalue, :array
160
+ end
161
+
162
+ class ExampleWithAlias
163
+ include Fluent::Configurable
164
+
165
+ config_param :name, :string, alias: :fullname
166
+ config_param :bool, :bool, alias: :flag
167
+ config_section :detail, required: false, multi: false, alias: "information" do
168
+ config_param :address, :string, default: "x"
169
+ end
170
+
171
+ def get_all
172
+ [@name, @detail]
173
+ end
174
+ end
175
+
176
+ class ExampleWithSecret
177
+ include Fluent::Configurable
178
+
179
+ config_param :normal_param, :string
180
+ config_param :secret_param, :string, secret: true
181
+
182
+ config_section :section do
183
+ config_param :normal_param2, :string
184
+ config_param :secret_param2, :string, secret: true
185
+ end
186
+ end
187
+
188
+ class ExampleWithDefaultHashAndArray
189
+ include Fluent::Configurable
190
+ config_param :obj1, :hash, default: {}
191
+ config_param :obj2, :array, default: []
192
+ end
193
+
194
+ class ExampleWithSkipAccessor
195
+ include Fluent::Configurable
196
+ config_param :name, :string, default: 'example7', skip_accessor: true
197
+ end
198
+
199
+ class ExampleWithCustomSection
200
+ include Fluent::Configurable
201
+ config_param :name_param, :string
202
+ config_section :normal_section do
203
+ config_param :normal_section_param, :string
204
+ end
205
+
206
+ class CustomSection
207
+ include Fluent::Configurable
208
+ config_param :custom_section_param, :string
209
+ end
210
+
211
+ class AnotherElement
212
+ include Fluent::Configurable
213
+ end
214
+
215
+ def configure(conf)
216
+ super
217
+ conf.elements.each do |e|
218
+ next if e.name != 'custom_section'
219
+ CustomSection.new.configure(e)
220
+ end
221
+ end
222
+ end
223
+
224
+ class ExampleWithIntFloat
225
+ include Fluent::Configurable
226
+ config_param :int1, :integer
227
+ config_param :float1, :float
228
+ end
229
+
230
+ module Overwrite
231
+ class Base
232
+ include Fluent::Configurable
233
+
234
+ config_param :name, :string, alias: :fullname
235
+ config_param :bool, :bool, alias: :flag
236
+ config_section :detail, required: false, multi: false, alias: "information" do
237
+ config_param :address, :string, default: "x"
238
+ end
239
+ end
240
+
241
+ class Required < Base
242
+ config_section :detail, required: true do
243
+ config_param :address, :string, default: "x"
244
+ end
245
+ end
246
+
247
+ class Multi < Base
248
+ config_section :detail, multi: true do
249
+ config_param :address, :string, default: "x"
250
+ end
251
+ end
252
+
253
+ class Alias < Base
254
+ config_section :detail, alias: "information2" do
255
+ config_param :address, :string, default: "x"
256
+ end
257
+ end
258
+
259
+ class DefaultOptions < Base
260
+ config_section :detail do
261
+ config_param :address, :string, default: "x"
262
+ end
263
+ end
264
+
265
+ class DetailAddressDefault < Base
266
+ config_section :detail do
267
+ config_param :address, :string, default: "y"
268
+ end
269
+ end
270
+
271
+ class AddParam < Base
272
+ config_section :detail do
273
+ config_param :phone_no, :string
274
+ end
275
+ end
276
+
277
+ class AddParamOverwriteAddress < Base
278
+ config_section :detail do
279
+ config_param :address, :string, default: "y"
280
+ config_param :phone_no, :string
281
+ end
282
+ end
283
+ end
284
+
285
+ module Final
286
+ # Show what is allowed in finalized sections
287
+ # InheritsFinalized < Finalized < Base
288
+ class Base
289
+ include Fluent::Configurable
290
+ config_section :appendix, multi: false, final: false do
291
+ config_param :code, :string
292
+ config_param :name, :string
293
+ config_param :address, :string, default: ""
294
+ end
295
+ end
296
+
297
+ class Finalized < Base
298
+ # to non-finalized section
299
+ # subclass can change type (code)
300
+ # add default value (name)
301
+ # change default value (address)
302
+ # add field (age)
303
+ config_section :appendix, final: true do
304
+ config_param :code, :integer
305
+ config_set_default :name, "y"
306
+ config_set_default :address, "-"
307
+ config_param :age, :integer, default: 10
308
+ end
309
+ end
310
+
311
+ class InheritsFinalized < Finalized
312
+ # to finalized section
313
+ # subclass can add default value (code)
314
+ # change default value (age)
315
+ # add field (phone_no)
316
+ config_section :appendix do
317
+ config_set_default :code, 2
318
+ config_set_default :age, 0
319
+ config_param :phone_no, :string
320
+ end
321
+ end
322
+
323
+ # Show what is allowed/prohibited for finalized sections
324
+ class FinalizedBase
325
+ include Fluent::Configurable
326
+ config_section :appendix, param_name: :apd, init: false, required: true, multi: false, alias: "options", final: true do
327
+ config_param :name, :string
328
+ end
329
+ end
330
+
331
+ class FinalizedBase2
332
+ include Fluent::Configurable
333
+ config_section :appendix, param_name: :apd, init: false, required: false, multi: false, alias: "options", final: true do
334
+ config_param :name, :string
335
+ end
336
+ end
337
+
338
+ # subclass can change init with adding default values
339
+ class OverwriteInit < FinalizedBase2
340
+ config_section :appendix, init: true do
341
+ config_set_default :name, "moris"
342
+ config_param :code, :integer, default: 0
343
+ end
344
+ end
345
+
346
+ # subclass cannot change type (name)
347
+ class Subclass < FinalizedBase
348
+ config_section :appendix do
349
+ config_param :name, :integer
350
+ end
351
+ end
352
+
353
+ # subclass cannot change param_name
354
+ class OverwriteParamName < FinalizedBase
355
+ config_section :appendix, param_name: :adx do
356
+ end
357
+ end
358
+
359
+ # subclass cannot change final (section)
360
+ class OverwriteFinal < FinalizedBase
361
+ config_section :appendix, final: false do
362
+ config_param :name, :integer
363
+ end
364
+ end
365
+
366
+ # subclass cannot change required
367
+ class OverwriteRequired < FinalizedBase
368
+ config_section :appendix, required: false do
369
+ end
370
+ end
371
+
372
+ # subclass cannot change multi
373
+ class OverwriteMulti < FinalizedBase
374
+ config_section :appendix, multi: true do
375
+ end
376
+ end
377
+
378
+ # subclass cannot change alias
379
+ class OverwriteAlias < FinalizedBase
380
+ config_section :appendix, alias: "options2" do
381
+ end
382
+ end
383
+ end
384
+
385
+ module OverwriteDefaults
386
+ class Owner
387
+ include Fluent::Configurable
388
+ config_set_default :key1, "V1"
389
+ config_section :buffer do
390
+ config_set_default :size_of_something, 1024
391
+ end
392
+ end
393
+
394
+ class SubOwner < Owner
395
+ config_section :buffer do
396
+ config_set_default :size_of_something, 2048
397
+ end
398
+ end
399
+
400
+ class NilOwner < Owner
401
+ config_section :buffer do
402
+ config_set_default :size_of_something, nil
403
+ end
404
+ end
405
+
406
+ class FlatChild
407
+ include Fluent::Configurable
408
+ attr_accessor :owner
409
+ config_param :key1, :string, default: "v1"
410
+ end
411
+
412
+ class BufferChild
413
+ include Fluent::Configurable
414
+ attr_accessor :owner
415
+ configured_in :buffer
416
+ config_param :size_of_something, :size, default: 128
417
+ end
418
+
419
+ class BufferBase
420
+ include Fluent::Configurable
421
+ end
422
+
423
+ class BufferSubclass < BufferBase
424
+ attr_accessor :owner
425
+ configured_in :buffer
426
+ config_param :size_of_something, :size, default: 512
427
+ end
428
+
429
+ class BufferSubSubclass < BufferSubclass
430
+ end
431
+ end
432
+ class UnRecommended
433
+ include Fluent::Configurable
434
+ attr_accessor :log
435
+ config_param :key1, :string, default: 'deprecated', deprecated: "key1 will be removed."
436
+ config_param :key2, :string, default: 'obsoleted', obsoleted: "key2 has been removed."
437
+ end
438
+ end
439
+
440
+ module Fluent::Config
441
+ class TestConfigurable < ::Test::Unit::TestCase
442
+ sub_test_case 'class defined without config_section' do
443
+ sub_test_case '#initialize' do
444
+ test 'create instance methods and default values by config_param and config_set_default' do
445
+ obj1 = ConfigurableSpec::Base1.new
446
+ assert_equal("node", obj1.node)
447
+ assert_false(obj1.flag1)
448
+ assert_true(obj1.flag2)
449
+ assert_nil(obj1.name1)
450
+ assert_nil(obj1.name2)
451
+ assert_equal("base1", obj1.name3)
452
+ assert_equal("base1", obj1.name4)
453
+ assert_nil(obj1.opt1)
454
+ assert_equal(:foo, obj1.opt2)
455
+ end
456
+
457
+ test 'create instance methods and default values overwritten by sub class definition' do
458
+ obj2 = ConfigurableSpec::Base2.new
459
+ assert_equal("node", obj2.node)
460
+ assert_false(obj2.flag1)
461
+ assert_true(obj2.flag2)
462
+ assert_nil(obj2.name1)
463
+ assert_equal("base2", obj2.name2)
464
+ assert_equal("base1", obj2.name3)
465
+ assert_equal("base2", obj2.name4)
466
+ assert_nil(obj2.name5)
467
+ assert_equal("base2", obj2.name6)
468
+ assert_equal(:bar, obj2.opt1)
469
+ assert_equal(:foo, obj2.opt2)
470
+ end
471
+ end
472
+
473
+ sub_test_case '#configured_section_create' do
474
+ test 'raises configuration error if required param exists but no configuration element is specified' do
475
+ obj = ConfigurableSpec::Base1.new
476
+ assert_raise(Fluent::ConfigError.new("'name1' parameter is required")) do
477
+ obj.configured_section_create(nil)
478
+ end
479
+ end
480
+
481
+ test 'creates root section with default values if name and config are specified with nil' do
482
+ obj = ConfigurableSpec::Base1Safe.new
483
+ root = obj.configured_section_create(nil)
484
+
485
+ assert_equal "node", root.node
486
+ assert_false root.flag1
487
+ assert_true root.flag2
488
+ assert_equal "basex1", root.name1
489
+ assert_equal "basex2", root.name2
490
+ assert_equal "base1", root.name3
491
+ assert_equal "base1", root.name4
492
+ assert_equal :baz, root.opt1
493
+ assert_equal :foo, root.opt2
494
+ end
495
+
496
+ test 'creates root section with default values if name is nil and config is empty element' do
497
+ obj = ConfigurableSpec::Base1Safe.new
498
+ root = obj.configured_section_create(nil, config_element())
499
+
500
+ assert_equal "node", root.node
501
+ assert_false root.flag1
502
+ assert_true root.flag2
503
+ assert_equal "basex1", root.name1
504
+ assert_equal "basex2", root.name2
505
+ assert_equal "base1", root.name3
506
+ assert_equal "base1", root.name4
507
+ assert_equal :baz, root.opt1
508
+ assert_equal :foo, root.opt2
509
+ end
510
+
511
+ test 'creates root section with specified value if name is nil and configuration element is specified' do
512
+ obj = ConfigurableSpec::Base1Safe.new
513
+ root = obj.configured_section_create(nil, config_element('match', '', {'node' => "nodename", 'flag1' => 'true', 'name1' => 'fixed1', 'opt1' => 'foo'}))
514
+
515
+ assert_equal "nodename", root.node
516
+ assert_equal "fixed1", root.name1
517
+ assert_true root.flag1
518
+ assert_equal :foo, root.opt1
519
+
520
+ assert_true root.flag2
521
+ assert_equal "basex2", root.name2
522
+ assert_equal "base1", root.name3
523
+ assert_equal "base1", root.name4
524
+ assert_equal :foo, root.opt2
525
+ end
526
+ end
527
+
528
+ sub_test_case '#configure' do
529
+ test 'returns configurable object itself' do
530
+ b2 = ConfigurableSpec::Base2.new
531
+ assert_instance_of(ConfigurableSpec::Base2, b2.configure(config_element("", "", {"name1" => "t1", "name5" => "t5", "opt3" => "a"})))
532
+ end
533
+
534
+ test 'can accept frozen string' do
535
+ b2 = ConfigurableSpec::Base2.new
536
+ assert_instance_of(ConfigurableSpec::Base2, b2.configure(config_element("", "", {"name1" => "t1".freeze, "name5" => "t5", "opt3" => "a"})))
537
+ end
538
+
539
+ test 'raise errors without any specifications for param without defaults' do
540
+ b2 = ConfigurableSpec::Base2.new
541
+ assert_raise(Fluent::ConfigError) { b2.configure(config_element("", "", {})) }
542
+ assert_raise(Fluent::ConfigError) { b2.configure(config_element("", "", {"name1" => "t1"})) }
543
+ assert_raise(Fluent::ConfigError) { b2.configure(config_element("", "", {"name5" => "t5"})) }
544
+ assert_raise(Fluent::ConfigError) { b2.configure(config_element("", "", {"name1" => "t1", "name5" => "t5"})) }
545
+ assert_nothing_raised { b2.configure(config_element("", "", {"name1" => "t1", "name5" => "t5", "opt3" => "a"})) }
546
+
547
+ assert_equal(["node", false, true, "t1", "base2", "base1", "base2", "t5", "base2"], b2.get_all)
548
+ assert_equal(:a, b2.opt3)
549
+ end
550
+
551
+ test 'can configure bool values' do
552
+ b2a = ConfigurableSpec::Base2.new
553
+ assert_nothing_raised { b2a.configure(config_element("", "", {"flag1" => "true", "flag2" => "yes", "name1" => "t1", "name5" => "t5", "opt3" => "a"})) }
554
+ assert_true(b2a.flag1)
555
+ assert_true(b2a.flag2)
556
+
557
+ b2b = ConfigurableSpec::Base2.new
558
+ assert_nothing_raised { b2b.configure(config_element("", "", {"flag1" => false, "flag2" => "no", "name1" => "t1", "name5" => "t5", "opt3" => "a"})) }
559
+ assert_false(b2b.flag1)
560
+ assert_false(b2b.flag2)
561
+ end
562
+
563
+ test 'overwrites values of defaults' do
564
+ b2 = ConfigurableSpec::Base2.new
565
+ b2.configure(config_element("", "", {"name1" => "t1", "name2" => "t2", "name3" => "t3", "name4" => "t4", "name5" => "t5", "opt1" => "foo", "opt3" => "b"}))
566
+ assert_equal("t1", b2.name1)
567
+ assert_equal("t2", b2.name2)
568
+ assert_equal("t3", b2.name3)
569
+ assert_equal("t4", b2.name4)
570
+ assert_equal("t5", b2.name5)
571
+ assert_equal("base2", b2.name6)
572
+ assert_equal(:foo, b2.opt1)
573
+ assert_equal(:b, b2.opt3)
574
+
575
+ assert_equal(["node", false, true, "t1", "t2", "t3", "t4", "t5", "base2"], b2.get_all)
576
+ end
577
+
578
+ test 'enum type rejects values which does not exist in list' do
579
+ default = config_element("", "", {"name1" => "t1", "name2" => "t2", "name3" => "t3", "name4" => "t4", "name5" => "t5", "opt1" => "foo", "opt3" => "b"})
580
+
581
+ b2 = ConfigurableSpec::Base2.new
582
+ assert_nothing_raised { b2.configure(default) }
583
+ assert_raise(Fluent::ConfigError) { b2.configure(default.merge({"opt1" => "bazz"})) }
584
+ assert_raise(Fluent::ConfigError) { b2.configure(default.merge({"opt2" => "fooooooo"})) }
585
+ assert_raise(Fluent::ConfigError) { b2.configure(default.merge({"opt3" => "c"})) }
586
+ end
587
+
588
+ sub_test_case 'default values should be duplicated before touched in plugin code' do
589
+ test 'default object should be dupped for cases configured twice' do
590
+ x6a = ConfigurableSpec::ExampleWithDefaultHashAndArray.new
591
+ assert_nothing_raised { x6a.configure(config_element("")) }
592
+ assert_equal({}, x6a.obj1)
593
+ assert_equal([], x6a.obj2)
594
+
595
+ x6b = ConfigurableSpec::ExampleWithDefaultHashAndArray.new
596
+ assert_nothing_raised { x6b.configure(config_element("")) }
597
+ assert_equal({}, x6b.obj1)
598
+ assert_equal([], x6b.obj2)
599
+
600
+ assert { x6a.obj1.object_id != x6b.obj1.object_id }
601
+ assert { x6a.obj2.object_id != x6b.obj2.object_id }
602
+
603
+ x6c = ConfigurableSpec::ExampleWithDefaultHashAndArray.new
604
+ assert_nothing_raised { x6c.configure(config_element("")) }
605
+ assert_equal({}, x6c.obj1)
606
+ assert_equal([], x6c.obj2)
607
+
608
+ x6c.obj1['k'] = 'v'
609
+ x6c.obj2 << 'v'
610
+
611
+ assert_equal({'k' => 'v'}, x6c.obj1)
612
+ assert_equal(['v'], x6c.obj2)
613
+
614
+ assert_equal({}, x6a.obj1)
615
+ assert_equal([], x6a.obj2)
616
+ end
617
+ end
618
+
619
+ test 'strict value type' do
620
+ default = config_element("", "", {"int1" => "1", "float1" => ""})
621
+
622
+ c = ConfigurableSpec::ExampleWithIntFloat.new
623
+ assert_nothing_raised { c.configure(default) }
624
+ assert_raise(Fluent::ConfigError) { c.configure(default, true) }
625
+ end
626
+ end
627
+
628
+ test 'set nil for a parameter which has no default value' do
629
+ obj = ConfigurableSpec::Base2.new
630
+ conf = config_element("", "", {"name1" => nil, "name5" => "t5", "opt3" => "a"})
631
+ assert_raise(Fluent::ConfigError.new("'name1' parameter is required but nil is specified")) do
632
+ obj.configure(conf)
633
+ end
634
+ end
635
+
636
+ test 'set nil for a parameter which has non-nil default value' do
637
+ obj = ConfigurableSpec::Base2.new
638
+ conf = config_element("", "", {"name1" => "t1", "name3" => nil, "name5" => "t5", "opt3" => "a"})
639
+ assert_raise(Fluent::ConfigError.new("'name3' parameter is required but nil is specified")) do
640
+ obj.configure(conf)
641
+ end
642
+ end
643
+
644
+ test 'set nil for a parameter whose default value is nil' do
645
+ obj = ConfigurableSpec::Base1Nil.new
646
+ conf = config_element("", "", {"name5" => nil})
647
+ obj.configure(conf)
648
+ assert_nil obj.name5
649
+ end
650
+
651
+ test 'set nil for parameters whose default values are overwritten by nil' do
652
+ obj = ConfigurableSpec::Base1Nil.new
653
+ conf = config_element("", "", {"name1" => nil, "name2" => nil, "opt1" => nil})
654
+ obj.configure(conf)
655
+ assert_nil obj.name1
656
+ assert_nil obj.name2
657
+ assert_nil obj.opt1
658
+ end
659
+
660
+ test 'set :default' do
661
+ obj = ConfigurableSpec::Base2.new
662
+ conf = config_element("", "", {"name1" => "t1", "name3" => :default, "name5" => "t5", "opt3" => "a"})
663
+ obj.configure(conf)
664
+ assert_equal "base1", obj.name3
665
+ end
666
+
667
+ test 'set :default for a parameter which has no default value' do
668
+ obj = ConfigurableSpec::Base2.new
669
+ conf = config_element("", "", {"name1" => :default, "name5" => "t5", "opt3" => "a"})
670
+ assert_raise(Fluent::ConfigError.new("'name1' doesn't have default value")) do
671
+ obj.configure(conf)
672
+ end
673
+ end
674
+
675
+ test 'set :default for a parameter which has an overwritten default value' do
676
+ obj = ConfigurableSpec::Base2.new
677
+ conf = config_element("", "", {"name1" => "t1", "name3" => "t3", "name4" => :default, "name5" => "t5", "opt3" => "a"})
678
+ obj.configure(conf)
679
+ assert_equal "base2", obj.name4
680
+ end
681
+ end
682
+
683
+ sub_test_case 'class defined with config_section' do
684
+ sub_test_case '#initialize' do
685
+ test 'create instance methods and default values as nil for params from config_section specified as non-multi' do
686
+ b4 = ConfigurableSpec::Base4.new
687
+ assert_nil(b4.description1)
688
+ assert_nil(b4.description2)
689
+ end
690
+
691
+ test 'create instance methods and default values as [] for params from config_section specified as multi' do
692
+ b4 = ConfigurableSpec::Base4.new
693
+ assert_equal([], b4.description3)
694
+ end
695
+
696
+ test 'overwrite base class definition by config_section of sub class definition' do
697
+ b3 = ConfigurableSpec::Base3.new
698
+ assert_equal([], b3.node)
699
+ end
700
+
701
+ test 'create instance methods and default values by param_name' do
702
+ b4 = ConfigurableSpec::Base4.new
703
+ assert_equal([], b4.nodes)
704
+ assert_equal("node", b4.node)
705
+ end
706
+
707
+ test 'create non-required and multi without any specifications' do
708
+ b3 = ConfigurableSpec::Base3.new
709
+ assert_false(b3.class.merged_configure_proxy.sections[:node].required?)
710
+ assert_true(b3.class.merged_configure_proxy.sections[:node].multi?)
711
+ end
712
+ end
713
+
714
+ sub_test_case '#configured_section_create' do
715
+ test 'raises configuration error if required param exists but no configuration element is specified' do
716
+ obj = ConfigurableSpec::Base4.new
717
+ assert_raise(Fluent::ConfigError.new("'<node ARG>' section requires argument")) do
718
+ obj.configured_section_create(:node)
719
+ end
720
+ assert_raise(Fluent::ConfigError.new("'text' parameter is required")) do
721
+ obj.configured_section_create(:description1)
722
+ end
723
+ end
724
+
725
+ test 'creates any defined section with default values if name is nil and config is not specified' do
726
+ obj = ConfigurableSpec::Base4Safe.new
727
+ node = obj.configured_section_create(:node)
728
+ assert_equal 0, node.num
729
+ assert_equal "node", node.name
730
+ assert_equal "b4", node.type
731
+
732
+ desc1 = obj.configured_section_create(:description1)
733
+ assert_equal "desc1", desc1.note
734
+ assert_equal "teeeext", desc1.text
735
+ end
736
+
737
+ test 'creates any defined section with default values if name is nil and config is empty element' do
738
+ obj = ConfigurableSpec::Base4Safe.new
739
+ node = obj.configured_section_create(:node, config_element())
740
+ assert_equal 0, node.num
741
+ assert_equal "node", node.name
742
+ assert_equal "b4", node.type
743
+
744
+ desc1 = obj.configured_section_create(:description1, config_element())
745
+ assert_equal "desc1", desc1.note
746
+ assert_equal "teeeext", desc1.text
747
+ end
748
+
749
+ test 'creates any defined section with specified value if name is nil and configuration element is specified' do
750
+ obj = ConfigurableSpec::Base4Safe.new
751
+ node = obj.configured_section_create(:node, config_element('node', '1', {'name' => 'node1', 'type' => 'b1'}))
752
+ assert_equal 1, node.num
753
+ assert_equal "node1", node.name
754
+ assert_equal "b1", node.type
755
+
756
+ desc1 = obj.configured_section_create(:description1, config_element('description1', 'desc one', {'text' => 't'}))
757
+ assert_equal "desc one", desc1.note
758
+ assert_equal "t", desc1.text
759
+ end
760
+
761
+ test 'creates a defined section instance even if it is defined as multi:true' do
762
+ obj = ConfigurableSpec::Base4Safe.new
763
+ desc3 = obj.configured_section_create(:description3)
764
+ assert_equal "desc3", desc3.note
765
+ assert_equal "yay", desc3.text
766
+
767
+ desc3 = obj.configured_section_create(:description3, config_element('description3', 'foo'))
768
+ assert_equal "desc3: foo", desc3.note
769
+ assert_equal "yay", desc3.text
770
+ end
771
+ end
772
+
773
+ sub_test_case '#configure' do
774
+ BASE_ATTRS = {
775
+ "name1" => "1", "name2" => "2", "name3" => "3",
776
+ "name4" => "4", "name5" => "5", "name6" => "6",
777
+ }
778
+ test 'checks required subsections' do
779
+ b3 = ConfigurableSpec::Base3.new
780
+ # branch sections required
781
+ assert_raise(Fluent::ConfigError) { b3.configure(config_element('ROOT', '', BASE_ATTRS, [])) }
782
+
783
+ # branch argument required
784
+ msg = "'<branch ARG>' section requires argument, in section branch"
785
+ #expect{ b3.configure(e('ROOT', '', BASE_ATTRS, [e('branch', '')])) }.to raise_error(Fluent::ConfigError, msg)
786
+ assert_raise(Fluent::ConfigError.new(msg)) { b3.configure(config_element('ROOT', '', BASE_ATTRS, [config_element('branch', '')])) }
787
+
788
+ # leaf is not required
789
+ assert_nothing_raised { b3.configure(config_element('ROOT', '', BASE_ATTRS, [config_element('branch', 'branch_name')])) }
790
+
791
+ # leaf weight required
792
+ msg = "'weight' parameter is required, in section branch > leaf"
793
+ branch1 = config_element('branch', 'branch_name', {size: 1}, [config_element('leaf', '10', {"weight" => 1})])
794
+ assert_nothing_raised { b3.configure(config_element('ROOT', '', BASE_ATTRS, [branch1])) }
795
+ branch2 = config_element('branch', 'branch_name', {size: 1}, [config_element('leaf', '20')])
796
+ assert_raise(Fluent::ConfigError.new(msg)) { b3.configure(config_element('ROOT', '', BASE_ATTRS, [branch1, branch2])) }
797
+ branch3 = config_element('branch', 'branch_name', {size: 1}, [config_element('leaf', '10', {"weight" => 3}), config_element('leaf', '20')])
798
+ assert_raise(Fluent::ConfigError.new(msg)) { b3.configure(config_element('ROOT', '', BASE_ATTRS, [branch3])) }
799
+
800
+ ### worm not required
801
+
802
+ b4 = ConfigurableSpec::Base4.new
803
+
804
+ d1 = config_element('description1', '', {"text" => "d1"})
805
+ d2 = config_element('description2', '', {"text" => "d2"})
806
+ d3 = config_element('description3', '', {"text" => "d3"})
807
+ assert_nothing_raised { b4.configure(config_element('ROOT', '', BASE_ATTRS, [d1.dup, d2.dup, d3.dup])) }
808
+
809
+ # description1 cannot be specified 2 or more
810
+ msg = "'<description1>' section cannot be written twice or more"
811
+ assert_raise(Fluent::ConfigError.new(msg)) { b4.configure(config_element('ROOT', '', BASE_ATTRS, [d1.dup, d2.dup, d1.dup, d3.dup])) }
812
+
813
+ # description2 cannot be specified 2 or more
814
+ msg = "'<description2>' section cannot be written twice or more"
815
+ assert_raise(Fluent::ConfigError.new(msg)) { b4.configure(config_element('ROOT', '', BASE_ATTRS, [d1.dup, d2.dup, d3.dup, d2.dup])) }
816
+
817
+ # description3 can be specified 2 or more
818
+ assert_nothing_raised { b4.configure(config_element('ROOT', '', BASE_ATTRS, [d1.dup, d2.dup, d3.dup, d3.dup])) }
819
+ end
820
+
821
+ test 'constructs configuration object tree for Base3' do
822
+ conf = config_element(
823
+ 'ROOT',
824
+ '',
825
+ BASE_ATTRS,
826
+ [
827
+ config_element('node', '', {"type" => "1"}), config_element('node', '', {"name" => "node2","type" => "2"}),
828
+ config_element('branch', 'b1.*', {}, []),
829
+ config_element('branch',
830
+ 'b2.*',
831
+ {"size" => 5},
832
+ [
833
+ config_element('leaf', 'THIS IS IGNORED', {"weight" => 55}, []),
834
+ config_element('leaf', 'THIS IS IGNORED', {"weight" => 50}, [ config_element('worm', '', {}) ]),
835
+ config_element('leaf', 'THIS IS IGNORED', {"weight" => 50}, [ config_element('worm', '', {"type" => "w1"}), config_element('worm', '', {"type" => "w2"}) ]),
836
+ ]
837
+ ),
838
+ config_element('branch',
839
+ 'b3.*',
840
+ {"size" => "503"},
841
+ [
842
+ config_element('leaf', 'THIS IS IGNORED', {"weight" => 55}, []),
843
+ ]
844
+ )
845
+ ],
846
+ )
847
+ b3 = ConfigurableSpec::Base3.new.configure(conf)
848
+
849
+ assert_not_equal("node", b3.node) # overwritten
850
+
851
+ assert_equal("1", b3.name1)
852
+ assert_equal("2", b3.name2)
853
+ assert_equal("3", b3.name3)
854
+ assert_equal("4", b3.name4)
855
+ assert_equal("5", b3.name5)
856
+ assert_equal("6", b3.name6)
857
+
858
+ assert_instance_of(Array, b3.node)
859
+ assert_equal(2, b3.node.size)
860
+
861
+ assert_equal("node", b3.node[0].name)
862
+ assert_equal("1", b3.node[0].type)
863
+ assert_equal(b3.node[0].type, b3.node[0][:type])
864
+ assert_equal("node2", b3.node[1].name)
865
+ assert_equal("2", b3.node[1].type)
866
+ assert_equal(b3.node[1].type, b3.node[1][:type])
867
+
868
+ assert_instance_of(Array, b3.branch)
869
+ assert_equal(3, b3.branch.size)
870
+
871
+ assert_equal('b1.*', b3.branch[0].name)
872
+ assert_equal(10, b3.branch[0].size)
873
+ assert_equal([], b3.branch[0].leaf)
874
+
875
+ assert_equal('b2.*', b3.branch[1].name)
876
+ assert_equal(5, b3.branch[1].size)
877
+ assert_equal(3, b3.branch[1].leaf.size)
878
+ assert_equal(b3.branch[1].leaf, b3.branch[1][:leaf])
879
+
880
+ assert_equal(55, b3.branch[1].leaf[0].weight)
881
+ assert_equal(0, b3.branch[1].leaf[0].worms.size)
882
+
883
+ assert_equal(50, b3.branch[1].leaf[1].weight)
884
+ assert_equal(1, b3.branch[1].leaf[1].worms.size)
885
+ assert_equal("ladybird", b3.branch[1].leaf[1].worms[0].type)
886
+
887
+ assert_equal(50, b3.branch[1].leaf[2].weight)
888
+ assert_equal(2, b3.branch[1].leaf[2].worms.size)
889
+ assert_equal("w1", b3.branch[1].leaf[2].worms[0].type)
890
+ assert_equal("w2", b3.branch[1].leaf[2].worms[1].type)
891
+
892
+ assert_equal('b3.*', b3.branch[2].name)
893
+ assert_equal(503, b3.branch[2].size)
894
+ assert_equal(1, b3.branch[2].leaf.size)
895
+ assert_equal(55, b3.branch[2].leaf[0].weight)
896
+ end
897
+
898
+ test 'constructs confuguration object tree for Base4' do
899
+ conf = config_element(
900
+ 'ROOT',
901
+ '',
902
+ BASE_ATTRS,
903
+ [
904
+ config_element('node', '1', {"type" => "1"}), config_element('node', '2', {"name" => "node2"}),
905
+ config_element('description3', '', {"text" => "dddd3-1"}),
906
+ config_element('description2', 'd-2', {"text" => "dddd2"}),
907
+ config_element('description1', '', {"text" => "dddd1"}),
908
+ config_element('description3', 'd-3', {"text" => "dddd3-2"}),
909
+ config_element('description3', 'd-3a', {"text" => "dddd3-3"}),
910
+ config_element('node', '4', {"type" => "four"}),
911
+ ],
912
+ )
913
+ b4 = ConfigurableSpec::Base4.new.configure(conf)
914
+
915
+ assert_equal("node", b4.node)
916
+
917
+ assert_equal("1", b4.name1)
918
+ assert_equal("2", b4.name2)
919
+ assert_equal("3", b4.name3)
920
+ assert_equal("4", b4.name4)
921
+ assert_equal("5", b4.name5)
922
+ assert_equal("6", b4.name6)
923
+
924
+ assert_instance_of(Array, b4.nodes)
925
+ assert_equal(3, b4.nodes.size)
926
+ assert_equal(1, b4.nodes[0].num)
927
+ assert_equal("node", b4.nodes[0].name)
928
+ assert_equal("1", b4.nodes[0].type)
929
+ assert_equal(2, b4.nodes[1].num)
930
+ assert_equal("node2", b4.nodes[1].name)
931
+ assert_equal("b4", b4.nodes[1].type)
932
+ assert_equal(4, b4.nodes[2].num)
933
+ assert_equal("node", b4.nodes[2].name)
934
+ assert_equal("four", b4.nodes[2].type)
935
+
936
+ # config_element('description3', '', {"text" => "dddd3-1"}),
937
+ # config_element('description3', 'd-3', {"text" => "dddd3-2"}),
938
+ # config_element('description3', 'd-3a', {"text" => "dddd3-3"}),
939
+
940
+ # NoMethodError: undefined method `class' for <Fluent::Config::Section {...}>:Fluent::Config::Section occurred. Should we add class method to Section?
941
+ #assert_equal('Fluent::Config::Section', b4.description1.class.name)
942
+ assert_equal("desc1", b4.description1.note)
943
+ assert_equal("dddd1", b4.description1.text)
944
+
945
+ # same with assert_equal('Fluent::Config::Section', b4.description1)
946
+ #assert_equal('Fluent::Config::Section', b4.description2)
947
+ assert_equal("d-2", b4.description2.note)
948
+ assert_equal("dddd2", b4.description2.text)
949
+
950
+ assert_instance_of(Array, b4.description3)
951
+ assert_equal(3, b4.description3.size)
952
+ assert_equal("desc3", b4.description3[0].note)
953
+ assert_equal("dddd3-1", b4.description3[0].text)
954
+ assert_equal('desc3: d-3', b4.description3[1].note)
955
+ assert_equal('dddd3-2', b4.description3[1].text)
956
+ assert_equal('desc3: d-3a', b4.description3[2].note)
957
+ assert_equal('dddd3-3', b4.description3[2].text)
958
+ end
959
+
960
+ test 'checks missing of specifications' do
961
+ conf0 = config_element('ROOT', '', {}, [])
962
+ ex01 = ConfigurableSpec::Example0.new
963
+ assert_raise(Fluent::ConfigError) { ex01.configure(conf0) }
964
+
965
+ complete = config_element('ROOT', '', {
966
+ "stringvalue" => "s1", "boolvalue" => "yes", "integervalue" => "10",
967
+ "sizevalue" => "10m", "timevalue" => "100s", "floatvalue" => "1.001",
968
+ "hashvalue" => '{"foo":1, "bar":2}',
969
+ "arrayvalue" => '[1,"ichi"]',
970
+ })
971
+
972
+ checker = lambda { |conf| ConfigurableSpec::Example0.new.configure(conf) }
973
+
974
+ assert_nothing_raised { checker.call(complete) }
975
+ assert_raise(Fluent::ConfigError) { c = complete.dup; c.delete("stringvalue"); checker.call(c) }
976
+ assert_raise(Fluent::ConfigError) { c = complete.dup; c.delete("boolvalue"); checker.call(c) }
977
+ assert_raise(Fluent::ConfigError) { c = complete.dup; c.delete("integervalue"); checker.call(c) }
978
+ assert_raise(Fluent::ConfigError) { c = complete.dup; c.delete("sizevalue"); checker.call(c) }
979
+ assert_raise(Fluent::ConfigError) { c = complete.dup; c.delete("timevalue"); checker.call(c) }
980
+ assert_raise(Fluent::ConfigError) { c = complete.dup; c.delete("floatvalue"); checker.call(c) }
981
+ assert_raise(Fluent::ConfigError) { c = complete.dup; c.delete("hashvalue"); checker.call(c) }
982
+ assert_raise(Fluent::ConfigError) { c = complete.dup; c.delete("arrayvalue"); checker.call(c) }
983
+ end
984
+
985
+ test 'generates section with default values for init:true sections' do
986
+ conf = config_element('ROOT', '', {}, [])
987
+ init0 = ConfigurableSpec::Init0.new
988
+ assert_nothing_raised { init0.configure(conf) }
989
+ assert init0.sec1
990
+ assert_equal "sec1", init0.sec1.name
991
+ assert_equal 1, init0.sec2.size
992
+ assert_equal "sec1", init0.sec2.first.name
993
+ end
994
+
995
+ test 'accepts configuration values as string representation' do
996
+ conf = config_element('ROOT', '', {
997
+ "stringvalue" => "s1", "boolvalue" => "yes", "integervalue" => "10",
998
+ "sizevalue" => "10m", "timevalue" => "10m", "floatvalue" => "1.001",
999
+ "hashvalue" => '{"foo":1, "bar":2}',
1000
+ "arrayvalue" => '[1,"ichi"]',
1001
+ })
1002
+ ex = ConfigurableSpec::Example0.new.configure(conf)
1003
+ assert_equal("s1", ex.stringvalue)
1004
+ assert_true(ex.boolvalue)
1005
+ assert_equal(10, ex.integervalue)
1006
+ assert_equal(10 * 1024 * 1024, ex.sizevalue)
1007
+ assert_equal(10 * 60, ex.timevalue)
1008
+ assert_equal(1.001, ex.floatvalue)
1009
+ assert_equal({"foo" => 1, "bar" => 2}, ex.hashvalue)
1010
+ assert_equal([1, "ichi"], ex.arrayvalue)
1011
+ end
1012
+
1013
+ test 'accepts configuration values as ruby value representation (especially for DSL)' do
1014
+ conf = config_element('ROOT', '', {
1015
+ "stringvalue" => "s1", "boolvalue" => true, "integervalue" => 10,
1016
+ "sizevalue" => 10 * 1024 * 1024, "timevalue" => 10 * 60, "floatvalue" => 1.001,
1017
+ "hashvalue" => {"foo" => 1, "bar" => 2},
1018
+ "arrayvalue" => [1,"ichi"],
1019
+ })
1020
+ ex = ConfigurableSpec::Example0.new.configure(conf)
1021
+ assert_equal("s1", ex.stringvalue)
1022
+ assert_true(ex.boolvalue)
1023
+ assert_equal(10, ex.integervalue)
1024
+ assert_equal(10 * 1024 * 1024, ex.sizevalue)
1025
+ assert_equal(10 * 60, ex.timevalue)
1026
+ assert_equal(1.001, ex.floatvalue)
1027
+ assert_equal({"foo" => 1, "bar" => 2}, ex.hashvalue)
1028
+ assert_equal([1, "ichi"], ex.arrayvalue)
1029
+ end
1030
+
1031
+ test 'gets both of true(yes) and false(no) for bool value parameter' do
1032
+ conf = config_element('ROOT', '', {
1033
+ "stringvalue" => "s1", "integervalue" => 10,
1034
+ "sizevalue" => 10 * 1024 * 1024, "timevalue" => 10 * 60, "floatvalue" => 1.001,
1035
+ "hashvalue" => {"foo" => 1, "bar" => 2},
1036
+ "arrayvalue" => [1,"ichi"],
1037
+ })
1038
+ ex0 = ConfigurableSpec::Example0.new.configure(conf.merge({"boolvalue" => "true"}))
1039
+ assert_true(ex0.boolvalue)
1040
+
1041
+ ex1 = ConfigurableSpec::Example0.new.configure(conf.merge({"boolvalue" => "yes"}))
1042
+ assert_true(ex1.boolvalue)
1043
+
1044
+ ex2 = ConfigurableSpec::Example0.new.configure(conf.merge({"boolvalue" => true}))
1045
+ assert_true(ex2.boolvalue)
1046
+
1047
+ ex3 = ConfigurableSpec::Example0.new.configure(conf.merge({"boolvalue" => "false"}))
1048
+ assert_false(ex3.boolvalue)
1049
+
1050
+ ex4 = ConfigurableSpec::Example0.new.configure(conf.merge({"boolvalue" => "no"}))
1051
+ assert_false(ex4.boolvalue)
1052
+
1053
+ ex5 = ConfigurableSpec::Example0.new.configure(conf.merge({"boolvalue" => false}))
1054
+ assert_false(ex5.boolvalue)
1055
+ end
1056
+ end
1057
+
1058
+ sub_test_case '.config_section' do
1059
+ CONF1 = config_element('ROOT', '', {
1060
+ 'name' => 'tagomoris',
1061
+ 'bool' => true,
1062
+ })
1063
+
1064
+ CONF2 = config_element('ROOT', '', {
1065
+ 'name' => 'tagomoris',
1066
+ 'bool' => true,
1067
+ },
1068
+ [config_element('detail', '', { 'phone_no' => "+81-00-0000-0000" }, [])])
1069
+
1070
+ CONF3 = config_element('ROOT', '', {
1071
+ 'name' => 'tagomoris',
1072
+ 'bool' => true,
1073
+ },
1074
+ [config_element('detail', '', { 'address' => "Chiyoda Tokyo Japan" }, [])])
1075
+
1076
+ CONF4 = config_element('ROOT', '', {
1077
+ 'name' => 'tagomoris',
1078
+ 'bool' => true,
1079
+ },
1080
+ [
1081
+ config_element('detail', '', {
1082
+ 'address' => "Chiyoda Tokyo Japan",
1083
+ 'phone_no' => '+81-00-0000-0000'
1084
+ },
1085
+ [])
1086
+ ])
1087
+
1088
+ data(conf1: CONF1,
1089
+ conf2: CONF2,
1090
+ conf3: CONF3,
1091
+ conf4: CONF4,)
1092
+ test 'base class' do |data|
1093
+ assert_nothing_raised { ConfigurableSpec::Overwrite::Base.new.configure(data) }
1094
+ end
1095
+
1096
+ test 'subclass cannot overwrite required' do
1097
+ assert_raise(Fluent::ConfigError.new("BUG: subclass cannot overwrite base class's config_section: required")) do
1098
+ ConfigurableSpec::Overwrite::Required.new.configure(CONF1)
1099
+ end
1100
+ end
1101
+
1102
+ test 'subclass cannot overwrite multi' do
1103
+ assert_raise(Fluent::ConfigError.new("BUG: subclass cannot overwrite base class's config_section: multi")) do
1104
+ ConfigurableSpec::Overwrite::Multi.new.configure(CONF1)
1105
+ end
1106
+ end
1107
+
1108
+ test 'subclass cannot overwrite alias' do
1109
+ assert_raise(Fluent::ConfigError.new("BUG: subclass cannot overwrite base class's config_section: alias")) do
1110
+ ConfigurableSpec::Overwrite::Alias.new.configure(CONF1)
1111
+ end
1112
+ end
1113
+
1114
+ test 'subclass uses superclass default options' do
1115
+ base = ConfigurableSpec::Overwrite::Base.new.configure(CONF2)
1116
+ sub = ConfigurableSpec::Overwrite::DefaultOptions.new.configure(CONF2)
1117
+ detail_base = base.class.merged_configure_proxy.sections[:detail]
1118
+ detail_sub = sub.class.merged_configure_proxy.sections[:detail]
1119
+ detail_base_attributes = {
1120
+ required: detail_base.required,
1121
+ multi: detail_base.multi,
1122
+ alias: detail_base.alias,
1123
+ }
1124
+ detail_sub_attributes = {
1125
+ required: detail_sub.required,
1126
+ multi: detail_sub.multi,
1127
+ alias: detail_sub.alias,
1128
+ }
1129
+ assert_equal(detail_base_attributes, detail_sub_attributes)
1130
+ end
1131
+
1132
+ test 'subclass can overwrite detail.address' do
1133
+ base = ConfigurableSpec::Overwrite::Base.new.configure(CONF2)
1134
+ target = ConfigurableSpec::Overwrite::DetailAddressDefault.new.configure(CONF2)
1135
+ expected_addresses = ["x", "y"]
1136
+ actual_addresses = [base.detail.address, target.detail.address]
1137
+ assert_equal(expected_addresses, actual_addresses)
1138
+ end
1139
+
1140
+ test 'subclass can add param' do
1141
+ assert_raise(Fluent::ConfigError.new("'phone_no' parameter is required, in section detail")) do
1142
+ ConfigurableSpec::Overwrite::AddParam.new.configure(CONF3)
1143
+ end
1144
+ target = ConfigurableSpec::Overwrite::AddParam.new.configure(CONF4)
1145
+ expected = {
1146
+ address: "Chiyoda Tokyo Japan",
1147
+ phone_no: "+81-00-0000-0000"
1148
+ }
1149
+ actual = {
1150
+ address: target.detail.address,
1151
+ phone_no: target.detail.phone_no
1152
+ }
1153
+ assert_equal(expected, actual)
1154
+ end
1155
+
1156
+ test 'subclass can add param with overwriting address' do
1157
+ assert_raise(Fluent::ConfigError.new("'phone_no' parameter is required, in section detail")) do
1158
+ ConfigurableSpec::Overwrite::AddParamOverwriteAddress.new.configure(CONF3)
1159
+ end
1160
+ target = ConfigurableSpec::Overwrite::AddParamOverwriteAddress.new.configure(CONF4)
1161
+ expected = {
1162
+ address: "Chiyoda Tokyo Japan",
1163
+ phone_no: "+81-00-0000-0000"
1164
+ }
1165
+ actual = {
1166
+ address: target.detail.address,
1167
+ phone_no: target.detail.phone_no
1168
+ }
1169
+ assert_equal(expected, actual)
1170
+ end
1171
+
1172
+ sub_test_case 'final' do
1173
+ test 'base class has designed params and default values' do
1174
+ b = ConfigurableSpec::Final::Base.new
1175
+ appendix_conf = config_element('appendix', '', {"code" => "b", "name" => "base"})
1176
+ b.configure(config_element('ROOT', '', {}, [appendix_conf]))
1177
+
1178
+ assert_equal "b", b.appendix.code
1179
+ assert_equal "base", b.appendix.name
1180
+ assert_equal "", b.appendix.address
1181
+ end
1182
+
1183
+ test 'subclass can change type, add default value, change default value of parameters, and add parameters to non-finalized section' do
1184
+ f = ConfigurableSpec::Final::Finalized.new
1185
+ appendix_conf = config_element('appendix', '', {"code" => 1})
1186
+ f.configure(config_element('ROOT', '', {}, [appendix_conf]))
1187
+
1188
+ assert_equal 1, f.appendix.code
1189
+ assert_equal 'y', f.appendix.name
1190
+ assert_equal "-", f.appendix.address
1191
+ assert_equal 10, f.appendix.age
1192
+ end
1193
+
1194
+ test 'subclass can add default value, change default value of parameters, and add parameters to finalized section' do
1195
+ i = ConfigurableSpec::Final::InheritsFinalized.new
1196
+ appendix_conf = config_element('appendix', '', {"phone_no" => "00-0000-0000"})
1197
+ i.configure(config_element('ROOT', '', {}, [appendix_conf]))
1198
+
1199
+ assert_equal 2, i.appendix.code
1200
+ assert_equal 0, i.appendix.age
1201
+ assert_equal "00-0000-0000", i.appendix.phone_no
1202
+ end
1203
+
1204
+ test 'finalized base class works as designed' do
1205
+ b = ConfigurableSpec::Final::FinalizedBase.new
1206
+ appendix_conf = config_element('options', '', {"name" => "moris"})
1207
+
1208
+ assert_nothing_raised do
1209
+ b.configure(config_element('ROOT', '', {}, [appendix_conf]))
1210
+ end
1211
+ assert b.apd
1212
+ assert_equal "moris", b.apd.name
1213
+ end
1214
+
1215
+ test 'subclass can change init' do
1216
+ n = ConfigurableSpec::Final::OverwriteInit.new
1217
+
1218
+ assert_nothing_raised do
1219
+ n.configure(config_element('ROOT', ''))
1220
+ end
1221
+ assert n.apd
1222
+ assert_equal "moris", n.apd.name
1223
+ assert_equal 0, n.apd.code
1224
+ end
1225
+
1226
+ test 'subclass cannot change parameter types in finalized sections' do
1227
+ s = ConfigurableSpec::Final::Subclass.new
1228
+ appendix_conf = config_element('options', '', {"name" => "1"})
1229
+
1230
+ assert_nothing_raised do
1231
+ s.configure(config_element('ROOT', '', {}, [appendix_conf]))
1232
+ end
1233
+ assert_equal "1", s.apd.name
1234
+ end
1235
+
1236
+ test 'subclass cannot change param_name of finalized section' do
1237
+ assert_raise(Fluent::ConfigError.new("BUG: subclass cannot overwrite base class's config_section: param_name")) do
1238
+ ConfigurableSpec::Final::OverwriteParamName.new
1239
+ end
1240
+ end
1241
+
1242
+ test 'subclass cannot change final of finalized section' do
1243
+ assert_raise(Fluent::ConfigError.new("BUG: subclass cannot overwrite finalized base class's config_section")) do
1244
+ ConfigurableSpec::Final::OverwriteFinal.new
1245
+ end
1246
+ end
1247
+
1248
+ test 'subclass cannot change required of finalized section' do
1249
+ assert_raise(Fluent::ConfigError.new("BUG: subclass cannot overwrite base class's config_section: required")) do
1250
+ ConfigurableSpec::Final::OverwriteRequired.new
1251
+ end
1252
+ end
1253
+
1254
+ test 'subclass cannot change multi of finalized section' do
1255
+ assert_raise(Fluent::ConfigError.new("BUG: subclass cannot overwrite base class's config_section: multi")) do
1256
+ ConfigurableSpec::Final::OverwriteMulti.new
1257
+ end
1258
+ end
1259
+
1260
+ test 'subclass cannot change alias of finalized section' do
1261
+ assert_raise(Fluent::ConfigError.new("BUG: subclass cannot overwrite base class's config_section: alias")) do
1262
+ ConfigurableSpec::Final::OverwriteAlias.new
1263
+ end
1264
+ end
1265
+ end
1266
+ end
1267
+ end
1268
+
1269
+ sub_test_case 'class defined with config_param/config_section having :alias' do
1270
+ sub_test_case '#initialize' do
1271
+ test 'does not create methods for alias' do
1272
+ ex1 = ConfigurableSpec::ExampleWithAlias.new
1273
+ assert_nothing_raised { ex1.name }
1274
+ assert_raise(NoMethodError) { ex1.fullname }
1275
+ assert_nothing_raised { ex1.bool }
1276
+ assert_raise(NoMethodError) { ex1.flag }
1277
+ assert_nothing_raised { ex1.detail }
1278
+ assert_raise(NoMethodError) { ex1.information}
1279
+ end
1280
+ end
1281
+
1282
+ sub_test_case '#configure' do
1283
+ test 'provides accessible data for alias attribute keys' do
1284
+ ex1 = ConfigurableSpec::ExampleWithAlias.new
1285
+ conf = config_element('ROOT', '', {
1286
+ "fullname" => "foo bar",
1287
+ "bool" => false
1288
+ },
1289
+ [config_element('information', '', {"address" => "Mountain View 0"})])
1290
+ ex1.configure(conf)
1291
+ assert_equal("foo bar", ex1.name)
1292
+ assert_not_nil(ex1.bool)
1293
+ assert_false(ex1.bool)
1294
+ assert_not_nil(ex1.detail)
1295
+ assert_equal("Mountain View 0", ex1.detail.address)
1296
+ end
1297
+ end
1298
+ end
1299
+
1300
+ sub_test_case 'defaults can be overwritten by owner' do
1301
+ test 'for feature plugin which has flat parameters with parent' do
1302
+ owner = ConfigurableSpec::OverwriteDefaults::Owner.new
1303
+ child = ConfigurableSpec::OverwriteDefaults::FlatChild.new
1304
+ assert_nil child.class.merged_configure_proxy.configured_in_section
1305
+
1306
+ child.owner = owner
1307
+ child.configure(config_element('ROOT', '', {}, []))
1308
+ assert_equal "V1", child.key1
1309
+ end
1310
+
1311
+ test 'for feature plugin which has parameters in subsection of parent' do
1312
+ owner = ConfigurableSpec::OverwriteDefaults::Owner.new
1313
+ child = ConfigurableSpec::OverwriteDefaults::BufferChild.new
1314
+ assert_equal :buffer, child.class.merged_configure_proxy.configured_in_section
1315
+
1316
+ child.owner = owner
1317
+ child.configure(config_element('ROOT', '', {}, []))
1318
+ assert_equal 1024, child.size_of_something
1319
+ end
1320
+
1321
+ test 'even in subclass of owner' do
1322
+ owner = ConfigurableSpec::OverwriteDefaults::SubOwner.new
1323
+ child = ConfigurableSpec::OverwriteDefaults::BufferChild.new
1324
+ assert_equal :buffer, child.class.merged_configure_proxy.configured_in_section
1325
+
1326
+ child.owner = owner
1327
+ child.configure(config_element('ROOT', '', {}, []))
1328
+ assert_equal 2048, child.size_of_something
1329
+ end
1330
+
1331
+ test 'default values can be overwritten with nil' do
1332
+ owner = ConfigurableSpec::OverwriteDefaults::NilOwner.new
1333
+ child = ConfigurableSpec::OverwriteDefaults::BufferChild.new
1334
+ assert_equal :buffer, child.class.merged_configure_proxy.configured_in_section
1335
+
1336
+ child.owner = owner
1337
+ child.configure(config_element('ROOT', '', {}, []))
1338
+ assert_nil child.size_of_something
1339
+ end
1340
+
1341
+ test 'the first configured_in (in the order from base class) will be applied' do
1342
+ child = ConfigurableSpec::OverwriteDefaults::BufferSubclass.new
1343
+ assert_equal :buffer, child.class.merged_configure_proxy.configured_in_section
1344
+
1345
+ child.configure(config_element('ROOT', '', {}, []))
1346
+ assert_equal 512, child.size_of_something
1347
+ end
1348
+
1349
+ test 'the first configured_in is valid with owner classes' do
1350
+ owner = ConfigurableSpec::OverwriteDefaults::Owner.new
1351
+ child = ConfigurableSpec::OverwriteDefaults::BufferSubclass.new
1352
+ assert_equal :buffer, child.class.merged_configure_proxy.configured_in_section
1353
+
1354
+ child.owner = owner
1355
+ child.configure(config_element('ROOT', '', {}, []))
1356
+ assert_equal 1024, child.size_of_something
1357
+ end
1358
+
1359
+ test 'the only first configured_in is valid even in subclasses of a class with configured_in' do
1360
+ child = ConfigurableSpec::OverwriteDefaults::BufferSubSubclass.new
1361
+ assert_equal :buffer, child.class.merged_configure_proxy.configured_in_section
1362
+
1363
+ child.configure(config_element('ROOT', '', {}, []))
1364
+ assert_equal 512, child.size_of_something
1365
+ end
1366
+ end
1367
+
1368
+ sub_test_case ':secret option' do
1369
+ setup do
1370
+ @conf = config_element('ROOT', '',
1371
+ {
1372
+ 'normal_param' => 'normal',
1373
+ 'secret_param' => 'secret'
1374
+ },
1375
+ [config_element('section', '', {'normal_param2' => 'normal', 'secret_param2' => 'secret'} )])
1376
+ @example = ConfigurableSpec::ExampleWithSecret.new
1377
+ @example.configure(@conf)
1378
+ end
1379
+
1380
+ test 'to_s hides secret config_param' do
1381
+ @conf.to_s.each_line { |line|
1382
+ key, value = line.strip.split(' ', 2)
1383
+ assert_secret_param(key, value)
1384
+ }
1385
+ end
1386
+
1387
+ test 'config returns masked configuration' do
1388
+ conf = @example.config
1389
+ conf.each_pair { |key, value|
1390
+ assert_secret_param(key, value)
1391
+ }
1392
+ conf.elements.each { |element|
1393
+ element.each_pair { |key, value|
1394
+ assert_secret_param(key, value)
1395
+ }
1396
+ }
1397
+ end
1398
+
1399
+ def assert_secret_param(key, value)
1400
+ case key
1401
+ when 'normal_param', 'normal_param2'
1402
+ assert_equal 'normal', value
1403
+ when 'secret_param', 'secret_param2'
1404
+ assert_equal 'xxxxxx', value
1405
+ end
1406
+ end
1407
+ end
1408
+
1409
+ sub_test_case 'unused section' do
1410
+ test 'get plugin name when found unknown section' do
1411
+ conf = config_element('ROOT', '',
1412
+ {
1413
+ 'name_param' => 'name',
1414
+ },
1415
+ [config_element('unknown', '', {'name_param' => 'normal'} )])
1416
+ example = ConfigurableSpec::ExampleWithCustomSection.new
1417
+ example.configure(conf)
1418
+ conf.elements.each { |e|
1419
+ assert_equal(['ROOT', nil], e.unused_in)
1420
+ }
1421
+ end
1422
+
1423
+ test 'get an empty array when the section is defined without using config_section' do
1424
+ conf = config_element('ROOT', '',
1425
+ {
1426
+ 'name_param' => 'name',
1427
+ },
1428
+ [config_element('custom_section', '', {'custom_section_param' => 'custom'} )])
1429
+ example = ConfigurableSpec::ExampleWithCustomSection.new
1430
+ example.configure(conf)
1431
+ conf.elements.each { |e|
1432
+ assert_equal([], e.unused_in)
1433
+ }
1434
+ end
1435
+
1436
+ test 'get an empty array when the configuration is used in another element without any sections' do
1437
+ conf = config_element('ROOT', '',
1438
+ {
1439
+ 'name_param' => 'name',
1440
+ },
1441
+ [config_element('normal_section', '', {'normal_section_param' => 'normal'} )])
1442
+ example = ConfigurableSpec::ExampleWithCustomSection.new
1443
+ example.configure(conf)
1444
+ ConfigurableSpec::ExampleWithCustomSection::AnotherElement.new.configure(conf)
1445
+ conf.elements.each { |e|
1446
+ assert_equal([], e.unused_in)
1447
+ }
1448
+ end
1449
+ end
1450
+
1451
+ sub_test_case ':skip_accessor option' do
1452
+ test 'it does not create accessor methods for parameters' do
1453
+ @example = ConfigurableSpec::ExampleWithSkipAccessor.new
1454
+ @example.configure(config_element('ROOT'))
1455
+ assert_equal 'example7', @example.instance_variable_get(:@name)
1456
+ assert_raise NoMethodError do
1457
+ @example.name
1458
+ end
1459
+ end
1460
+ end
1461
+
1462
+ sub_test_case 'non-required options for config_param' do
1463
+ test 'desc must be a string if specified' do
1464
+ assert_raise ArgumentError.new("key: desc must be a String, but Symbol") do
1465
+ class InvalidDescClass
1466
+ include Fluent::Configurable
1467
+ config_param :key, :string, default: '', desc: :invalid_description
1468
+ end
1469
+ end
1470
+ end
1471
+ test 'alias must be a symbol if specified' do
1472
+ assert_raise ArgumentError.new("key: alias must be a Symbol, but String") do
1473
+ class InvalidAliasClass
1474
+ include Fluent::Configurable
1475
+ config_param :key, :string, default: '', alias: 'yay'
1476
+ end
1477
+ end
1478
+ end
1479
+ test 'secret must be true or false if specified' do
1480
+ assert_raise ArgumentError.new("key: secret must be true or false, but NilClass") do
1481
+ class InvalidSecretClass
1482
+ include Fluent::Configurable
1483
+ config_param :key, :string, default: '', secret: nil
1484
+ end
1485
+ end
1486
+ assert_raise ArgumentError.new("key: secret must be true or false, but String") do
1487
+ class InvalidSecret2Class
1488
+ include Fluent::Configurable
1489
+ config_param :key, :string, default: '', secret: 'yes'
1490
+ end
1491
+ end
1492
+ end
1493
+ test 'deprecated must be a string if specified' do
1494
+ assert_raise ArgumentError.new("key: deprecated must be a String, but TrueClass") do
1495
+ class InvalidDeprecatedClass
1496
+ include Fluent::Configurable
1497
+ config_param :key, :string, default: '', deprecated: true
1498
+ end
1499
+ end
1500
+ end
1501
+ test 'obsoleted must be a string if specified' do
1502
+ assert_raise ArgumentError.new("key: obsoleted must be a String, but TrueClass") do
1503
+ class InvalidObsoletedClass
1504
+ include Fluent::Configurable
1505
+ config_param :key, :string, default: '', obsoleted: true
1506
+ end
1507
+ end
1508
+ end
1509
+ test 'value_type for hash must be a symbol' do
1510
+ assert_raise ArgumentError.new("key: value_type must be a Symbol, but String") do
1511
+ class InvalidValueTypeOfHashClass
1512
+ include Fluent::Configurable
1513
+ config_param :key, :hash, value_type: 'yay'
1514
+ end
1515
+ end
1516
+ end
1517
+ test 'value_type for array must be a symbol' do
1518
+ assert_raise ArgumentError.new("key: value_type must be a Symbol, but String") do
1519
+ class InvalidValueTypeOfArrayClass
1520
+ include Fluent::Configurable
1521
+ config_param :key, :array, value_type: 'yay'
1522
+ end
1523
+ end
1524
+ end
1525
+ test 'skip_accessor must be true or false if specified' do
1526
+ assert_raise ArgumentError.new("key: skip_accessor must be true or false, but NilClass") do
1527
+ class InvalidSkipAccessorClass
1528
+ include Fluent::Configurable
1529
+ config_param :key, :string, default: '', skip_accessor: nil
1530
+ end
1531
+ end
1532
+ assert_raise ArgumentError.new("key: skip_accessor must be true or false, but String") do
1533
+ class InvalidSkipAccessor2Class
1534
+ include Fluent::Configurable
1535
+ config_param :key, :string, default: '', skip_accessor: 'yes'
1536
+ end
1537
+ end
1538
+ end
1539
+ end
1540
+ sub_test_case 'enum parameters' do
1541
+ test 'list must be specified as an array of symbols'
1542
+ end
1543
+ sub_test_case 'deprecated/obsoleted parameters' do
1544
+ test 'both cannot be specified at once' do
1545
+ assert_raise ArgumentError.new("param1: both of deprecated and obsoleted cannot be specified at once") do
1546
+ class Buggy1
1547
+ include Fluent::Configurable
1548
+ config_param :param1, :string, default: '', deprecated: 'yay', obsoleted: 'foo!'
1549
+ end
1550
+ end
1551
+ end
1552
+
1553
+ test 'warned if deprecated parameter is configured' do
1554
+ obj = ConfigurableSpec::UnRecommended.new
1555
+ obj.log = Fluent::Test::TestLogger.new
1556
+ obj.configure(config_element('ROOT', '', {'key1' => 'yay'}, []))
1557
+
1558
+ assert_equal 'yay', obj.key1
1559
+ first_log = obj.log.logs.first
1560
+ assert{ first_log && first_log.include?("[warn]") && first_log.include?("'key1' parameter is deprecated: key1 will be removed.") }
1561
+ end
1562
+
1563
+ test 'error raised if obsoleted parameter is configured' do
1564
+ obj = ConfigurableSpec::UnRecommended.new
1565
+ obj.log = Fluent::Test::TestLogger.new
1566
+
1567
+ assert_raise Fluent::ObsoletedParameterError.new("'key2' parameter is already removed: key2 has been removed.") do
1568
+ obj.configure(config_element('ROOT', '', {'key2' => 'yay'}, []))
1569
+ end
1570
+ first_log = obj.log.logs.first
1571
+ assert{ first_log && first_log.include?("[error]") && first_log.include?("config error in:\n<ROOT>\n key2 yay\n</ROOT>") }
1572
+ end
1573
+
1574
+ sub_test_case 'logger is nil' do
1575
+ test 'nothing raised if deprecated parameter is configured' do
1576
+ obj = ConfigurableSpec::UnRecommended.new
1577
+ obj.log = nil
1578
+ obj.configure(config_element('ROOT', '', {'key1' => 'yay'}, []))
1579
+ assert_nil(obj.log)
1580
+ end
1581
+
1582
+ test 'NoMethodError is not raised if obsoleted parameter is configured' do
1583
+ obj = ConfigurableSpec::UnRecommended.new
1584
+ obj.log = nil
1585
+ assert_raise Fluent::ObsoletedParameterError.new("'key2' parameter is already removed: key2 has been removed.") do
1586
+ obj.configure(config_element('ROOT', '', {'key2' => 'yay'}, []))
1587
+ end
1588
+ assert_nil(obj.log)
1589
+ end
1590
+ end
1591
+ end
1592
+
1593
+ sub_test_case '#config_param without default values cause error if section is configured as init:true' do
1594
+ setup do
1595
+ @type_lookup = ->(type) { Fluent::Configurable.lookup_type(type) }
1596
+ @proxy = Fluent::Config::ConfigureProxy.new(:section, type_lookup: @type_lookup)
1597
+ end
1598
+
1599
+ test 'with simple config_param with default value' do
1600
+ class InitTestClass01
1601
+ include Fluent::Configurable
1602
+ config_section :subsection, init: true do
1603
+ config_param :param1, :integer, default: 1
1604
+ end
1605
+ end
1606
+ c = InitTestClass01.new
1607
+ c.configure(config_element('root', ''))
1608
+
1609
+ assert_equal 1, c.subsection.size
1610
+ assert_equal 1, c.subsection.first.param1
1611
+ end
1612
+
1613
+ test 'with simple config_param without default value' do
1614
+ class InitTestClass02
1615
+ include Fluent::Configurable
1616
+ config_section :subsection, init: true do
1617
+ config_param :param1, :integer
1618
+ end
1619
+ end
1620
+ c = InitTestClass02.new
1621
+ assert_raises ArgumentError.new("subsection: init is specified, but there're parameters without default values:param1") do
1622
+ c.configure(config_element('root', ''))
1623
+ end
1624
+
1625
+ c.configure(config_element('root', '', {}, [config_element('subsection', '', {'param1' => '1'})]))
1626
+
1627
+ assert_equal 1, c.subsection.size
1628
+ assert_equal 1, c.subsection.first.param1
1629
+ end
1630
+
1631
+ test 'with config_param with config_set_default' do
1632
+ module InitTestModule03
1633
+ include Fluent::Configurable
1634
+ config_section :subsection, init: true do
1635
+ config_param :param1, :integer
1636
+ end
1637
+ end
1638
+ class InitTestClass03
1639
+ include Fluent::Configurable
1640
+ include InitTestModule03
1641
+ config_section :subsection do
1642
+ config_set_default :param1, 1
1643
+ end
1644
+ end
1645
+
1646
+ c = InitTestClass03.new
1647
+ c.configure(config_element('root', ''))
1648
+
1649
+ assert_equal 1, c.subsection.size
1650
+ assert_equal 1, c.subsection.first.param1
1651
+ end
1652
+
1653
+ test 'with config_argument with default value' do
1654
+ class InitTestClass04
1655
+ include Fluent::Configurable
1656
+ config_section :subsection, init: true do
1657
+ config_argument :param0, :string, default: 'yay'
1658
+ end
1659
+ end
1660
+
1661
+ c = InitTestClass04.new
1662
+ c.configure(config_element('root', ''))
1663
+
1664
+ assert_equal 1, c.subsection.size
1665
+ assert_equal 'yay', c.subsection.first.param0
1666
+ end
1667
+
1668
+ test 'with config_argument without default value' do
1669
+ class InitTestClass04
1670
+ include Fluent::Configurable
1671
+ config_section :subsection, init: true do
1672
+ config_argument :param0, :string
1673
+ end
1674
+ end
1675
+
1676
+ c = InitTestClass04.new
1677
+ assert_raise ArgumentError.new("subsection: init is specified, but default value of argument is missing") do
1678
+ c.configure(config_element('root', ''))
1679
+ end
1680
+ end
1681
+
1682
+ test 'with config_argument with config_set_default' do
1683
+ module InitTestModule05
1684
+ include Fluent::Configurable
1685
+ config_section :subsection, init: true do
1686
+ config_argument :param0, :string
1687
+ end
1688
+ end
1689
+ class InitTestClass05
1690
+ include Fluent::Configurable
1691
+ include InitTestModule05
1692
+ config_section :subsection do
1693
+ config_set_default :param0, 'foo'
1694
+ end
1695
+ end
1696
+
1697
+ c = InitTestClass05.new
1698
+ c.configure(config_element('root', ''))
1699
+
1700
+ assert_equal 1, c.subsection.size
1701
+ assert_equal 'foo', c.subsection.first.param0
1702
+ end
1703
+ end
1704
+
1705
+ sub_test_case '#config_argument' do
1706
+ test 'with strict_config_value' do
1707
+ class TestClass01
1708
+ include Fluent::Configurable
1709
+ config_section :subsection do
1710
+ config_argument :param1, :integer
1711
+ end
1712
+ end
1713
+
1714
+ c = TestClass01.new
1715
+ subsection = config_element('subsection', "hoge", { })
1716
+ assert_raise(Fluent::ConfigError.new('param1: invalid value for Integer(): "hoge"')) do
1717
+ c.configure(config_element('root', '', {}, [subsection]), true)
1718
+ end
1719
+ end
1720
+
1721
+ test 'with nil' do
1722
+ class TestClass02
1723
+ include Fluent::Configurable
1724
+ config_section :subsection do
1725
+ config_argument :param1, :integer
1726
+ end
1727
+ end
1728
+
1729
+ c = TestClass02.new
1730
+ subsection = config_element('subsection', nil, { })
1731
+ assert_raise(Fluent::ConfigError.new("'<subsection ARG>' section requires argument, in section subsection")) do
1732
+ c.configure(config_element('root', '', {}, [subsection]))
1733
+ end
1734
+ end
1735
+
1736
+ test 'with nil for an argument whose default value is nil' do
1737
+ class TestClass03
1738
+ include Fluent::Configurable
1739
+ config_section :subsection do
1740
+ config_argument :param1, :integer, default: nil
1741
+ end
1742
+ end
1743
+
1744
+ c = TestClass03.new
1745
+ subsection = config_element('subsection', nil, { })
1746
+ c.configure(config_element('root', '', {}, [subsection]))
1747
+
1748
+ assert_equal 1, c.subsection.size
1749
+ assert_equal nil, c.subsection.first.param1
1750
+ end
1751
+
1752
+ test 'with :default' do
1753
+ class TestClass04
1754
+ include Fluent::Configurable
1755
+ config_section :subsection do
1756
+ config_argument :param1, :integer, default: 3
1757
+ end
1758
+ end
1759
+
1760
+ c = TestClass04.new
1761
+ subsection = config_element('subsection', :default, { })
1762
+ c.configure(config_element('root', '', {}, [subsection]))
1763
+
1764
+ assert_equal 1, c.subsection.size
1765
+ assert_equal 3, c.subsection.first.param1
1766
+ end
1767
+
1768
+ test 'with :default for an argument which does not have default value' do
1769
+ class TestClass05
1770
+ include Fluent::Configurable
1771
+ config_section :subsection do
1772
+ config_argument :param1, :integer
1773
+ end
1774
+ end
1775
+
1776
+ c = TestClass05.new
1777
+ subsection = config_element('subsection', :default, { })
1778
+ assert_raise(Fluent::ConfigError.new("'param1' doesn\'t have default value")) do
1779
+ c.configure(config_element('root', '', {}, [subsection]))
1780
+ end
1781
+ end
1782
+ end
1783
+ end
1784
+ end