fluentd 0.12.40 → 1.6.2

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 (428) hide show
  1. checksums.yaml +5 -5
  2. data/.github/ISSUE_TEMPLATE/bug_report.md +39 -0
  3. data/.github/ISSUE_TEMPLATE/feature_request.md +23 -0
  4. data/.github/ISSUE_TEMPLATE.md +17 -0
  5. data/.github/PULL_REQUEST_TEMPLATE.md +13 -0
  6. data/.gitignore +5 -0
  7. data/.gitlab/cicd-template.yaml +10 -0
  8. data/.gitlab-ci.yml +147 -0
  9. data/.travis.yml +56 -20
  10. data/ADOPTERS.md +5 -0
  11. data/CHANGELOG.md +1369 -0
  12. data/CONTRIBUTING.md +16 -5
  13. data/GOVERNANCE.md +55 -0
  14. data/Gemfile +5 -0
  15. data/GithubWorkflow.md +78 -0
  16. data/LICENSE +202 -0
  17. data/MAINTAINERS.md +7 -0
  18. data/README.md +23 -11
  19. data/Rakefile +48 -2
  20. data/Vagrantfile +17 -0
  21. data/appveyor.yml +37 -0
  22. data/bin/fluent-binlog-reader +7 -0
  23. data/bin/fluent-ca-generate +6 -0
  24. data/bin/fluent-plugin-config-format +5 -0
  25. data/bin/fluent-plugin-generate +5 -0
  26. data/bin/fluentd +3 -0
  27. data/code-of-conduct.md +3 -0
  28. data/example/copy_roundrobin.conf +39 -0
  29. data/example/counter.conf +18 -0
  30. data/example/in_dummy_blocks.conf +17 -0
  31. data/example/in_dummy_with_compression.conf +23 -0
  32. data/example/in_forward.conf +7 -0
  33. data/example/in_forward_client.conf +37 -0
  34. data/example/in_forward_shared_key.conf +15 -0
  35. data/example/in_forward_tls.conf +14 -0
  36. data/example/in_forward_users.conf +24 -0
  37. data/example/in_forward_workers.conf +21 -0
  38. data/example/in_http.conf +3 -1
  39. data/example/in_out_forward.conf +17 -0
  40. data/example/logevents.conf +25 -0
  41. data/example/multi_filters.conf +61 -0
  42. data/example/out_exec_filter.conf +42 -0
  43. data/example/out_forward.conf +13 -13
  44. data/example/out_forward_buf_file.conf +23 -0
  45. data/example/out_forward_client.conf +109 -0
  46. data/example/out_forward_heartbeat_none.conf +16 -0
  47. data/example/out_forward_shared_key.conf +36 -0
  48. data/example/out_forward_tls.conf +18 -0
  49. data/example/out_forward_users.conf +65 -0
  50. data/example/out_null.conf +36 -0
  51. data/example/secondary_file.conf +42 -0
  52. data/example/suppress_config_dump.conf +7 -0
  53. data/example/worker_section.conf +36 -0
  54. data/fluent.conf +29 -0
  55. data/fluentd.gemspec +21 -11
  56. data/lib/fluent/agent.rb +67 -90
  57. data/lib/fluent/clock.rb +62 -0
  58. data/lib/fluent/command/binlog_reader.rb +244 -0
  59. data/lib/fluent/command/ca_generate.rb +181 -0
  60. data/lib/fluent/command/cat.rb +42 -18
  61. data/lib/fluent/command/debug.rb +12 -10
  62. data/lib/fluent/command/fluentd.rb +153 -5
  63. data/lib/fluent/command/plugin_config_formatter.rb +292 -0
  64. data/lib/fluent/command/plugin_generator.rb +324 -0
  65. data/lib/fluent/compat/call_super_mixin.rb +67 -0
  66. data/lib/fluent/compat/detach_process_mixin.rb +33 -0
  67. data/lib/fluent/compat/exec_util.rb +129 -0
  68. data/lib/fluent/compat/file_util.rb +54 -0
  69. data/lib/fluent/compat/filter.rb +68 -0
  70. data/lib/fluent/compat/formatter.rb +111 -0
  71. data/lib/fluent/compat/formatter_utils.rb +85 -0
  72. data/lib/fluent/compat/handle_tag_and_time_mixin.rb +62 -0
  73. data/lib/fluent/compat/handle_tag_name_mixin.rb +53 -0
  74. data/lib/fluent/compat/input.rb +49 -0
  75. data/lib/fluent/compat/output.rb +718 -0
  76. data/lib/fluent/compat/output_chain.rb +60 -0
  77. data/lib/fluent/compat/parser.rb +310 -0
  78. data/lib/fluent/compat/parser_utils.rb +40 -0
  79. data/lib/fluent/compat/propagate_default.rb +62 -0
  80. data/lib/fluent/compat/record_filter_mixin.rb +34 -0
  81. data/lib/fluent/compat/set_tag_key_mixin.rb +50 -0
  82. data/lib/fluent/compat/set_time_key_mixin.rb +69 -0
  83. data/lib/fluent/compat/socket_util.rb +165 -0
  84. data/lib/fluent/compat/string_util.rb +34 -0
  85. data/lib/fluent/compat/structured_format_mixin.rb +26 -0
  86. data/lib/fluent/compat/type_converter.rb +90 -0
  87. data/lib/fluent/config/configure_proxy.rb +210 -62
  88. data/lib/fluent/config/dsl.rb +12 -5
  89. data/lib/fluent/config/element.rb +107 -9
  90. data/lib/fluent/config/literal_parser.rb +9 -3
  91. data/lib/fluent/config/parser.rb +4 -4
  92. data/lib/fluent/config/section.rb +51 -14
  93. data/lib/fluent/config/types.rb +28 -13
  94. data/lib/fluent/config/v1_parser.rb +3 -5
  95. data/lib/fluent/config.rb +23 -20
  96. data/lib/fluent/configurable.rb +79 -21
  97. data/lib/fluent/counter/base_socket.rb +46 -0
  98. data/lib/fluent/counter/client.rb +297 -0
  99. data/lib/fluent/counter/error.rb +86 -0
  100. data/lib/fluent/counter/mutex_hash.rb +163 -0
  101. data/lib/fluent/counter/server.rb +273 -0
  102. data/lib/fluent/counter/store.rb +205 -0
  103. data/lib/fluent/counter/validator.rb +145 -0
  104. data/lib/fluent/counter.rb +23 -0
  105. data/lib/fluent/daemon.rb +15 -0
  106. data/lib/fluent/engine.rb +102 -65
  107. data/lib/fluent/env.rb +7 -3
  108. data/lib/fluent/error.rb +30 -0
  109. data/lib/fluent/event.rb +197 -21
  110. data/lib/fluent/event_router.rb +93 -10
  111. data/lib/fluent/filter.rb +2 -50
  112. data/lib/fluent/formatter.rb +4 -293
  113. data/lib/fluent/input.rb +2 -32
  114. data/lib/fluent/label.rb +10 -2
  115. data/lib/fluent/load.rb +3 -3
  116. data/lib/fluent/log.rb +348 -81
  117. data/lib/fluent/match.rb +37 -36
  118. data/lib/fluent/mixin.rb +12 -176
  119. data/lib/fluent/msgpack_factory.rb +62 -0
  120. data/lib/fluent/output.rb +10 -612
  121. data/lib/fluent/output_chain.rb +23 -0
  122. data/lib/fluent/parser.rb +4 -800
  123. data/lib/fluent/plugin/bare_output.rb +63 -0
  124. data/lib/fluent/plugin/base.rb +192 -0
  125. data/lib/fluent/plugin/buf_file.rb +128 -174
  126. data/lib/fluent/plugin/buf_memory.rb +9 -92
  127. data/lib/fluent/plugin/buffer/chunk.rb +221 -0
  128. data/lib/fluent/plugin/buffer/file_chunk.rb +383 -0
  129. data/lib/fluent/plugin/buffer/memory_chunk.rb +90 -0
  130. data/lib/fluent/plugin/buffer.rb +779 -0
  131. data/lib/fluent/plugin/compressable.rb +92 -0
  132. data/lib/fluent/plugin/exec_util.rb +3 -108
  133. data/lib/fluent/plugin/file_util.rb +4 -34
  134. data/lib/fluent/plugin/file_wrapper.rb +120 -0
  135. data/lib/fluent/plugin/filter.rb +93 -0
  136. data/lib/fluent/plugin/filter_grep.rb +117 -34
  137. data/lib/fluent/plugin/filter_parser.rb +85 -62
  138. data/lib/fluent/plugin/filter_record_transformer.rb +27 -39
  139. data/lib/fluent/plugin/filter_stdout.rb +15 -12
  140. data/lib/fluent/plugin/formatter.rb +50 -0
  141. data/lib/fluent/plugin/formatter_csv.rb +52 -0
  142. data/lib/fluent/plugin/formatter_hash.rb +33 -0
  143. data/lib/fluent/plugin/formatter_json.rb +55 -0
  144. data/lib/fluent/plugin/formatter_ltsv.rb +42 -0
  145. data/lib/fluent/plugin/formatter_msgpack.rb +33 -0
  146. data/lib/fluent/plugin/formatter_out_file.rb +51 -0
  147. data/lib/fluent/plugin/formatter_single_value.rb +34 -0
  148. data/lib/fluent/plugin/formatter_stdout.rb +76 -0
  149. data/lib/fluent/plugin/formatter_tsv.rb +38 -0
  150. data/lib/fluent/plugin/in_debug_agent.rb +17 -6
  151. data/lib/fluent/plugin/in_dummy.rb +47 -20
  152. data/lib/fluent/plugin/in_exec.rb +55 -123
  153. data/lib/fluent/plugin/in_forward.rb +299 -216
  154. data/lib/fluent/plugin/in_gc_stat.rb +14 -36
  155. data/lib/fluent/plugin/in_http.rb +204 -91
  156. data/lib/fluent/plugin/in_monitor_agent.rb +186 -258
  157. data/lib/fluent/plugin/in_object_space.rb +13 -41
  158. data/lib/fluent/plugin/in_syslog.rb +112 -134
  159. data/lib/fluent/plugin/in_tail.rb +408 -745
  160. data/lib/fluent/plugin/in_tcp.rb +66 -9
  161. data/lib/fluent/plugin/in_udp.rb +60 -11
  162. data/lib/fluent/plugin/{in_stream.rb → in_unix.rb} +8 -4
  163. data/lib/fluent/plugin/input.rb +37 -0
  164. data/lib/fluent/plugin/multi_output.rb +158 -0
  165. data/lib/fluent/plugin/out_copy.rb +23 -35
  166. data/lib/fluent/plugin/out_exec.rb +67 -70
  167. data/lib/fluent/plugin/out_exec_filter.rb +204 -271
  168. data/lib/fluent/plugin/out_file.rb +267 -73
  169. data/lib/fluent/plugin/out_forward.rb +854 -325
  170. data/lib/fluent/plugin/out_null.rb +42 -9
  171. data/lib/fluent/plugin/out_relabel.rb +9 -5
  172. data/lib/fluent/plugin/out_roundrobin.rb +18 -37
  173. data/lib/fluent/plugin/out_secondary_file.rb +133 -0
  174. data/lib/fluent/plugin/out_stdout.rb +43 -10
  175. data/lib/fluent/plugin/out_stream.rb +7 -2
  176. data/lib/fluent/plugin/output.rb +1498 -0
  177. data/lib/fluent/plugin/owned_by_mixin.rb +42 -0
  178. data/lib/fluent/plugin/parser.rb +191 -0
  179. data/lib/fluent/plugin/parser_apache.rb +28 -0
  180. data/lib/fluent/plugin/parser_apache2.rb +88 -0
  181. data/lib/fluent/plugin/parser_apache_error.rb +26 -0
  182. data/lib/fluent/plugin/parser_csv.rb +39 -0
  183. data/lib/fluent/plugin/parser_json.rb +94 -0
  184. data/lib/fluent/plugin/parser_ltsv.rb +49 -0
  185. data/lib/fluent/plugin/parser_msgpack.rb +50 -0
  186. data/lib/fluent/plugin/parser_multiline.rb +106 -0
  187. data/lib/fluent/plugin/parser_nginx.rb +28 -0
  188. data/lib/fluent/plugin/parser_none.rb +36 -0
  189. data/lib/fluent/plugin/parser_regexp.rb +68 -0
  190. data/lib/fluent/plugin/parser_syslog.rb +142 -0
  191. data/lib/fluent/plugin/parser_tsv.rb +42 -0
  192. data/lib/fluent/plugin/socket_util.rb +3 -143
  193. data/lib/fluent/plugin/storage.rb +84 -0
  194. data/lib/fluent/plugin/storage_local.rb +164 -0
  195. data/lib/fluent/plugin/string_util.rb +3 -15
  196. data/lib/fluent/plugin.rb +122 -121
  197. data/lib/fluent/plugin_helper/cert_option.rb +178 -0
  198. data/lib/fluent/plugin_helper/child_process.rb +364 -0
  199. data/lib/fluent/plugin_helper/compat_parameters.rb +333 -0
  200. data/lib/fluent/plugin_helper/counter.rb +51 -0
  201. data/lib/fluent/plugin_helper/event_emitter.rb +93 -0
  202. data/lib/fluent/plugin_helper/event_loop.rb +170 -0
  203. data/lib/fluent/plugin_helper/extract.rb +104 -0
  204. data/lib/fluent/plugin_helper/formatter.rb +147 -0
  205. data/lib/fluent/plugin_helper/http_server/app.rb +79 -0
  206. data/lib/fluent/plugin_helper/http_server/compat/server.rb +81 -0
  207. data/lib/fluent/plugin_helper/http_server/compat/webrick_handler.rb +58 -0
  208. data/lib/fluent/plugin_helper/http_server/methods.rb +35 -0
  209. data/lib/fluent/plugin_helper/http_server/request.rb +42 -0
  210. data/lib/fluent/plugin_helper/http_server/router.rb +54 -0
  211. data/lib/fluent/plugin_helper/http_server/server.rb +87 -0
  212. data/lib/fluent/plugin_helper/http_server.rb +76 -0
  213. data/lib/fluent/plugin_helper/inject.rb +151 -0
  214. data/lib/fluent/plugin_helper/parser.rb +147 -0
  215. data/lib/fluent/plugin_helper/record_accessor.rb +210 -0
  216. data/lib/fluent/plugin_helper/retry_state.rb +205 -0
  217. data/lib/fluent/plugin_helper/server.rb +807 -0
  218. data/lib/fluent/plugin_helper/socket.rb +250 -0
  219. data/lib/fluent/plugin_helper/socket_option.rb +80 -0
  220. data/lib/fluent/plugin_helper/storage.rb +349 -0
  221. data/lib/fluent/plugin_helper/thread.rb +179 -0
  222. data/lib/fluent/plugin_helper/timer.rb +92 -0
  223. data/lib/fluent/plugin_helper.rb +73 -0
  224. data/lib/fluent/plugin_id.rb +80 -0
  225. data/lib/fluent/process.rb +3 -489
  226. data/lib/fluent/registry.rb +52 -10
  227. data/lib/fluent/root_agent.rb +204 -42
  228. data/lib/fluent/supervisor.rb +597 -359
  229. data/lib/fluent/system_config.rb +131 -42
  230. data/lib/fluent/test/base.rb +6 -54
  231. data/lib/fluent/test/driver/base.rb +224 -0
  232. data/lib/fluent/test/driver/base_owned.rb +70 -0
  233. data/lib/fluent/test/driver/base_owner.rb +135 -0
  234. data/lib/fluent/test/driver/event_feeder.rb +98 -0
  235. data/lib/fluent/test/driver/filter.rb +57 -0
  236. data/lib/fluent/test/driver/formatter.rb +30 -0
  237. data/lib/fluent/test/driver/input.rb +31 -0
  238. data/lib/fluent/test/driver/multi_output.rb +53 -0
  239. data/lib/fluent/test/driver/output.rb +102 -0
  240. data/lib/fluent/test/driver/parser.rb +30 -0
  241. data/lib/fluent/test/driver/test_event_router.rb +45 -0
  242. data/lib/fluent/test/filter_test.rb +0 -1
  243. data/lib/fluent/test/formatter_test.rb +4 -1
  244. data/lib/fluent/test/helpers.rb +58 -10
  245. data/lib/fluent/test/input_test.rb +27 -19
  246. data/lib/fluent/test/log.rb +79 -0
  247. data/lib/fluent/test/output_test.rb +28 -39
  248. data/lib/fluent/test/parser_test.rb +3 -1
  249. data/lib/fluent/test/startup_shutdown.rb +46 -0
  250. data/lib/fluent/test.rb +33 -1
  251. data/lib/fluent/time.rb +450 -1
  252. data/lib/fluent/timezone.rb +27 -3
  253. data/lib/fluent/{status.rb → unique_id.rb} +15 -24
  254. data/lib/fluent/version.rb +1 -1
  255. data/lib/fluent/winsvc.rb +85 -0
  256. data/templates/new_gem/Gemfile +3 -0
  257. data/templates/new_gem/README.md.erb +43 -0
  258. data/templates/new_gem/Rakefile +13 -0
  259. data/templates/new_gem/fluent-plugin.gemspec.erb +27 -0
  260. data/templates/new_gem/lib/fluent/plugin/filter.rb.erb +14 -0
  261. data/templates/new_gem/lib/fluent/plugin/formatter.rb.erb +14 -0
  262. data/templates/new_gem/lib/fluent/plugin/input.rb.erb +11 -0
  263. data/templates/new_gem/lib/fluent/plugin/output.rb.erb +11 -0
  264. data/templates/new_gem/lib/fluent/plugin/parser.rb.erb +15 -0
  265. data/templates/new_gem/test/helper.rb.erb +8 -0
  266. data/templates/new_gem/test/plugin/test_filter.rb.erb +18 -0
  267. data/templates/new_gem/test/plugin/test_formatter.rb.erb +18 -0
  268. data/templates/new_gem/test/plugin/test_input.rb.erb +18 -0
  269. data/templates/new_gem/test/plugin/test_output.rb.erb +18 -0
  270. data/templates/new_gem/test/plugin/test_parser.rb.erb +18 -0
  271. data/templates/plugin_config_formatter/param.md-compact.erb +25 -0
  272. data/templates/plugin_config_formatter/param.md.erb +34 -0
  273. data/templates/plugin_config_formatter/section.md.erb +12 -0
  274. data/test/command/test_binlog_reader.rb +346 -0
  275. data/test/command/test_ca_generate.rb +70 -0
  276. data/test/command/test_fluentd.rb +901 -0
  277. data/test/command/test_plugin_config_formatter.rb +276 -0
  278. data/test/command/test_plugin_generator.rb +92 -0
  279. data/test/compat/test_calls_super.rb +166 -0
  280. data/test/compat/test_parser.rb +92 -0
  281. data/test/config/test_config_parser.rb +126 -2
  282. data/test/config/test_configurable.rb +946 -187
  283. data/test/config/test_configure_proxy.rb +424 -74
  284. data/test/config/test_dsl.rb +11 -11
  285. data/test/config/test_element.rb +500 -0
  286. data/test/config/test_literal_parser.rb +8 -0
  287. data/test/config/test_plugin_configuration.rb +56 -0
  288. data/test/config/test_section.rb +79 -7
  289. data/test/config/test_system_config.rb +122 -35
  290. data/test/config/test_types.rb +38 -0
  291. data/test/counter/test_client.rb +559 -0
  292. data/test/counter/test_error.rb +44 -0
  293. data/test/counter/test_mutex_hash.rb +179 -0
  294. data/test/counter/test_server.rb +589 -0
  295. data/test/counter/test_store.rb +258 -0
  296. data/test/counter/test_validator.rb +137 -0
  297. data/test/helper.rb +89 -6
  298. data/test/helpers/fuzzy_assert.rb +89 -0
  299. data/test/plugin/test_bare_output.rb +118 -0
  300. data/test/plugin/test_base.rb +115 -0
  301. data/test/plugin/test_buf_file.rb +823 -460
  302. data/test/plugin/test_buf_memory.rb +32 -194
  303. data/test/plugin/test_buffer.rb +1233 -0
  304. data/test/plugin/test_buffer_chunk.rb +198 -0
  305. data/test/plugin/test_buffer_file_chunk.rb +844 -0
  306. data/test/plugin/test_buffer_memory_chunk.rb +338 -0
  307. data/test/plugin/test_compressable.rb +84 -0
  308. data/test/plugin/test_filter.rb +357 -0
  309. data/test/plugin/test_filter_grep.rb +540 -29
  310. data/test/plugin/test_filter_parser.rb +439 -452
  311. data/test/plugin/test_filter_record_transformer.rb +123 -166
  312. data/test/plugin/test_filter_stdout.rb +160 -72
  313. data/test/plugin/test_formatter_csv.rb +111 -0
  314. data/test/plugin/test_formatter_hash.rb +35 -0
  315. data/test/plugin/test_formatter_json.rb +51 -0
  316. data/test/plugin/test_formatter_ltsv.rb +62 -0
  317. data/test/plugin/test_formatter_msgpack.rb +28 -0
  318. data/test/plugin/test_formatter_out_file.rb +95 -0
  319. data/test/plugin/test_formatter_single_value.rb +38 -0
  320. data/test/plugin/test_formatter_tsv.rb +68 -0
  321. data/test/plugin/test_in_debug_agent.rb +24 -1
  322. data/test/plugin/test_in_dummy.rb +111 -18
  323. data/test/plugin/test_in_exec.rb +200 -113
  324. data/test/plugin/test_in_forward.rb +990 -387
  325. data/test/plugin/test_in_gc_stat.rb +10 -8
  326. data/test/plugin/test_in_http.rb +600 -224
  327. data/test/plugin/test_in_monitor_agent.rb +690 -0
  328. data/test/plugin/test_in_object_space.rb +24 -8
  329. data/test/plugin/test_in_syslog.rb +154 -215
  330. data/test/plugin/test_in_tail.rb +1006 -707
  331. data/test/plugin/test_in_tcp.rb +125 -48
  332. data/test/plugin/test_in_udp.rb +204 -63
  333. data/test/plugin/{test_in_stream.rb → test_in_unix.rb} +14 -13
  334. data/test/plugin/test_input.rb +126 -0
  335. data/test/plugin/test_metadata.rb +89 -0
  336. data/test/plugin/test_multi_output.rb +180 -0
  337. data/test/plugin/test_out_copy.rb +117 -112
  338. data/test/plugin/test_out_exec.rb +258 -53
  339. data/test/plugin/test_out_exec_filter.rb +538 -115
  340. data/test/plugin/test_out_file.rb +865 -178
  341. data/test/plugin/test_out_forward.rb +998 -210
  342. data/test/plugin/test_out_null.rb +105 -0
  343. data/test/plugin/test_out_relabel.rb +28 -0
  344. data/test/plugin/test_out_roundrobin.rb +36 -29
  345. data/test/plugin/test_out_secondary_file.rb +458 -0
  346. data/test/plugin/test_out_stdout.rb +135 -37
  347. data/test/plugin/test_out_stream.rb +18 -0
  348. data/test/plugin/test_output.rb +984 -0
  349. data/test/plugin/test_output_as_buffered.rb +2021 -0
  350. data/test/plugin/test_output_as_buffered_backup.rb +312 -0
  351. data/test/plugin/test_output_as_buffered_compress.rb +165 -0
  352. data/test/plugin/test_output_as_buffered_overflow.rb +250 -0
  353. data/test/plugin/test_output_as_buffered_retries.rb +911 -0
  354. data/test/plugin/test_output_as_buffered_secondary.rb +874 -0
  355. data/test/plugin/test_output_as_standard.rb +374 -0
  356. data/test/plugin/test_owned_by.rb +35 -0
  357. data/test/plugin/test_parser.rb +359 -0
  358. data/test/plugin/test_parser_apache.rb +42 -0
  359. data/test/plugin/test_parser_apache2.rb +47 -0
  360. data/test/plugin/test_parser_apache_error.rb +45 -0
  361. data/test/plugin/test_parser_csv.rb +103 -0
  362. data/test/plugin/test_parser_json.rb +138 -0
  363. data/test/plugin/test_parser_labeled_tsv.rb +145 -0
  364. data/test/plugin/test_parser_multiline.rb +100 -0
  365. data/test/plugin/test_parser_nginx.rb +88 -0
  366. data/test/plugin/test_parser_none.rb +52 -0
  367. data/test/plugin/test_parser_regexp.rb +289 -0
  368. data/test/plugin/test_parser_syslog.rb +441 -0
  369. data/test/plugin/test_parser_tsv.rb +122 -0
  370. data/test/plugin/test_storage.rb +167 -0
  371. data/test/plugin/test_storage_local.rb +335 -0
  372. data/test/plugin_helper/data/cert/cert-key.pem +27 -0
  373. data/test/plugin_helper/data/cert/cert-with-no-newline.pem +19 -0
  374. data/test/plugin_helper/data/cert/cert.pem +19 -0
  375. data/test/plugin_helper/http_server/test_app.rb +65 -0
  376. data/test/plugin_helper/http_server/test_route.rb +32 -0
  377. data/test/plugin_helper/test_cert_option.rb +16 -0
  378. data/test/plugin_helper/test_child_process.rb +794 -0
  379. data/test/plugin_helper/test_compat_parameters.rb +353 -0
  380. data/test/plugin_helper/test_event_emitter.rb +51 -0
  381. data/test/plugin_helper/test_event_loop.rb +52 -0
  382. data/test/plugin_helper/test_extract.rb +194 -0
  383. data/test/plugin_helper/test_formatter.rb +255 -0
  384. data/test/plugin_helper/test_http_server_helper.rb +205 -0
  385. data/test/plugin_helper/test_inject.rb +519 -0
  386. data/test/plugin_helper/test_parser.rb +264 -0
  387. data/test/plugin_helper/test_record_accessor.rb +197 -0
  388. data/test/plugin_helper/test_retry_state.rb +442 -0
  389. data/test/plugin_helper/test_server.rb +1714 -0
  390. data/test/plugin_helper/test_storage.rb +542 -0
  391. data/test/plugin_helper/test_thread.rb +164 -0
  392. data/test/plugin_helper/test_timer.rb +132 -0
  393. data/test/scripts/exec_script.rb +0 -6
  394. data/test/scripts/fluent/plugin/formatter1/formatter_test1.rb +7 -0
  395. data/test/scripts/fluent/plugin/formatter2/formatter_test2.rb +7 -0
  396. data/test/scripts/fluent/plugin/out_test.rb +23 -15
  397. data/test/scripts/fluent/plugin/out_test2.rb +80 -0
  398. data/test/test_clock.rb +164 -0
  399. data/test/test_config.rb +16 -7
  400. data/test/test_configdsl.rb +2 -2
  401. data/test/test_event.rb +360 -13
  402. data/test/test_event_router.rb +108 -11
  403. data/test/test_event_time.rb +199 -0
  404. data/test/test_filter.rb +48 -6
  405. data/test/test_formatter.rb +11 -391
  406. data/test/test_input.rb +1 -1
  407. data/test/test_log.rb +591 -31
  408. data/test/test_mixin.rb +1 -1
  409. data/test/test_output.rb +121 -185
  410. data/test/test_plugin.rb +251 -0
  411. data/test/test_plugin_classes.rb +177 -10
  412. data/test/test_plugin_helper.rb +81 -0
  413. data/test/test_plugin_id.rb +101 -0
  414. data/test/test_process.rb +8 -42
  415. data/test/test_root_agent.rb +766 -21
  416. data/test/test_supervisor.rb +481 -0
  417. data/test/test_test_drivers.rb +135 -0
  418. data/test/test_time_formatter.rb +282 -0
  419. data/test/test_time_parser.rb +231 -0
  420. data/test/test_unique_id.rb +47 -0
  421. metadata +454 -60
  422. data/COPYING +0 -14
  423. data/ChangeLog +0 -666
  424. data/lib/fluent/buffer.rb +0 -365
  425. data/lib/fluent/plugin/in_status.rb +0 -76
  426. data/test/plugin/test_in_status.rb +0 -38
  427. data/test/test_buffer.rb +0 -624
  428. data/test/test_parser.rb +0 -1305
@@ -24,6 +24,12 @@ module ConfigurableSpec
24
24
  end
25
25
  end
26
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
+
27
33
  class Base2 < Base1
28
34
  config_set_default :name2, "base2"
29
35
  config_set_default :name4, "base2"
@@ -89,6 +95,50 @@ module ConfigurableSpec
89
95
  end
90
96
  end
91
97
 
98
+ class Base4Safe < Base4
99
+ # config_section :node, param_name: :nodes do
100
+ # config_argument :num, :integer
101
+ # config_param :name, :string, default: "node"
102
+ # config_param :type, :string, default: "b4"
103
+ # end
104
+ # config_section :description1, required: false, multi: false do
105
+ # config_argument :note, :string, default: "desc1"
106
+ # config_param :text, :string
107
+ # end
108
+ # config_section :description2, required: true, multi: false do
109
+ # config_argument :note, :string, default: "desc2"
110
+ # config_param :text, :string
111
+ # end
112
+ # config_section :description3, required: true, multi: true do
113
+ # config_argument :note, default: "desc3" do |val|
114
+ # "desc3: #{val}"
115
+ # end
116
+ # config_param :text, :string
117
+ # end
118
+ config_section :node do
119
+ config_set_default :num, 0
120
+ end
121
+ config_section :description1 do
122
+ config_set_default :text, "teeeext"
123
+ end
124
+ config_section :description2 do
125
+ config_set_default :text, nil
126
+ end
127
+ config_section :description3 do
128
+ config_set_default :text, "yay"
129
+ end
130
+ end
131
+
132
+ class Init0
133
+ include Fluent::Configurable
134
+ config_section :sec1, init: true, multi: false do
135
+ config_param :name, :string, default: 'sec1'
136
+ end
137
+ config_section :sec2, init: true, multi: true do
138
+ config_param :name, :string, default: 'sec1'
139
+ end
140
+ end
141
+
92
142
  class Example0
93
143
  include Fluent::Configurable
94
144
 
@@ -116,13 +166,6 @@ module ConfigurableSpec
116
166
  end
117
167
  end
118
168
 
119
- class Example2 < Example1
120
- config_section :detail, required: true, multi: false, alias: "information2" do
121
- config_param :address, :string, default: "y"
122
- config_param :phone_no, :string
123
- end
124
- end
125
-
126
169
  class Example3
127
170
  include Fluent::Configurable
128
171
 
@@ -138,15 +181,6 @@ module ConfigurableSpec
138
181
  end
139
182
  end
140
183
 
141
- class Example4 < Example3
142
- config_param :age, :integer, default: 20
143
-
144
- config_section :appendix, required: false, multi: false, final: false do
145
- config_param :name, :string, default: "y"
146
- config_param :age, :integer, default: 10
147
- end
148
- end
149
-
150
184
  class Example5
151
185
  include Fluent::Configurable
152
186
 
@@ -159,6 +193,219 @@ module ConfigurableSpec
159
193
  end
160
194
  end
161
195
 
196
+ class Example6
197
+ include Fluent::Configurable
198
+ config_param :obj1, :hash, default: {}
199
+ config_param :obj2, :array, default: []
200
+ end
201
+
202
+ class Example7
203
+ include Fluent::Configurable
204
+ config_param :name, :string, default: 'example7', skip_accessor: true
205
+ end
206
+
207
+ module Overwrite
208
+ class Base
209
+ include Fluent::Configurable
210
+
211
+ config_param :name, :string, alias: :fullname
212
+ config_param :bool, :bool, alias: :flag
213
+ config_section :detail, required: false, multi: false, alias: "information" do
214
+ config_param :address, :string, default: "x"
215
+ end
216
+ end
217
+
218
+ class Required < Base
219
+ config_section :detail, required: true do
220
+ config_param :address, :string, default: "x"
221
+ end
222
+ end
223
+
224
+ class Multi < Base
225
+ config_section :detail, multi: true do
226
+ config_param :address, :string, default: "x"
227
+ end
228
+ end
229
+
230
+ class Alias < Base
231
+ config_section :detail, alias: "information2" do
232
+ config_param :address, :string, default: "x"
233
+ end
234
+ end
235
+
236
+ class DefaultOptions < Base
237
+ config_section :detail do
238
+ config_param :address, :string, default: "x"
239
+ end
240
+ end
241
+
242
+ class DetailAddressDefault < Base
243
+ config_section :detail do
244
+ config_param :address, :string, default: "y"
245
+ end
246
+ end
247
+
248
+ class AddParam < Base
249
+ config_section :detail do
250
+ config_param :phone_no, :string
251
+ end
252
+ end
253
+
254
+ class AddParamOverwriteAddress < Base
255
+ config_section :detail do
256
+ config_param :address, :string, default: "y"
257
+ config_param :phone_no, :string
258
+ end
259
+ end
260
+ end
261
+
262
+ module Final
263
+ # Show what is allowed in finalized sections
264
+ # InheritsFinalized < Finalized < Base
265
+ class Base
266
+ include Fluent::Configurable
267
+ config_section :appendix, multi: false, final: false do
268
+ config_param :code, :string
269
+ config_param :name, :string
270
+ config_param :address, :string, default: ""
271
+ end
272
+ end
273
+
274
+ class Finalized < Base
275
+ # to non-finalized section
276
+ # subclass can change type (code)
277
+ # add default value (name)
278
+ # change default value (address)
279
+ # add field (age)
280
+ config_section :appendix, final: true do
281
+ config_param :code, :integer
282
+ config_set_default :name, "y"
283
+ config_set_default :address, "-"
284
+ config_param :age, :integer, default: 10
285
+ end
286
+ end
287
+
288
+ class InheritsFinalized < Finalized
289
+ # to finalized section
290
+ # subclass can add default value (code)
291
+ # change default value (age)
292
+ # add field (phone_no)
293
+ config_section :appendix do
294
+ config_set_default :code, 2
295
+ config_set_default :age, 0
296
+ config_param :phone_no, :string
297
+ end
298
+ end
299
+
300
+ # Show what is allowed/prohibited for finalized sections
301
+ class FinalizedBase
302
+ include Fluent::Configurable
303
+ config_section :appendix, param_name: :apd, init: false, required: true, multi: false, alias: "options", final: true do
304
+ config_param :name, :string
305
+ end
306
+ end
307
+
308
+ class FinalizedBase2
309
+ include Fluent::Configurable
310
+ config_section :appendix, param_name: :apd, init: false, required: false, multi: false, alias: "options", final: true do
311
+ config_param :name, :string
312
+ end
313
+ end
314
+
315
+ # subclass can change init with adding default values
316
+ class OverwriteInit < FinalizedBase2
317
+ config_section :appendix, init: true do
318
+ config_set_default :name, "moris"
319
+ config_param :code, :integer, default: 0
320
+ end
321
+ end
322
+
323
+ # subclass cannot change type (name)
324
+ class Subclass < FinalizedBase
325
+ config_section :appendix do
326
+ config_param :name, :integer
327
+ end
328
+ end
329
+
330
+ # subclass cannot change param_name
331
+ class OverwriteParamName < FinalizedBase
332
+ config_section :appendix, param_name: :adx do
333
+ end
334
+ end
335
+
336
+ # subclass cannot change final (section)
337
+ class OverwriteFinal < FinalizedBase
338
+ config_section :appendix, final: false do
339
+ config_param :name, :integer
340
+ end
341
+ end
342
+
343
+ # subclass cannot change required
344
+ class OverwriteRequired < FinalizedBase
345
+ config_section :appendix, required: false do
346
+ end
347
+ end
348
+
349
+ # subclass cannot change multi
350
+ class OverwriteMulti < FinalizedBase
351
+ config_section :appendix, multi: true do
352
+ end
353
+ end
354
+
355
+ # subclass cannot change alias
356
+ class OverwriteAlias < FinalizedBase
357
+ config_section :appendix, alias: "options2" do
358
+ end
359
+ end
360
+ end
361
+
362
+ module OverwriteDefaults
363
+ class Owner
364
+ include Fluent::Configurable
365
+ config_set_default :key1, "V1"
366
+ config_section :buffer do
367
+ config_set_default :size_of_something, 1024
368
+ end
369
+ end
370
+
371
+ class SubOwner < Owner
372
+ config_section :buffer do
373
+ config_set_default :size_of_something, 2048
374
+ end
375
+ end
376
+
377
+ class NilOwner < Owner
378
+ config_section :buffer do
379
+ config_set_default :size_of_something, nil
380
+ end
381
+ end
382
+
383
+ class FlatChild
384
+ include Fluent::Configurable
385
+ attr_accessor :owner
386
+ config_param :key1, :string, default: "v1"
387
+ end
388
+
389
+ class BufferChild
390
+ include Fluent::Configurable
391
+ attr_accessor :owner
392
+ configured_in :buffer
393
+ config_param :size_of_something, :size, default: 128
394
+ end
395
+
396
+ class BufferBase
397
+ include Fluent::Configurable
398
+ end
399
+
400
+ class BufferSubclass < BufferBase
401
+ attr_accessor :owner
402
+ configured_in :buffer
403
+ config_param :size_of_something, :size, default: 512
404
+ end
405
+
406
+ class BufferSubSubclass < BufferSubclass
407
+ end
408
+ end
162
409
  class UnRecommended
163
410
  include Fluent::Configurable
164
411
  attr_accessor :log
@@ -200,23 +447,79 @@ module Fluent::Config
200
447
  end
201
448
  end
202
449
 
203
- sub_test_case '#configure' do
204
- def e(attrs)
205
- Fluent::Config::Element.new('', '', attrs, [])
450
+ sub_test_case '#configured_section_create' do
451
+ test 'raises configuration error if required param exists but no configuration element is specified' do
452
+ obj = ConfigurableSpec::Base1.new
453
+ assert_raise(Fluent::ConfigError.new("'name1' parameter is required")) do
454
+ obj.configured_section_create(nil)
455
+ end
456
+ end
457
+
458
+ test 'creates root section with default values if name and config are specified with nil' do
459
+ obj = ConfigurableSpec::Base1Safe.new
460
+ root = obj.configured_section_create(nil)
461
+
462
+ assert_equal "node", root.node
463
+ assert_false root.flag1
464
+ assert_true root.flag2
465
+ assert_equal "basex1", root.name1
466
+ assert_equal "basex2", root.name2
467
+ assert_equal "base1", root.name3
468
+ assert_equal "base1", root.name4
469
+ assert_equal :baz, root.opt1
470
+ assert_equal :foo, root.opt2
206
471
  end
207
472
 
473
+ test 'creates root section with default values if name is nil and config is empty element' do
474
+ obj = ConfigurableSpec::Base1Safe.new
475
+ root = obj.configured_section_create(nil, config_element())
476
+
477
+ assert_equal "node", root.node
478
+ assert_false root.flag1
479
+ assert_true root.flag2
480
+ assert_equal "basex1", root.name1
481
+ assert_equal "basex2", root.name2
482
+ assert_equal "base1", root.name3
483
+ assert_equal "base1", root.name4
484
+ assert_equal :baz, root.opt1
485
+ assert_equal :foo, root.opt2
486
+ end
487
+
488
+ test 'creates root section with specified value if name is nil and configuration element is specified' do
489
+ obj = ConfigurableSpec::Base1Safe.new
490
+ root = obj.configured_section_create(nil, config_element('match', '', {'node' => "nodename", 'flag1' => 'true', 'name1' => 'fixed1', 'opt1' => 'foo'}))
491
+
492
+ assert_equal "nodename", root.node
493
+ assert_equal "fixed1", root.name1
494
+ assert_true root.flag1
495
+ assert_equal :foo, root.opt1
496
+
497
+ assert_true root.flag2
498
+ assert_equal "basex2", root.name2
499
+ assert_equal "base1", root.name3
500
+ assert_equal "base1", root.name4
501
+ assert_equal :foo, root.opt2
502
+ end
503
+ end
504
+
505
+ sub_test_case '#configure' do
208
506
  test 'returns configurable object itself' do
209
507
  b2 = ConfigurableSpec::Base2.new
210
- assert_instance_of(ConfigurableSpec::Base2, b2.configure(e({"name1" => "t1", "name5" => "t5", "opt3" => "a"})))
508
+ assert_instance_of(ConfigurableSpec::Base2, b2.configure(config_element("", "", {"name1" => "t1", "name5" => "t5", "opt3" => "a"})))
509
+ end
510
+
511
+ test 'can accept frozen string' do
512
+ b2 = ConfigurableSpec::Base2.new
513
+ assert_instance_of(ConfigurableSpec::Base2, b2.configure(config_element("", "", {"name1" => "t1".freeze, "name5" => "t5", "opt3" => "a"})))
211
514
  end
212
515
 
213
516
  test 'raise errors without any specifications for param without defaults' do
214
517
  b2 = ConfigurableSpec::Base2.new
215
- assert_raise(Fluent::ConfigError) { b2.configure(e({})) }
216
- assert_raise(Fluent::ConfigError) { b2.configure(e({"name1" => "t1"})) }
217
- assert_raise(Fluent::ConfigError) { b2.configure(e({"name5" => "t5"})) }
218
- assert_raise(Fluent::ConfigError) { b2.configure(e({"name1" => "t1", "name5" => "t5"})) }
219
- assert_nothing_raised { b2.configure(e({"name1" => "t1", "name5" => "t5", "opt3" => "a"})) }
518
+ assert_raise(Fluent::ConfigError) { b2.configure(config_element("", "", {})) }
519
+ assert_raise(Fluent::ConfigError) { b2.configure(config_element("", "", {"name1" => "t1"})) }
520
+ assert_raise(Fluent::ConfigError) { b2.configure(config_element("", "", {"name5" => "t5"})) }
521
+ assert_raise(Fluent::ConfigError) { b2.configure(config_element("", "", {"name1" => "t1", "name5" => "t5"})) }
522
+ assert_nothing_raised { b2.configure(config_element("", "", {"name1" => "t1", "name5" => "t5", "opt3" => "a"})) }
220
523
 
221
524
  assert_equal(["node", false, true, "t1", "base2", "base1", "base2", "t5", "base2"], b2.get_all)
222
525
  assert_equal(:a, b2.opt3)
@@ -224,19 +527,19 @@ module Fluent::Config
224
527
 
225
528
  test 'can configure bool values' do
226
529
  b2a = ConfigurableSpec::Base2.new
227
- assert_nothing_raised { b2a.configure(e({"flag1" => "true", "flag2" => "yes", "name1" => "t1", "name5" => "t5", "opt3" => "a"})) }
530
+ assert_nothing_raised { b2a.configure(config_element("", "", {"flag1" => "true", "flag2" => "yes", "name1" => "t1", "name5" => "t5", "opt3" => "a"})) }
228
531
  assert_true(b2a.flag1)
229
532
  assert_true(b2a.flag2)
230
533
 
231
534
  b2b = ConfigurableSpec::Base2.new
232
- assert_nothing_raised { b2b.configure(e({"flag1" => false, "flag2" => "no", "name1" => "t1", "name5" => "t5", "opt3" => "a"})) }
535
+ assert_nothing_raised { b2b.configure(config_element("", "", {"flag1" => false, "flag2" => "no", "name1" => "t1", "name5" => "t5", "opt3" => "a"})) }
233
536
  assert_false(b2b.flag1)
234
537
  assert_false(b2b.flag2)
235
538
  end
236
539
 
237
540
  test 'overwrites values of defaults' do
238
541
  b2 = ConfigurableSpec::Base2.new
239
- b2.configure(e({"name1" => "t1", "name2" => "t2", "name3" => "t3", "name4" => "t4", "name5" => "t5", "opt1" => "foo", "opt3" => "b"}))
542
+ b2.configure(config_element("", "", {"name1" => "t1", "name2" => "t2", "name3" => "t3", "name4" => "t4", "name5" => "t5", "opt1" => "foo", "opt3" => "b"}))
240
543
  assert_equal("t1", b2.name1)
241
544
  assert_equal("t2", b2.name2)
242
545
  assert_equal("t3", b2.name3)
@@ -250,7 +553,7 @@ module Fluent::Config
250
553
  end
251
554
 
252
555
  test 'enum type rejects values which does not exist in list' do
253
- default = e({"name1" => "t1", "name2" => "t2", "name3" => "t3", "name4" => "t4", "name5" => "t5", "opt1" => "foo", "opt3" => "b"})
556
+ default = config_element("", "", {"name1" => "t1", "name2" => "t2", "name3" => "t3", "name4" => "t4", "name5" => "t5", "opt1" => "foo", "opt3" => "b"})
254
557
 
255
558
  b2 = ConfigurableSpec::Base2.new
256
559
  assert_nothing_raised { b2.configure(default) }
@@ -258,6 +561,37 @@ module Fluent::Config
258
561
  assert_raise(Fluent::ConfigError) { b2.configure(default.merge({"opt2" => "fooooooo"})) }
259
562
  assert_raise(Fluent::ConfigError) { b2.configure(default.merge({"opt3" => "c"})) }
260
563
  end
564
+
565
+ sub_test_case 'default values should be duplicated before touched in plugin code' do
566
+ test 'default object should be dupped for cases configured twice' do
567
+ x6a = ConfigurableSpec::Example6.new
568
+ assert_nothing_raised { x6a.configure(config_element("")) }
569
+ assert_equal({}, x6a.obj1)
570
+ assert_equal([], x6a.obj2)
571
+
572
+ x6b = ConfigurableSpec::Example6.new
573
+ assert_nothing_raised { x6b.configure(config_element("")) }
574
+ assert_equal({}, x6b.obj1)
575
+ assert_equal([], x6b.obj2)
576
+
577
+ assert { x6a.obj1.object_id != x6b.obj1.object_id }
578
+ assert { x6a.obj2.object_id != x6b.obj2.object_id }
579
+
580
+ x6c = ConfigurableSpec::Example6.new
581
+ assert_nothing_raised { x6c.configure(config_element("")) }
582
+ assert_equal({}, x6c.obj1)
583
+ assert_equal([], x6c.obj2)
584
+
585
+ x6c.obj1['k'] = 'v'
586
+ x6c.obj2 << 'v'
587
+
588
+ assert_equal({'k' => 'v'}, x6c.obj1)
589
+ assert_equal(['v'], x6c.obj2)
590
+
591
+ assert_equal({}, x6a.obj1)
592
+ assert_equal([], x6a.obj2)
593
+ end
594
+ end
261
595
  end
262
596
  end
263
597
 
@@ -292,13 +626,66 @@ module Fluent::Config
292
626
  end
293
627
  end
294
628
 
295
- sub_test_case '#configure' do
296
- def e(name, arg = '', attrs = {}, elements = [])
297
- attrs_str_keys = {}
298
- attrs.each{|key, value| attrs_str_keys[key.to_s] = value }
299
- config_element(name, arg, attrs_str_keys, elements)
629
+ sub_test_case '#configured_section_create' do
630
+ test 'raises configuration error if required param exists but no configuration element is specified' do
631
+ obj = ConfigurableSpec::Base4.new
632
+ assert_raise(Fluent::ConfigError.new("'<node ARG>' section requires argument")) do
633
+ obj.configured_section_create(:node)
634
+ end
635
+ assert_raise(Fluent::ConfigError.new("'text' parameter is required")) do
636
+ obj.configured_section_create(:description1)
637
+ end
638
+ end
639
+
640
+ test 'creates any defined section with default values if name is nil and config is not specified' do
641
+ obj = ConfigurableSpec::Base4Safe.new
642
+ node = obj.configured_section_create(:node)
643
+ assert_equal 0, node.num
644
+ assert_equal "node", node.name
645
+ assert_equal "b4", node.type
646
+
647
+ desc1 = obj.configured_section_create(:description1)
648
+ assert_equal "desc1", desc1.note
649
+ assert_equal "teeeext", desc1.text
650
+ end
651
+
652
+ test 'creates any defined section with default values if name is nil and config is empty element' do
653
+ obj = ConfigurableSpec::Base4Safe.new
654
+ node = obj.configured_section_create(:node, config_element())
655
+ assert_equal 0, node.num
656
+ assert_equal "node", node.name
657
+ assert_equal "b4", node.type
658
+
659
+ desc1 = obj.configured_section_create(:description1, config_element())
660
+ assert_equal "desc1", desc1.note
661
+ assert_equal "teeeext", desc1.text
300
662
  end
301
663
 
664
+ test 'creates any defined section with specified value if name is nil and configuration element is specified' do
665
+ obj = ConfigurableSpec::Base4Safe.new
666
+ node = obj.configured_section_create(:node, config_element('node', '1', {'name' => 'node1', 'type' => 'b1'}))
667
+ assert_equal 1, node.num
668
+ assert_equal "node1", node.name
669
+ assert_equal "b1", node.type
670
+
671
+ desc1 = obj.configured_section_create(:description1, config_element('description1', 'desc one', {'text' => 't'}))
672
+ assert_equal "desc one", desc1.note
673
+ assert_equal "t", desc1.text
674
+ end
675
+
676
+ test 'creates a defined section instance even if it is defined as multi:true' do
677
+ obj = ConfigurableSpec::Base4Safe.new
678
+ desc3 = obj.configured_section_create(:description3)
679
+ assert_equal "desc3", desc3.note
680
+ assert_equal "yay", desc3.text
681
+
682
+ desc3 = obj.configured_section_create(:description3, config_element('description3', 'foo'))
683
+ assert_equal "desc3: foo", desc3.note
684
+ assert_equal "yay", desc3.text
685
+ end
686
+ end
687
+
688
+ sub_test_case '#configure' do
302
689
  BASE_ATTRS = {
303
690
  "name1" => "1", "name2" => "2", "name3" => "3",
304
691
  "name4" => "4", "name5" => "5", "name6" => "6",
@@ -306,68 +693,68 @@ module Fluent::Config
306
693
  test 'checks required subsections' do
307
694
  b3 = ConfigurableSpec::Base3.new
308
695
  # branch sections required
309
- assert_raise(Fluent::ConfigError) { b3.configure(e('ROOT', '', BASE_ATTRS, [])) }
696
+ assert_raise(Fluent::ConfigError) { b3.configure(config_element('ROOT', '', BASE_ATTRS, [])) }
310
697
 
311
698
  # branch argument required
312
699
  msg = "'<branch ARG>' section requires argument, in section branch"
313
700
  #expect{ b3.configure(e('ROOT', '', BASE_ATTRS, [e('branch', '')])) }.to raise_error(Fluent::ConfigError, msg)
314
- assert_raise(Fluent::ConfigError.new(msg)) { b3.configure(e('ROOT', '', BASE_ATTRS, [e('branch', '')])) }
701
+ assert_raise(Fluent::ConfigError.new(msg)) { b3.configure(config_element('ROOT', '', BASE_ATTRS, [config_element('branch', '')])) }
315
702
 
316
703
  # leaf is not required
317
- assert_nothing_raised { b3.configure(e('ROOT', '', BASE_ATTRS, [e('branch', 'branch_name')])) }
704
+ assert_nothing_raised { b3.configure(config_element('ROOT', '', BASE_ATTRS, [config_element('branch', 'branch_name')])) }
318
705
 
319
706
  # leaf weight required
320
707
  msg = "'weight' parameter is required, in section branch > leaf"
321
- branch1 = e('branch', 'branch_name', {size: 1}, [e('leaf', '10', {weight: 1})])
322
- assert_nothing_raised { b3.configure(e('ROOT', '', BASE_ATTRS, [branch1])) }
323
- branch2 = e('branch', 'branch_name', {size: 1}, [e('leaf', '20')])
324
- assert_raise(Fluent::ConfigError.new(msg)) { b3.configure(e('ROOT', '', BASE_ATTRS, [branch1, branch2])) }
325
- branch3 = e('branch', 'branch_name', {size: 1}, [e('leaf', '10', {weight: 3}), e('leaf', '20')])
326
- assert_raise(Fluent::ConfigError.new(msg)) { b3.configure(e('ROOT', '', BASE_ATTRS, [branch3])) }
708
+ branch1 = config_element('branch', 'branch_name', {size: 1}, [config_element('leaf', '10', {"weight" => 1})])
709
+ assert_nothing_raised { b3.configure(config_element('ROOT', '', BASE_ATTRS, [branch1])) }
710
+ branch2 = config_element('branch', 'branch_name', {size: 1}, [config_element('leaf', '20')])
711
+ assert_raise(Fluent::ConfigError.new(msg)) { b3.configure(config_element('ROOT', '', BASE_ATTRS, [branch1, branch2])) }
712
+ branch3 = config_element('branch', 'branch_name', {size: 1}, [config_element('leaf', '10', {"weight" => 3}), config_element('leaf', '20')])
713
+ assert_raise(Fluent::ConfigError.new(msg)) { b3.configure(config_element('ROOT', '', BASE_ATTRS, [branch3])) }
327
714
 
328
715
  ### worm not required
329
716
 
330
717
  b4 = ConfigurableSpec::Base4.new
331
718
 
332
- d1 = e('description1', '', {text:"d1"})
333
- d2 = e('description2', '', {text:"d2"})
334
- d3 = e('description3', '', {text:"d3"})
335
- assert_nothing_raised { b4.configure(e('ROOT', '', BASE_ATTRS, [d1.dup, d2.dup, d3.dup])) }
719
+ d1 = config_element('description1', '', {"text" => "d1"})
720
+ d2 = config_element('description2', '', {"text" => "d2"})
721
+ d3 = config_element('description3', '', {"text" => "d3"})
722
+ assert_nothing_raised { b4.configure(config_element('ROOT', '', BASE_ATTRS, [d1.dup, d2.dup, d3.dup])) }
336
723
 
337
724
  # description1 cannot be specified 2 or more
338
725
  msg = "'<description1>' section cannot be written twice or more"
339
- assert_raise(Fluent::ConfigError.new(msg)) { b4.configure(e('ROOT', '', BASE_ATTRS, [d1.dup, d2.dup, d1.dup, d3.dup])) }
726
+ assert_raise(Fluent::ConfigError.new(msg)) { b4.configure(config_element('ROOT', '', BASE_ATTRS, [d1.dup, d2.dup, d1.dup, d3.dup])) }
340
727
 
341
728
  # description2 cannot be specified 2 or more
342
729
  msg = "'<description2>' section cannot be written twice or more"
343
- assert_raise(Fluent::ConfigError.new(msg)) { b4.configure(e('ROOT', '', BASE_ATTRS, [d1.dup, d2.dup, d3.dup, d2.dup])) }
730
+ assert_raise(Fluent::ConfigError.new(msg)) { b4.configure(config_element('ROOT', '', BASE_ATTRS, [d1.dup, d2.dup, d3.dup, d2.dup])) }
344
731
 
345
732
  # description3 can be specified 2 or more
346
- assert_nothing_raised { b4.configure(e('ROOT', '', BASE_ATTRS, [d1.dup, d2.dup, d3.dup, d3.dup])) }
733
+ assert_nothing_raised { b4.configure(config_element('ROOT', '', BASE_ATTRS, [d1.dup, d2.dup, d3.dup, d3.dup])) }
347
734
  end
348
735
 
349
- test 'constructs confuguration object tree for Base3' do
350
- conf = e(
736
+ test 'constructs configuration object tree for Base3' do
737
+ conf = config_element(
351
738
  'ROOT',
352
739
  '',
353
740
  BASE_ATTRS,
354
741
  [
355
- e('node', '', {type:"1"}), e('node', '', {name:"node2",type:"2"}),
356
- e('branch', 'b1.*', {}, []),
357
- e('branch',
742
+ config_element('node', '', {"type" => "1"}), config_element('node', '', {"name" => "node2","type" => "2"}),
743
+ config_element('branch', 'b1.*', {}, []),
744
+ config_element('branch',
358
745
  'b2.*',
359
- {size: 5},
746
+ {"size" => 5},
360
747
  [
361
- e('leaf', 'THIS IS IGNORED', {weight: 55}, []),
362
- e('leaf', 'THIS IS IGNORED', {weight: 50}, [ e('worm', '', {}) ]),
363
- e('leaf', 'THIS IS IGNORED', {weight: 50}, [ e('worm', '', {type:"w1"}), e('worm', '', {type:"w2"}) ]),
748
+ config_element('leaf', 'THIS IS IGNORED', {"weight" => 55}, []),
749
+ config_element('leaf', 'THIS IS IGNORED', {"weight" => 50}, [ config_element('worm', '', {}) ]),
750
+ config_element('leaf', 'THIS IS IGNORED', {"weight" => 50}, [ config_element('worm', '', {"type" => "w1"}), config_element('worm', '', {"type" => "w2"}) ]),
364
751
  ]
365
752
  ),
366
- e('branch',
753
+ config_element('branch',
367
754
  'b3.*',
368
- {size: "503"},
755
+ {"size" => "503"},
369
756
  [
370
- e('leaf', 'THIS IS IGNORED', {weight: 55}, []),
757
+ config_element('leaf', 'THIS IS IGNORED', {"weight" => 55}, []),
371
758
  ]
372
759
  )
373
760
  ],
@@ -424,18 +811,18 @@ module Fluent::Config
424
811
  end
425
812
 
426
813
  test 'constructs confuguration object tree for Base4' do
427
- conf = e(
814
+ conf = config_element(
428
815
  'ROOT',
429
816
  '',
430
817
  BASE_ATTRS,
431
818
  [
432
- e('node', '1', {type:"1"}), e('node', '2', {name:"node2"}),
433
- e('description3', '', {text:"dddd3-1"}),
434
- e('description2', 'd-2', {text:"dddd2"}),
435
- e('description1', '', {text:"dddd1"}),
436
- e('description3', 'd-3', {text:"dddd3-2"}),
437
- e('description3', 'd-3a', {text:"dddd3-3"}),
438
- e('node', '4', {type:"four"}),
819
+ config_element('node', '1', {"type" => "1"}), config_element('node', '2', {"name" => "node2"}),
820
+ config_element('description3', '', {"text" => "dddd3-1"}),
821
+ config_element('description2', 'd-2', {"text" => "dddd2"}),
822
+ config_element('description1', '', {"text" => "dddd1"}),
823
+ config_element('description3', 'd-3', {"text" => "dddd3-2"}),
824
+ config_element('description3', 'd-3a', {"text" => "dddd3-3"}),
825
+ config_element('node', '4', {"type" => "four"}),
439
826
  ],
440
827
  )
441
828
  b4 = ConfigurableSpec::Base4.new.configure(conf)
@@ -461,9 +848,9 @@ module Fluent::Config
461
848
  assert_equal("node", b4.nodes[2].name)
462
849
  assert_equal("four", b4.nodes[2].type)
463
850
 
464
- # e('description3', '', {text:"dddd3-1"}),
465
- # e('description3', 'd-3', {text:"dddd3-2"}),
466
- # e('description3', 'd-3a', {text:"dddd3-3"}),
851
+ # config_element('description3', '', {"text" => "dddd3-1"}),
852
+ # config_element('description3', 'd-3', {"text" => "dddd3-2"}),
853
+ # config_element('description3', 'd-3a', {"text" => "dddd3-3"}),
467
854
 
468
855
  # NoMethodError: undefined method `class' for <Fluent::Config::Section {...}>:Fluent::Config::Section occurred. Should we add class method to Section?
469
856
  #assert_equal('Fluent::Config::Section', b4.description1.class.name)
@@ -486,11 +873,11 @@ module Fluent::Config
486
873
  end
487
874
 
488
875
  test 'checks missing of specifications' do
489
- conf0 = e('ROOT', '', {}, [])
876
+ conf0 = config_element('ROOT', '', {}, [])
490
877
  ex01 = ConfigurableSpec::Example0.new
491
878
  assert_raise(Fluent::ConfigError) { ex01.configure(conf0) }
492
879
 
493
- complete = e('ROOT', '', {
880
+ complete = config_element('ROOT', '', {
494
881
  "stringvalue" => "s1", "boolvalue" => "yes", "integervalue" => "10",
495
882
  "sizevalue" => "10m", "timevalue" => "100s", "floatvalue" => "1.001",
496
883
  "hashvalue" => '{"foo":1, "bar":2}',
@@ -500,18 +887,28 @@ module Fluent::Config
500
887
  checker = lambda { |conf| ConfigurableSpec::Example0.new.configure(conf) }
501
888
 
502
889
  assert_nothing_raised { checker.call(complete) }
503
- assert_raise(Fluent::ConfigError) { checker.call(complete.reject{|k,v| k == "stringvalue" }) }
504
- assert_raise(Fluent::ConfigError) { checker.call(complete.reject{|k,v| k == "boolvalue" }) }
505
- assert_raise(Fluent::ConfigError) { checker.call(complete.reject{|k,v| k == "integervalue"}) }
506
- assert_raise(Fluent::ConfigError) { checker.call(complete.reject{|k,v| k == "sizevalue" }) }
507
- assert_raise(Fluent::ConfigError) { checker.call(complete.reject{|k,v| k == "timevalue" }) }
508
- assert_raise(Fluent::ConfigError) { checker.call(complete.reject{|k,v| k == "floatvalue" }) }
509
- assert_raise(Fluent::ConfigError) { checker.call(complete.reject{|k,v| k == "hashvalue" }) }
510
- assert_raise(Fluent::ConfigError) { checker.call(complete.reject{|k,v| k == "arrayvalue" }) }
890
+ assert_raise(Fluent::ConfigError) { c = complete.dup; c.delete("stringvalue"); checker.call(c) }
891
+ assert_raise(Fluent::ConfigError) { c = complete.dup; c.delete("boolvalue"); checker.call(c) }
892
+ assert_raise(Fluent::ConfigError) { c = complete.dup; c.delete("integervalue"); checker.call(c) }
893
+ assert_raise(Fluent::ConfigError) { c = complete.dup; c.delete("sizevalue"); checker.call(c) }
894
+ assert_raise(Fluent::ConfigError) { c = complete.dup; c.delete("timevalue"); checker.call(c) }
895
+ assert_raise(Fluent::ConfigError) { c = complete.dup; c.delete("floatvalue"); checker.call(c) }
896
+ assert_raise(Fluent::ConfigError) { c = complete.dup; c.delete("hashvalue"); checker.call(c) }
897
+ assert_raise(Fluent::ConfigError) { c = complete.dup; c.delete("arrayvalue"); checker.call(c) }
898
+ end
899
+
900
+ test 'generates section with default values for init:true sections' do
901
+ conf = config_element('ROOT', '', {}, [])
902
+ init0 = ConfigurableSpec::Init0.new
903
+ assert_nothing_raised { init0.configure(conf) }
904
+ assert init0.sec1
905
+ assert_equal "sec1", init0.sec1.name
906
+ assert_equal 1, init0.sec2.size
907
+ assert_equal "sec1", init0.sec2.first.name
511
908
  end
512
909
 
513
910
  test 'accepts configuration values as string representation' do
514
- conf = e('ROOT', '', {
911
+ conf = config_element('ROOT', '', {
515
912
  "stringvalue" => "s1", "boolvalue" => "yes", "integervalue" => "10",
516
913
  "sizevalue" => "10m", "timevalue" => "10m", "floatvalue" => "1.001",
517
914
  "hashvalue" => '{"foo":1, "bar":2}',
@@ -529,7 +926,7 @@ module Fluent::Config
529
926
  end
530
927
 
531
928
  test 'accepts configuration values as ruby value representation (especially for DSL)' do
532
- conf = e('ROOT', '', {
929
+ conf = config_element('ROOT', '', {
533
930
  "stringvalue" => "s1", "boolvalue" => true, "integervalue" => 10,
534
931
  "sizevalue" => 10 * 1024 * 1024, "timevalue" => 10 * 60, "floatvalue" => 1.001,
535
932
  "hashvalue" => {"foo" => 1, "bar" => 2},
@@ -547,7 +944,7 @@ module Fluent::Config
547
944
  end
548
945
 
549
946
  test 'gets both of true(yes) and false(no) for bool value parameter' do
550
- conf = e('ROOT', '', {
947
+ conf = config_element('ROOT', '', {
551
948
  "stringvalue" => "s1", "integervalue" => 10,
552
949
  "sizevalue" => 10 * 1024 * 1024, "timevalue" => 10 * 60, "floatvalue" => 1.001,
553
950
  "hashvalue" => {"foo" => 1, "bar" => 2},
@@ -574,93 +971,212 @@ module Fluent::Config
574
971
  end
575
972
 
576
973
  sub_test_case '.config_section' do
577
- def e(name, arg = '', attrs = {}, elements = [])
578
- attrs_str_keys = {}
579
- attrs.each{|key, value| attrs_str_keys[key.to_s] = value }
580
- config_element(name, arg, attrs_str_keys, elements)
581
- end
582
-
583
- test 'subclass configuration spec can overwrite superclass specs' do
584
- # conf0 = e('ROOT', '', {}, [])
585
-
586
- conf1 = e('ROOT', '', {
587
- 'name' => 'tagomoris',
588
- 'bool' => true,
589
- },
590
- )
591
- # <detail> section is required by overwriting of Example2 config_section spec
592
- assert_nothing_raised { ConfigurableSpec::Example1.new.configure(conf1) }
593
- assert_raise(Fluent::ConfigError.new("'<detail>' sections are required")) { ConfigurableSpec::Example2.new.configure(conf1) }
594
-
595
- conf2 = e('ROOT', '', {
596
- 'name' => 'tagomoris',
597
- 'bool' => true,
598
- },
599
- [e('detail', '', { 'phone_no' => "+81-00-0000-0000" }, [])],
600
- )
601
- # <detail> address </detail> default is overwritten by Example2
602
- assert_nothing_raised { ConfigurableSpec::Example1.new.configure(conf2) }
603
- assert_nothing_raised { ConfigurableSpec::Example2.new.configure(conf2) }
604
- ex1 = ConfigurableSpec::Example1.new.configure(conf2)
605
- assert_equal "x", ex1.detail.address
606
- ex2 = ConfigurableSpec::Example2.new.configure(conf2)
607
- assert_equal "y", ex2.detail.address
608
-
609
- conf3 = e('ROOT', '', {
610
- 'name' => 'tagomoris',
611
- 'bool' => true,
612
- },
613
- [e('detail', '', { 'address' => "Chiyoda Tokyo Japan" }, [])],
614
- )
615
- # <detail> phone_no </detail> is required by Example2 config_param spec
616
- assert_nothing_raised { ConfigurableSpec::Example1.new.configure(conf3) }
617
- assert_raise(Fluent::ConfigError.new("'phone_no' parameter is required, in section detail")) { ConfigurableSpec::Example2.new.configure(conf3) }
618
-
619
- conf4 = e('ROOT', '', {
620
- 'name' => 'tagomoris',
621
- 'bool' => true,
622
- },
623
- [e('detail', '', { 'address' => "Chiyoda Tokyo Japan", 'phone_no' => '+81-00-0000-0000' }, [])],
624
- )
625
- assert_nothing_raised { ConfigurableSpec::Example1.new.configure(conf4) } # phone_no is not used
626
- assert_nothing_raised { ConfigurableSpec::Example2.new.configure(conf4) }
627
-
628
- ex2 = ConfigurableSpec::Example2.new.configure(conf4)
629
- assert_equal "Chiyoda Tokyo Japan", ex2.detail.address
630
- assert_equal "+81-00-0000-0000", ex2.detail.phone_no
631
- end
632
-
633
- test 'adds only config_param definitions into configuration without overwriting existing finalized configuration elements' do
634
-
635
- conf1 = e('ROOT', '', {}, [])
636
- # <appendix> is required by Example3 and its not be overwritten by Example4
637
- assert_raise(Fluent::ConfigError.new("'<appendix>' sections are required")) { ConfigurableSpec::Example3.new.configure(conf1) }
638
- assert_raise(Fluent::ConfigError.new("'<appendix>' sections are required")) { ConfigurableSpec::Example4.new.configure(conf1) }
639
-
640
- conf2 = e('ROOT', '', {
641
- },
642
- [e('appendix', '', {'type' => '1'}, [])],
643
- )
644
- # default value of age is overwritten by Example4, because root proxy is not finalized
645
- ex3 = ConfigurableSpec::Example3.new.configure(conf2)
646
- assert_equal 10, ex3.age
647
- assert_equal '1', ex3.appendix.type
648
- ex4 = ConfigurableSpec::Example4.new.configure(conf2)
649
- assert_equal 20, ex4.age
650
- assert_equal '1', ex4.appendix.type
651
-
652
- conf3 = e('ROOT', '', {},
653
- [e('appendix', '', {'type' => '2'}, [])],
654
- )
655
- # default value of <appendix> name </appendix> cannot be overwritten because it is finalized
656
- ex3 = ConfigurableSpec::Example3.new.configure(conf2)
657
- assert_equal 10, ex3.age
658
- assert_equal '1', ex3.appendix.type
659
- ex4 = ConfigurableSpec::Example4.new.configure(conf2)
660
- assert_equal 20, ex4.age
661
- assert_equal '1', ex4.appendix.type
662
- # <appendix> age </appendix> can be added because it is missing in superclass spec
663
- assert_equal 10, ex4.appendix.age
974
+ CONF1 = config_element('ROOT', '', {
975
+ 'name' => 'tagomoris',
976
+ 'bool' => true,
977
+ })
978
+
979
+ CONF2 = config_element('ROOT', '', {
980
+ 'name' => 'tagomoris',
981
+ 'bool' => true,
982
+ },
983
+ [config_element('detail', '', { 'phone_no' => "+81-00-0000-0000" }, [])])
984
+
985
+ CONF3 = config_element('ROOT', '', {
986
+ 'name' => 'tagomoris',
987
+ 'bool' => true,
988
+ },
989
+ [config_element('detail', '', { 'address' => "Chiyoda Tokyo Japan" }, [])])
990
+
991
+ CONF4 = config_element('ROOT', '', {
992
+ 'name' => 'tagomoris',
993
+ 'bool' => true,
994
+ },
995
+ [
996
+ config_element('detail', '', {
997
+ 'address' => "Chiyoda Tokyo Japan",
998
+ 'phone_no' => '+81-00-0000-0000'
999
+ },
1000
+ [])
1001
+ ])
1002
+
1003
+ data(conf1: CONF1,
1004
+ conf2: CONF2,
1005
+ conf3: CONF3,
1006
+ conf4: CONF4,)
1007
+ test 'base class' do |data|
1008
+ assert_nothing_raised { ConfigurableSpec::Overwrite::Base.new.configure(data) }
1009
+ end
1010
+
1011
+ test 'subclass cannot overwrite required' do
1012
+ assert_raise(Fluent::ConfigError.new("BUG: subclass cannot overwrite base class's config_section: required")) do
1013
+ ConfigurableSpec::Overwrite::Required.new.configure(CONF1)
1014
+ end
1015
+ end
1016
+
1017
+ test 'subclass cannot overwrite multi' do
1018
+ assert_raise(Fluent::ConfigError.new("BUG: subclass cannot overwrite base class's config_section: multi")) do
1019
+ ConfigurableSpec::Overwrite::Multi.new.configure(CONF1)
1020
+ end
1021
+ end
1022
+
1023
+ test 'subclass cannot overwrite alias' do
1024
+ assert_raise(Fluent::ConfigError.new("BUG: subclass cannot overwrite base class's config_section: alias")) do
1025
+ ConfigurableSpec::Overwrite::Alias.new.configure(CONF1)
1026
+ end
1027
+ end
1028
+
1029
+ test 'subclass uses superclass default options' do
1030
+ base = ConfigurableSpec::Overwrite::Base.new.configure(CONF2)
1031
+ sub = ConfigurableSpec::Overwrite::DefaultOptions.new.configure(CONF2)
1032
+ detail_base = base.class.merged_configure_proxy.sections[:detail]
1033
+ detail_sub = sub.class.merged_configure_proxy.sections[:detail]
1034
+ detail_base_attributes = {
1035
+ required: detail_base.required,
1036
+ multi: detail_base.multi,
1037
+ alias: detail_base.alias,
1038
+ }
1039
+ detail_sub_attributes = {
1040
+ required: detail_sub.required,
1041
+ multi: detail_sub.multi,
1042
+ alias: detail_sub.alias,
1043
+ }
1044
+ assert_equal(detail_base_attributes, detail_sub_attributes)
1045
+ end
1046
+
1047
+ test 'subclass can overwrite detail.address' do
1048
+ base = ConfigurableSpec::Overwrite::Base.new.configure(CONF2)
1049
+ target = ConfigurableSpec::Overwrite::DetailAddressDefault.new.configure(CONF2)
1050
+ expected_addresses = ["x", "y"]
1051
+ actual_addresses = [base.detail.address, target.detail.address]
1052
+ assert_equal(expected_addresses, actual_addresses)
1053
+ end
1054
+
1055
+ test 'subclass can add param' do
1056
+ assert_raise(Fluent::ConfigError.new("'phone_no' parameter is required, in section detail")) do
1057
+ ConfigurableSpec::Overwrite::AddParam.new.configure(CONF3)
1058
+ end
1059
+ target = ConfigurableSpec::Overwrite::AddParam.new.configure(CONF4)
1060
+ expected = {
1061
+ address: "Chiyoda Tokyo Japan",
1062
+ phone_no: "+81-00-0000-0000"
1063
+ }
1064
+ actual = {
1065
+ address: target.detail.address,
1066
+ phone_no: target.detail.phone_no
1067
+ }
1068
+ assert_equal(expected, actual)
1069
+ end
1070
+
1071
+ test 'subclass can add param with overwriting address' do
1072
+ assert_raise(Fluent::ConfigError.new("'phone_no' parameter is required, in section detail")) do
1073
+ ConfigurableSpec::Overwrite::AddParamOverwriteAddress.new.configure(CONF3)
1074
+ end
1075
+ target = ConfigurableSpec::Overwrite::AddParamOverwriteAddress.new.configure(CONF4)
1076
+ expected = {
1077
+ address: "Chiyoda Tokyo Japan",
1078
+ phone_no: "+81-00-0000-0000"
1079
+ }
1080
+ actual = {
1081
+ address: target.detail.address,
1082
+ phone_no: target.detail.phone_no
1083
+ }
1084
+ assert_equal(expected, actual)
1085
+ end
1086
+
1087
+ sub_test_case 'final' do
1088
+ test 'base class has designed params and default values' do
1089
+ b = ConfigurableSpec::Final::Base.new
1090
+ appendix_conf = config_element('appendix', '', {"code" => "b", "name" => "base"})
1091
+ b.configure(config_element('ROOT', '', {}, [appendix_conf]))
1092
+
1093
+ assert_equal "b", b.appendix.code
1094
+ assert_equal "base", b.appendix.name
1095
+ assert_equal "", b.appendix.address
1096
+ end
1097
+
1098
+ test 'subclass can change type, add default value, change default value of parameters, and add parameters to non-finalized section' do
1099
+ f = ConfigurableSpec::Final::Finalized.new
1100
+ appendix_conf = config_element('appendix', '', {"code" => 1})
1101
+ f.configure(config_element('ROOT', '', {}, [appendix_conf]))
1102
+
1103
+ assert_equal 1, f.appendix.code
1104
+ assert_equal 'y', f.appendix.name
1105
+ assert_equal "-", f.appendix.address
1106
+ assert_equal 10, f.appendix.age
1107
+ end
1108
+
1109
+ test 'subclass can add default value, change default value of parameters, and add parameters to finalized section' do
1110
+ i = ConfigurableSpec::Final::InheritsFinalized.new
1111
+ appendix_conf = config_element('appendix', '', {"phone_no" => "00-0000-0000"})
1112
+ i.configure(config_element('ROOT', '', {}, [appendix_conf]))
1113
+
1114
+ assert_equal 2, i.appendix.code
1115
+ assert_equal 0, i.appendix.age
1116
+ assert_equal "00-0000-0000", i.appendix.phone_no
1117
+ end
1118
+
1119
+ test 'finalized base class works as designed' do
1120
+ b = ConfigurableSpec::Final::FinalizedBase.new
1121
+ appendix_conf = config_element('options', '', {"name" => "moris"})
1122
+
1123
+ assert_nothing_raised do
1124
+ b.configure(config_element('ROOT', '', {}, [appendix_conf]))
1125
+ end
1126
+ assert b.apd
1127
+ assert_equal "moris", b.apd.name
1128
+ end
1129
+
1130
+ test 'subclass can change init' do
1131
+ n = ConfigurableSpec::Final::OverwriteInit.new
1132
+
1133
+ assert_nothing_raised do
1134
+ n.configure(config_element('ROOT', ''))
1135
+ end
1136
+ assert n.apd
1137
+ assert_equal "moris", n.apd.name
1138
+ assert_equal 0, n.apd.code
1139
+ end
1140
+
1141
+ test 'subclass cannot change parameter types in finalized sections' do
1142
+ s = ConfigurableSpec::Final::Subclass.new
1143
+ appendix_conf = config_element('options', '', {"name" => "1"})
1144
+
1145
+ assert_nothing_raised do
1146
+ s.configure(config_element('ROOT', '', {}, [appendix_conf]))
1147
+ end
1148
+ assert_equal "1", s.apd.name
1149
+ end
1150
+
1151
+ test 'subclass cannot change param_name of finalized section' do
1152
+ assert_raise(Fluent::ConfigError.new("BUG: subclass cannot overwrite base class's config_section: param_name")) do
1153
+ ConfigurableSpec::Final::OverwriteParamName.new
1154
+ end
1155
+ end
1156
+
1157
+ test 'subclass cannot change final of finalized section' do
1158
+ assert_raise(Fluent::ConfigError.new("BUG: subclass cannot overwrite finalized base class's config_section")) do
1159
+ ConfigurableSpec::Final::OverwriteFinal.new
1160
+ end
1161
+ end
1162
+
1163
+ test 'subclass cannot change required of finalized section' do
1164
+ assert_raise(Fluent::ConfigError.new("BUG: subclass cannot overwrite base class's config_section: required")) do
1165
+ ConfigurableSpec::Final::OverwriteRequired.new
1166
+ end
1167
+ end
1168
+
1169
+ test 'subclass cannot change multi of finalized section' do
1170
+ assert_raise(Fluent::ConfigError.new("BUG: subclass cannot overwrite base class's config_section: multi")) do
1171
+ ConfigurableSpec::Final::OverwriteMulti.new
1172
+ end
1173
+ end
1174
+
1175
+ test 'subclass cannot change alias of finalized section' do
1176
+ assert_raise(Fluent::ConfigError.new("BUG: subclass cannot overwrite base class's config_section: alias")) do
1177
+ ConfigurableSpec::Final::OverwriteAlias.new
1178
+ end
1179
+ end
664
1180
  end
665
1181
  end
666
1182
  end
@@ -679,15 +1195,14 @@ module Fluent::Config
679
1195
  end
680
1196
 
681
1197
  sub_test_case '#configure' do
682
- def e(name, arg = '', attrs = {}, elements = [])
683
- attrs_str_keys = {}
684
- attrs.each{|key, value| attrs_str_keys[key.to_s] = value }
685
- config_element(name, arg, attrs_str_keys, elements)
686
- end
687
-
688
1198
  test 'provides accessible data for alias attribute keys' do
689
1199
  ex1 = ConfigurableSpec::Example1.new
690
- ex1.configure(e('ROOT', '', {"fullname" => "foo bar", "bool" => false}, [e('information', '', {"address" => "Mountain View 0"})]))
1200
+ conf = config_element('ROOT', '', {
1201
+ "fullname" => "foo bar",
1202
+ "bool" => false
1203
+ },
1204
+ [config_element('information', '', {"address" => "Mountain View 0"})])
1205
+ ex1.configure(conf)
691
1206
  assert_equal("foo bar", ex1.name)
692
1207
  assert_not_nil(ex1.bool)
693
1208
  assert_false(ex1.bool)
@@ -697,15 +1212,82 @@ module Fluent::Config
697
1212
  end
698
1213
  end
699
1214
 
700
- sub_test_case ':secret option' do
701
- def e(name, arg = '', attrs = {}, elements = [])
702
- attrs_str_keys = {}
703
- attrs.each { |key, value| attrs_str_keys[key.to_s] = value }
704
- config_element(name, arg, attrs_str_keys, elements)
1215
+ sub_test_case 'defaults can be overwritten by owner' do
1216
+ test 'for feature plugin which has flat parameters with parent' do
1217
+ owner = ConfigurableSpec::OverwriteDefaults::Owner.new
1218
+ child = ConfigurableSpec::OverwriteDefaults::FlatChild.new
1219
+ assert_nil child.class.merged_configure_proxy.configured_in_section
1220
+
1221
+ child.owner = owner
1222
+ child.configure(config_element('ROOT', '', {}, []))
1223
+ assert_equal "V1", child.key1
1224
+ end
1225
+
1226
+ test 'for feature plugin which has parameters in subsection of parent' do
1227
+ owner = ConfigurableSpec::OverwriteDefaults::Owner.new
1228
+ child = ConfigurableSpec::OverwriteDefaults::BufferChild.new
1229
+ assert_equal :buffer, child.class.merged_configure_proxy.configured_in_section
1230
+
1231
+ child.owner = owner
1232
+ child.configure(config_element('ROOT', '', {}, []))
1233
+ assert_equal 1024, child.size_of_something
1234
+ end
1235
+
1236
+ test 'even in subclass of owner' do
1237
+ owner = ConfigurableSpec::OverwriteDefaults::SubOwner.new
1238
+ child = ConfigurableSpec::OverwriteDefaults::BufferChild.new
1239
+ assert_equal :buffer, child.class.merged_configure_proxy.configured_in_section
1240
+
1241
+ child.owner = owner
1242
+ child.configure(config_element('ROOT', '', {}, []))
1243
+ assert_equal 2048, child.size_of_something
1244
+ end
1245
+
1246
+ test 'default values can be overwritten with nil' do
1247
+ owner = ConfigurableSpec::OverwriteDefaults::NilOwner.new
1248
+ child = ConfigurableSpec::OverwriteDefaults::BufferChild.new
1249
+ assert_equal :buffer, child.class.merged_configure_proxy.configured_in_section
1250
+
1251
+ child.owner = owner
1252
+ child.configure(config_element('ROOT', '', {}, []))
1253
+ assert_nil child.size_of_something
1254
+ end
1255
+
1256
+ test 'the first configured_in (in the order from base class) will be applied' do
1257
+ child = ConfigurableSpec::OverwriteDefaults::BufferSubclass.new
1258
+ assert_equal :buffer, child.class.merged_configure_proxy.configured_in_section
1259
+
1260
+ child.configure(config_element('ROOT', '', {}, []))
1261
+ assert_equal 512, child.size_of_something
1262
+ end
1263
+
1264
+ test 'the first configured_in is valid with owner classes' do
1265
+ owner = ConfigurableSpec::OverwriteDefaults::Owner.new
1266
+ child = ConfigurableSpec::OverwriteDefaults::BufferSubclass.new
1267
+ assert_equal :buffer, child.class.merged_configure_proxy.configured_in_section
1268
+
1269
+ child.owner = owner
1270
+ child.configure(config_element('ROOT', '', {}, []))
1271
+ assert_equal 1024, child.size_of_something
705
1272
  end
706
1273
 
1274
+ test 'the only first configured_in is valid even in subclasses of a class with configured_in' do
1275
+ child = ConfigurableSpec::OverwriteDefaults::BufferSubSubclass.new
1276
+ assert_equal :buffer, child.class.merged_configure_proxy.configured_in_section
1277
+
1278
+ child.configure(config_element('ROOT', '', {}, []))
1279
+ assert_equal 512, child.size_of_something
1280
+ end
1281
+ end
1282
+
1283
+ sub_test_case ':secret option' do
707
1284
  setup do
708
- @conf = e('ROOT', '', {'normal_param' => 'normal', 'secret_param' => 'secret'}, [e('section', '', {'normal_param2' => 'normal', 'secret_param2' => 'secret'} )])
1285
+ @conf = config_element('ROOT', '',
1286
+ {
1287
+ 'normal_param' => 'normal',
1288
+ 'secret_param' => 'secret'
1289
+ },
1290
+ [config_element('section', '', {'normal_param2' => 'normal', 'secret_param2' => 'secret'} )])
709
1291
  @example = ConfigurableSpec::Example5.new
710
1292
  @example.configure(@conf)
711
1293
  end
@@ -730,7 +1312,12 @@ module Fluent::Config
730
1312
  end
731
1313
 
732
1314
  test 'get plugin name when found unknown section' do
733
- @conf = e('ROOT', '', {'normal_param' => 'normal', 'secret_param' => 'secret'}, [e('unknown', '', {'normal_param2' => 'normal', 'secret_param2' => 'secret'} )])
1315
+ @conf = config_element('ROOT', '',
1316
+ {
1317
+ 'normal_param' => 'normal',
1318
+ 'secret_param' => 'secret'
1319
+ },
1320
+ [config_element('unknown', '', {'normal_param2' => 'normal', 'secret_param2' => 'secret'} )])
734
1321
  @example = ConfigurableSpec::Example5.new
735
1322
  @example.configure(@conf)
736
1323
  @conf.elements.each { |e|
@@ -747,6 +1334,18 @@ module Fluent::Config
747
1334
  end
748
1335
  end
749
1336
  end
1337
+
1338
+ sub_test_case ':skip_accessor option' do
1339
+ test 'it does not create accessor methods for parameters' do
1340
+ @example = ConfigurableSpec::Example7.new
1341
+ @example.configure(config_element('ROOT'))
1342
+ assert_equal 'example7', @example.instance_variable_get(:@name)
1343
+ assert_raise NoMethodError.new("undefined method `name' for #{@example}") do
1344
+ @example.name
1345
+ end
1346
+ end
1347
+ end
1348
+
750
1349
  sub_test_case 'non-required options for config_param' do
751
1350
  test 'desc must be a string if specified' do
752
1351
  assert_raise ArgumentError.new("key: desc must be a String, but Symbol") do
@@ -764,6 +1363,20 @@ module Fluent::Config
764
1363
  end
765
1364
  end
766
1365
  end
1366
+ test 'secret must be true or false if specified' do
1367
+ assert_raise ArgumentError.new("key: secret must be true or false, but NilClass") do
1368
+ class InvalidSecretClass
1369
+ include Fluent::Configurable
1370
+ config_param :key, :string, default: '', secret: nil
1371
+ end
1372
+ end
1373
+ assert_raise ArgumentError.new("key: secret must be true or false, but String") do
1374
+ class InvalidSecret2Class
1375
+ include Fluent::Configurable
1376
+ config_param :key, :string, default: '', secret: 'yes'
1377
+ end
1378
+ end
1379
+ end
767
1380
  test 'deprecated must be a string if specified' do
768
1381
  assert_raise ArgumentError.new("key: deprecated must be a String, but TrueClass") do
769
1382
  class InvalidDeprecatedClass
@@ -796,6 +1409,20 @@ module Fluent::Config
796
1409
  end
797
1410
  end
798
1411
  end
1412
+ test 'skip_accessor must be true or false if specified' do
1413
+ assert_raise ArgumentError.new("key: skip_accessor must be true or false, but NilClass") do
1414
+ class InvalidSkipAccessorClass
1415
+ include Fluent::Configurable
1416
+ config_param :key, :string, default: '', skip_accessor: nil
1417
+ end
1418
+ end
1419
+ assert_raise ArgumentError.new("key: skip_accessor must be true or false, but String") do
1420
+ class InvalidSkipAccessor2Class
1421
+ include Fluent::Configurable
1422
+ config_param :key, :string, default: '', skip_accessor: 'yes'
1423
+ end
1424
+ end
1425
+ end
799
1426
  end
800
1427
  sub_test_case 'enum parameters' do
801
1428
  test 'list must be specified as an array of symbols'
@@ -827,6 +1454,138 @@ module Fluent::Config
827
1454
  assert_raise Fluent::ObsoletedParameterError.new("'key2' parameter is already removed: key2 has been removed.") do
828
1455
  obj.configure(config_element('ROOT', '', {'key2' => 'yay'}, []))
829
1456
  end
1457
+ first_log = obj.log.logs.first
1458
+ assert{ first_log && first_log.include?("[error]") && first_log.include?("config error in:\n<ROOT>\n key2 yay\n</ROOT>") }
1459
+ end
1460
+
1461
+ sub_test_case 'logger is nil' do
1462
+ test 'nothing raised if deprecated parameter is configured' do
1463
+ obj = ConfigurableSpec::UnRecommended.new
1464
+ obj.log = nil
1465
+ obj.configure(config_element('ROOT', '', {'key1' => 'yay'}, []))
1466
+ assert_nil(obj.log)
1467
+ end
1468
+
1469
+ test 'NoMethodError is not raised if obsoleted parameter is configured' do
1470
+ obj = ConfigurableSpec::UnRecommended.new
1471
+ obj.log = nil
1472
+ assert_raise Fluent::ObsoletedParameterError.new("'key2' parameter is already removed: key2 has been removed.") do
1473
+ obj.configure(config_element('ROOT', '', {'key2' => 'yay'}, []))
1474
+ end
1475
+ assert_nil(obj.log)
1476
+ end
1477
+ end
1478
+ end
1479
+
1480
+ sub_test_case '#config_param without default values cause error if section is configured as init:true' do
1481
+ setup do
1482
+ @type_lookup = ->(type) { Fluent::Configurable.lookup_type(type) }
1483
+ @proxy = Fluent::Config::ConfigureProxy.new(:section, type_lookup: @type_lookup)
1484
+ end
1485
+
1486
+ test 'with simple config_param with default value' do
1487
+ class InitTestClass01
1488
+ include Fluent::Configurable
1489
+ config_section :subsection, init: true do
1490
+ config_param :param1, :integer, default: 1
1491
+ end
1492
+ end
1493
+ c = InitTestClass01.new
1494
+ c.configure(config_element('root', ''))
1495
+
1496
+ assert_equal 1, c.subsection.size
1497
+ assert_equal 1, c.subsection.first.param1
1498
+ end
1499
+
1500
+ test 'with simple config_param without default value' do
1501
+ class InitTestClass02
1502
+ include Fluent::Configurable
1503
+ config_section :subsection, init: true do
1504
+ config_param :param1, :integer
1505
+ end
1506
+ end
1507
+ c = InitTestClass02.new
1508
+ assert_raises ArgumentError.new("subsection: init is specified, but there're parameters without default values:param1") do
1509
+ c.configure(config_element('root', ''))
1510
+ end
1511
+
1512
+ c.configure(config_element('root', '', {}, [config_element('subsection', '', {'param1' => '1'})]))
1513
+
1514
+ assert_equal 1, c.subsection.size
1515
+ assert_equal 1, c.subsection.first.param1
1516
+ end
1517
+
1518
+ test 'with config_param with config_set_default' do
1519
+ module InitTestModule03
1520
+ include Fluent::Configurable
1521
+ config_section :subsection, init: true do
1522
+ config_param :param1, :integer
1523
+ end
1524
+ end
1525
+ class InitTestClass03
1526
+ include Fluent::Configurable
1527
+ include InitTestModule03
1528
+ config_section :subsection do
1529
+ config_set_default :param1, 1
1530
+ end
1531
+ end
1532
+
1533
+ c = InitTestClass03.new
1534
+ c.configure(config_element('root', ''))
1535
+
1536
+ assert_equal 1, c.subsection.size
1537
+ assert_equal 1, c.subsection.first.param1
1538
+ end
1539
+
1540
+ test 'with config_argument with default value' do
1541
+ class InitTestClass04
1542
+ include Fluent::Configurable
1543
+ config_section :subsection, init: true do
1544
+ config_argument :param0, :string, default: 'yay'
1545
+ end
1546
+ end
1547
+
1548
+ c = InitTestClass04.new
1549
+ c.configure(config_element('root', ''))
1550
+
1551
+ assert_equal 1, c.subsection.size
1552
+ assert_equal 'yay', c.subsection.first.param0
1553
+ end
1554
+
1555
+ test 'with config_argument without default value' do
1556
+ class InitTestClass04
1557
+ include Fluent::Configurable
1558
+ config_section :subsection, init: true do
1559
+ config_argument :param0, :string
1560
+ end
1561
+ end
1562
+
1563
+ c = InitTestClass04.new
1564
+ assert_raise ArgumentError.new("subsection: init is specified, but default value of argument is missing") do
1565
+ c.configure(config_element('root', ''))
1566
+ end
1567
+ end
1568
+
1569
+ test 'with config_argument with config_set_default' do
1570
+ module InitTestModule05
1571
+ include Fluent::Configurable
1572
+ config_section :subsection, init: true do
1573
+ config_argument :param0, :string
1574
+ end
1575
+ end
1576
+ class InitTestClass05
1577
+ include Fluent::Configurable
1578
+ include InitTestModule05
1579
+ config_section :subsection do
1580
+ config_set_default :param0, 'foo'
1581
+ end
1582
+ end
1583
+
1584
+ c = InitTestClass05.new
1585
+ c.configure(config_element('root', ''))
1586
+
1587
+ assert_equal 1, c.subsection.size
1588
+ assert_equal 'foo', c.subsection.first.param0
830
1589
  end
831
1590
  end
832
1591
  end