fluentd 1.17.0-x64-mingw32 → 1.17.1-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (259) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +46 -0
  3. data/README.md +1 -0
  4. data/SECURITY.md +2 -2
  5. data/fluent.conf +14 -14
  6. data/lib/fluent/command/cap_ctl.rb +4 -4
  7. data/lib/fluent/compat/call_super_mixin.rb +3 -3
  8. data/lib/fluent/compat/propagate_default.rb +4 -4
  9. data/lib/fluent/config/yaml_parser/parser.rb +4 -0
  10. data/lib/fluent/log/console_adapter.rb +4 -2
  11. data/lib/fluent/plugin/in_exec.rb +14 -2
  12. data/lib/fluent/plugin/in_http.rb +1 -1
  13. data/lib/fluent/plugin/in_sample.rb +13 -7
  14. data/lib/fluent/plugin/in_tail.rb +65 -23
  15. data/lib/fluent/plugin/out_copy.rb +1 -1
  16. data/lib/fluent/plugin/out_file.rb +8 -0
  17. data/lib/fluent/plugin/out_http.rb +12 -0
  18. data/lib/fluent/plugin/parser_json.rb +4 -12
  19. data/lib/fluent/plugin_helper/http_server/server.rb +1 -1
  20. data/lib/fluent/version.rb +1 -1
  21. data/templates/new_gem/fluent-plugin.gemspec.erb +6 -5
  22. metadata +25 -472
  23. data/.github/DISCUSSION_TEMPLATE/q-a-japanese.yml +0 -50
  24. data/.github/DISCUSSION_TEMPLATE/q-a.yml +0 -47
  25. data/.github/ISSUE_TEMPLATE/bug_report.yml +0 -71
  26. data/.github/ISSUE_TEMPLATE/config.yml +0 -5
  27. data/.github/ISSUE_TEMPLATE/feature_request.yml +0 -39
  28. data/.github/ISSUE_TEMPLATE.md +0 -17
  29. data/.github/PULL_REQUEST_TEMPLATE.md +0 -14
  30. data/.github/workflows/stale-actions.yml +0 -24
  31. data/.github/workflows/test-ruby-head.yml +0 -31
  32. data/.github/workflows/test.yml +0 -32
  33. data/.gitignore +0 -30
  34. data/Gemfile +0 -9
  35. data/fluentd.gemspec +0 -62
  36. data/test/command/test_binlog_reader.rb +0 -362
  37. data/test/command/test_ca_generate.rb +0 -70
  38. data/test/command/test_cap_ctl.rb +0 -100
  39. data/test/command/test_cat.rb +0 -128
  40. data/test/command/test_ctl.rb +0 -56
  41. data/test/command/test_fluentd.rb +0 -1291
  42. data/test/command/test_plugin_config_formatter.rb +0 -397
  43. data/test/command/test_plugin_generator.rb +0 -109
  44. data/test/compat/test_calls_super.rb +0 -166
  45. data/test/compat/test_parser.rb +0 -92
  46. data/test/config/assertions.rb +0 -42
  47. data/test/config/test_config_parser.rb +0 -551
  48. data/test/config/test_configurable.rb +0 -1784
  49. data/test/config/test_configure_proxy.rb +0 -604
  50. data/test/config/test_dsl.rb +0 -415
  51. data/test/config/test_element.rb +0 -518
  52. data/test/config/test_literal_parser.rb +0 -309
  53. data/test/config/test_plugin_configuration.rb +0 -56
  54. data/test/config/test_section.rb +0 -191
  55. data/test/config/test_system_config.rb +0 -195
  56. data/test/config/test_types.rb +0 -408
  57. data/test/counter/test_client.rb +0 -563
  58. data/test/counter/test_error.rb +0 -44
  59. data/test/counter/test_mutex_hash.rb +0 -179
  60. data/test/counter/test_server.rb +0 -589
  61. data/test/counter/test_store.rb +0 -258
  62. data/test/counter/test_validator.rb +0 -137
  63. data/test/helper.rb +0 -155
  64. data/test/helpers/fuzzy_assert.rb +0 -89
  65. data/test/helpers/process_extenstion.rb +0 -33
  66. data/test/log/test_console_adapter.rb +0 -117
  67. data/test/plugin/data/2010/01/20100102-030405.log +0 -0
  68. data/test/plugin/data/2010/01/20100102-030406.log +0 -0
  69. data/test/plugin/data/2010/01/20100102.log +0 -0
  70. data/test/plugin/data/log/bar +0 -0
  71. data/test/plugin/data/log/foo/bar.log +0 -0
  72. data/test/plugin/data/log/foo/bar2 +0 -0
  73. data/test/plugin/data/log/test.log +0 -0
  74. data/test/plugin/data/log_numeric/01.log +0 -0
  75. data/test/plugin/data/log_numeric/02.log +0 -0
  76. data/test/plugin/data/log_numeric/12.log +0 -0
  77. data/test/plugin/data/log_numeric/14.log +0 -0
  78. data/test/plugin/data/sd_file/config +0 -11
  79. data/test/plugin/data/sd_file/config.json +0 -17
  80. data/test/plugin/data/sd_file/config.yaml +0 -11
  81. data/test/plugin/data/sd_file/config.yml +0 -11
  82. data/test/plugin/data/sd_file/invalid_config.yml +0 -7
  83. data/test/plugin/in_tail/test_fifo.rb +0 -121
  84. data/test/plugin/in_tail/test_io_handler.rb +0 -150
  85. data/test/plugin/in_tail/test_position_file.rb +0 -346
  86. data/test/plugin/out_forward/test_ack_handler.rb +0 -140
  87. data/test/plugin/out_forward/test_connection_manager.rb +0 -145
  88. data/test/plugin/out_forward/test_handshake_protocol.rb +0 -112
  89. data/test/plugin/out_forward/test_load_balancer.rb +0 -106
  90. data/test/plugin/out_forward/test_socket_cache.rb +0 -174
  91. data/test/plugin/test_bare_output.rb +0 -131
  92. data/test/plugin/test_base.rb +0 -247
  93. data/test/plugin/test_buf_file.rb +0 -1314
  94. data/test/plugin/test_buf_file_single.rb +0 -898
  95. data/test/plugin/test_buf_memory.rb +0 -42
  96. data/test/plugin/test_buffer.rb +0 -1493
  97. data/test/plugin/test_buffer_chunk.rb +0 -209
  98. data/test/plugin/test_buffer_file_chunk.rb +0 -871
  99. data/test/plugin/test_buffer_file_single_chunk.rb +0 -611
  100. data/test/plugin/test_buffer_memory_chunk.rb +0 -339
  101. data/test/plugin/test_compressable.rb +0 -87
  102. data/test/plugin/test_file_util.rb +0 -96
  103. data/test/plugin/test_filter.rb +0 -368
  104. data/test/plugin/test_filter_grep.rb +0 -697
  105. data/test/plugin/test_filter_parser.rb +0 -731
  106. data/test/plugin/test_filter_record_transformer.rb +0 -577
  107. data/test/plugin/test_filter_stdout.rb +0 -207
  108. data/test/plugin/test_formatter_csv.rb +0 -136
  109. data/test/plugin/test_formatter_hash.rb +0 -38
  110. data/test/plugin/test_formatter_json.rb +0 -61
  111. data/test/plugin/test_formatter_ltsv.rb +0 -70
  112. data/test/plugin/test_formatter_msgpack.rb +0 -28
  113. data/test/plugin/test_formatter_out_file.rb +0 -116
  114. data/test/plugin/test_formatter_single_value.rb +0 -44
  115. data/test/plugin/test_formatter_tsv.rb +0 -76
  116. data/test/plugin/test_in_debug_agent.rb +0 -49
  117. data/test/plugin/test_in_exec.rb +0 -261
  118. data/test/plugin/test_in_forward.rb +0 -1178
  119. data/test/plugin/test_in_gc_stat.rb +0 -62
  120. data/test/plugin/test_in_http.rb +0 -1124
  121. data/test/plugin/test_in_monitor_agent.rb +0 -922
  122. data/test/plugin/test_in_object_space.rb +0 -66
  123. data/test/plugin/test_in_sample.rb +0 -190
  124. data/test/plugin/test_in_syslog.rb +0 -505
  125. data/test/plugin/test_in_tail.rb +0 -3429
  126. data/test/plugin/test_in_tcp.rb +0 -328
  127. data/test/plugin/test_in_udp.rb +0 -296
  128. data/test/plugin/test_in_unix.rb +0 -181
  129. data/test/plugin/test_input.rb +0 -137
  130. data/test/plugin/test_metadata.rb +0 -89
  131. data/test/plugin/test_metrics.rb +0 -294
  132. data/test/plugin/test_metrics_local.rb +0 -96
  133. data/test/plugin/test_multi_output.rb +0 -204
  134. data/test/plugin/test_out_copy.rb +0 -308
  135. data/test/plugin/test_out_exec.rb +0 -312
  136. data/test/plugin/test_out_exec_filter.rb +0 -606
  137. data/test/plugin/test_out_file.rb +0 -1038
  138. data/test/plugin/test_out_forward.rb +0 -1349
  139. data/test/plugin/test_out_http.rb +0 -557
  140. data/test/plugin/test_out_null.rb +0 -105
  141. data/test/plugin/test_out_relabel.rb +0 -28
  142. data/test/plugin/test_out_roundrobin.rb +0 -146
  143. data/test/plugin/test_out_secondary_file.rb +0 -458
  144. data/test/plugin/test_out_stdout.rb +0 -205
  145. data/test/plugin/test_out_stream.rb +0 -103
  146. data/test/plugin/test_output.rb +0 -1334
  147. data/test/plugin/test_output_as_buffered.rb +0 -2024
  148. data/test/plugin/test_output_as_buffered_backup.rb +0 -363
  149. data/test/plugin/test_output_as_buffered_compress.rb +0 -179
  150. data/test/plugin/test_output_as_buffered_overflow.rb +0 -250
  151. data/test/plugin/test_output_as_buffered_retries.rb +0 -966
  152. data/test/plugin/test_output_as_buffered_secondary.rb +0 -882
  153. data/test/plugin/test_output_as_standard.rb +0 -374
  154. data/test/plugin/test_owned_by.rb +0 -34
  155. data/test/plugin/test_parser.rb +0 -399
  156. data/test/plugin/test_parser_apache.rb +0 -42
  157. data/test/plugin/test_parser_apache2.rb +0 -47
  158. data/test/plugin/test_parser_apache_error.rb +0 -45
  159. data/test/plugin/test_parser_csv.rb +0 -200
  160. data/test/plugin/test_parser_json.rb +0 -244
  161. data/test/plugin/test_parser_labeled_tsv.rb +0 -160
  162. data/test/plugin/test_parser_msgpack.rb +0 -127
  163. data/test/plugin/test_parser_multiline.rb +0 -111
  164. data/test/plugin/test_parser_nginx.rb +0 -88
  165. data/test/plugin/test_parser_none.rb +0 -52
  166. data/test/plugin/test_parser_regexp.rb +0 -284
  167. data/test/plugin/test_parser_syslog.rb +0 -650
  168. data/test/plugin/test_parser_tsv.rb +0 -122
  169. data/test/plugin/test_sd_file.rb +0 -228
  170. data/test/plugin/test_sd_srv.rb +0 -230
  171. data/test/plugin/test_storage.rb +0 -166
  172. data/test/plugin/test_storage_local.rb +0 -335
  173. data/test/plugin/test_string_util.rb +0 -26
  174. data/test/plugin_helper/data/cert/cert-key.pem +0 -27
  175. data/test/plugin_helper/data/cert/cert-with-CRLF.pem +0 -19
  176. data/test/plugin_helper/data/cert/cert-with-no-newline.pem +0 -19
  177. data/test/plugin_helper/data/cert/cert.pem +0 -19
  178. data/test/plugin_helper/data/cert/cert_chains/ca-cert-key.pem +0 -27
  179. data/test/plugin_helper/data/cert/cert_chains/ca-cert.pem +0 -20
  180. data/test/plugin_helper/data/cert/cert_chains/cert-key.pem +0 -27
  181. data/test/plugin_helper/data/cert/cert_chains/cert.pem +0 -40
  182. data/test/plugin_helper/data/cert/empty.pem +0 -0
  183. data/test/plugin_helper/data/cert/generate_cert.rb +0 -125
  184. data/test/plugin_helper/data/cert/with_ca/ca-cert-key-pass.pem +0 -30
  185. data/test/plugin_helper/data/cert/with_ca/ca-cert-key.pem +0 -27
  186. data/test/plugin_helper/data/cert/with_ca/ca-cert-pass.pem +0 -20
  187. data/test/plugin_helper/data/cert/with_ca/ca-cert.pem +0 -20
  188. data/test/plugin_helper/data/cert/with_ca/cert-key-pass.pem +0 -30
  189. data/test/plugin_helper/data/cert/with_ca/cert-key.pem +0 -27
  190. data/test/plugin_helper/data/cert/with_ca/cert-pass.pem +0 -21
  191. data/test/plugin_helper/data/cert/with_ca/cert.pem +0 -21
  192. data/test/plugin_helper/data/cert/without_ca/cert-key-pass.pem +0 -30
  193. data/test/plugin_helper/data/cert/without_ca/cert-key.pem +0 -27
  194. data/test/plugin_helper/data/cert/without_ca/cert-pass.pem +0 -20
  195. data/test/plugin_helper/data/cert/without_ca/cert.pem +0 -20
  196. data/test/plugin_helper/http_server/test_app.rb +0 -65
  197. data/test/plugin_helper/http_server/test_route.rb +0 -32
  198. data/test/plugin_helper/service_discovery/test_manager.rb +0 -93
  199. data/test/plugin_helper/service_discovery/test_round_robin_balancer.rb +0 -21
  200. data/test/plugin_helper/test_cert_option.rb +0 -25
  201. data/test/plugin_helper/test_child_process.rb +0 -862
  202. data/test/plugin_helper/test_compat_parameters.rb +0 -358
  203. data/test/plugin_helper/test_event_emitter.rb +0 -80
  204. data/test/plugin_helper/test_event_loop.rb +0 -52
  205. data/test/plugin_helper/test_extract.rb +0 -194
  206. data/test/plugin_helper/test_formatter.rb +0 -255
  207. data/test/plugin_helper/test_http_server_helper.rb +0 -372
  208. data/test/plugin_helper/test_inject.rb +0 -561
  209. data/test/plugin_helper/test_metrics.rb +0 -137
  210. data/test/plugin_helper/test_parser.rb +0 -264
  211. data/test/plugin_helper/test_record_accessor.rb +0 -238
  212. data/test/plugin_helper/test_retry_state.rb +0 -1006
  213. data/test/plugin_helper/test_server.rb +0 -1895
  214. data/test/plugin_helper/test_service_discovery.rb +0 -165
  215. data/test/plugin_helper/test_socket.rb +0 -146
  216. data/test/plugin_helper/test_storage.rb +0 -542
  217. data/test/plugin_helper/test_thread.rb +0 -164
  218. data/test/plugin_helper/test_timer.rb +0 -130
  219. data/test/scripts/exec_script.rb +0 -32
  220. data/test/scripts/fluent/plugin/formatter1/formatter_test1.rb +0 -7
  221. data/test/scripts/fluent/plugin/formatter2/formatter_test2.rb +0 -7
  222. data/test/scripts/fluent/plugin/formatter_known.rb +0 -8
  223. data/test/scripts/fluent/plugin/out_test.rb +0 -81
  224. data/test/scripts/fluent/plugin/out_test2.rb +0 -80
  225. data/test/scripts/fluent/plugin/parser_known.rb +0 -4
  226. data/test/test_capability.rb +0 -74
  227. data/test/test_clock.rb +0 -164
  228. data/test/test_config.rb +0 -369
  229. data/test/test_configdsl.rb +0 -148
  230. data/test/test_daemonizer.rb +0 -91
  231. data/test/test_engine.rb +0 -203
  232. data/test/test_event.rb +0 -531
  233. data/test/test_event_router.rb +0 -348
  234. data/test/test_event_time.rb +0 -199
  235. data/test/test_file_wrapper.rb +0 -53
  236. data/test/test_filter.rb +0 -121
  237. data/test/test_fluent_log_event_router.rb +0 -99
  238. data/test/test_formatter.rb +0 -369
  239. data/test/test_input.rb +0 -31
  240. data/test/test_log.rb +0 -1076
  241. data/test/test_match.rb +0 -148
  242. data/test/test_mixin.rb +0 -351
  243. data/test/test_msgpack_factory.rb +0 -50
  244. data/test/test_oj_options.rb +0 -55
  245. data/test/test_output.rb +0 -278
  246. data/test/test_plugin.rb +0 -251
  247. data/test/test_plugin_classes.rb +0 -370
  248. data/test/test_plugin_helper.rb +0 -81
  249. data/test/test_plugin_id.rb +0 -119
  250. data/test/test_process.rb +0 -14
  251. data/test/test_root_agent.rb +0 -951
  252. data/test/test_static_config_analysis.rb +0 -177
  253. data/test/test_supervisor.rb +0 -821
  254. data/test/test_test_drivers.rb +0 -136
  255. data/test/test_time_formatter.rb +0 -301
  256. data/test/test_time_parser.rb +0 -362
  257. data/test/test_tls.rb +0 -65
  258. data/test/test_unique_id.rb +0 -47
  259. data/test/test_variable_store.rb +0 -65
@@ -1,1784 +0,0 @@
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