fluentd-hubspot 0.14.14.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.github/ISSUE_TEMPLATE.md +6 -0
- data/.gitignore +28 -0
- data/.travis.yml +51 -0
- data/AUTHORS +2 -0
- data/CONTRIBUTING.md +42 -0
- data/COPYING +14 -0
- data/ChangeLog +593 -0
- data/Gemfile +9 -0
- data/README.md +76 -0
- data/Rakefile +74 -0
- data/Vagrantfile +17 -0
- data/appveyor.yml +43 -0
- data/bin/fluent-binlog-reader +7 -0
- data/bin/fluent-debug +5 -0
- data/bin/fluent-plugin-config-format +5 -0
- data/bin/fluent-plugin-generate +5 -0
- data/code-of-conduct.md +3 -0
- data/example/copy_roundrobin.conf +39 -0
- data/example/filter_stdout.conf +22 -0
- data/example/in_dummy_blocks.conf +17 -0
- data/example/in_dummy_with_compression.conf +23 -0
- data/example/in_forward.conf +14 -0
- data/example/in_forward_client.conf +37 -0
- data/example/in_forward_shared_key.conf +15 -0
- data/example/in_forward_tls.conf +14 -0
- data/example/in_forward_users.conf +24 -0
- data/example/in_forward_workers.conf +21 -0
- data/example/in_http.conf +14 -0
- data/example/in_out_forward.conf +17 -0
- data/example/in_syslog.conf +15 -0
- data/example/in_tail.conf +14 -0
- data/example/in_tcp.conf +13 -0
- data/example/in_udp.conf +13 -0
- data/example/logevents.conf +25 -0
- data/example/multi_filters.conf +61 -0
- data/example/out_copy.conf +20 -0
- data/example/out_exec_filter.conf +42 -0
- data/example/out_file.conf +13 -0
- data/example/out_forward.conf +35 -0
- data/example/out_forward_buf_file.conf +23 -0
- data/example/out_forward_client.conf +109 -0
- data/example/out_forward_heartbeat_none.conf +16 -0
- data/example/out_forward_shared_key.conf +36 -0
- data/example/out_forward_tls.conf +18 -0
- data/example/out_forward_users.conf +65 -0
- data/example/out_null.conf +36 -0
- data/example/secondary_file.conf +41 -0
- data/example/suppress_config_dump.conf +7 -0
- data/example/v0_12_filter.conf +78 -0
- data/example/v1_literal_example.conf +36 -0
- data/fluent.conf +139 -0
- data/fluentd.gemspec +51 -0
- data/lib/fluent/agent.rb +163 -0
- data/lib/fluent/clock.rb +62 -0
- data/lib/fluent/command/binlog_reader.rb +234 -0
- data/lib/fluent/command/bundler_injection.rb +45 -0
- data/lib/fluent/command/cat.rb +330 -0
- data/lib/fluent/command/debug.rb +102 -0
- data/lib/fluent/command/fluentd.rb +301 -0
- data/lib/fluent/command/plugin_config_formatter.rb +258 -0
- data/lib/fluent/command/plugin_generator.rb +301 -0
- data/lib/fluent/compat/call_super_mixin.rb +67 -0
- data/lib/fluent/compat/detach_process_mixin.rb +25 -0
- data/lib/fluent/compat/exec_util.rb +129 -0
- data/lib/fluent/compat/file_util.rb +54 -0
- data/lib/fluent/compat/filter.rb +68 -0
- data/lib/fluent/compat/formatter.rb +111 -0
- data/lib/fluent/compat/formatter_utils.rb +85 -0
- data/lib/fluent/compat/handle_tag_and_time_mixin.rb +62 -0
- data/lib/fluent/compat/handle_tag_name_mixin.rb +53 -0
- data/lib/fluent/compat/input.rb +59 -0
- data/lib/fluent/compat/output.rb +728 -0
- data/lib/fluent/compat/output_chain.rb +60 -0
- data/lib/fluent/compat/parser.rb +310 -0
- data/lib/fluent/compat/parser_utils.rb +40 -0
- data/lib/fluent/compat/propagate_default.rb +62 -0
- data/lib/fluent/compat/record_filter_mixin.rb +34 -0
- data/lib/fluent/compat/set_tag_key_mixin.rb +50 -0
- data/lib/fluent/compat/set_time_key_mixin.rb +69 -0
- data/lib/fluent/compat/socket_util.rb +165 -0
- data/lib/fluent/compat/string_util.rb +34 -0
- data/lib/fluent/compat/structured_format_mixin.rb +26 -0
- data/lib/fluent/compat/type_converter.rb +90 -0
- data/lib/fluent/config.rb +56 -0
- data/lib/fluent/config/basic_parser.rb +123 -0
- data/lib/fluent/config/configure_proxy.rb +418 -0
- data/lib/fluent/config/dsl.rb +149 -0
- data/lib/fluent/config/element.rb +218 -0
- data/lib/fluent/config/error.rb +26 -0
- data/lib/fluent/config/literal_parser.rb +251 -0
- data/lib/fluent/config/parser.rb +107 -0
- data/lib/fluent/config/section.rb +223 -0
- data/lib/fluent/config/types.rb +136 -0
- data/lib/fluent/config/v1_parser.rb +190 -0
- data/lib/fluent/configurable.rb +200 -0
- data/lib/fluent/daemon.rb +15 -0
- data/lib/fluent/engine.rb +266 -0
- data/lib/fluent/env.rb +28 -0
- data/lib/fluent/error.rb +30 -0
- data/lib/fluent/event.rb +334 -0
- data/lib/fluent/event_router.rb +269 -0
- data/lib/fluent/filter.rb +21 -0
- data/lib/fluent/formatter.rb +23 -0
- data/lib/fluent/input.rb +21 -0
- data/lib/fluent/label.rb +46 -0
- data/lib/fluent/load.rb +35 -0
- data/lib/fluent/log.rb +546 -0
- data/lib/fluent/match.rb +178 -0
- data/lib/fluent/mixin.rb +31 -0
- data/lib/fluent/msgpack_factory.rb +62 -0
- data/lib/fluent/output.rb +29 -0
- data/lib/fluent/output_chain.rb +23 -0
- data/lib/fluent/parser.rb +23 -0
- data/lib/fluent/plugin.rb +183 -0
- data/lib/fluent/plugin/bare_output.rb +63 -0
- data/lib/fluent/plugin/base.rb +165 -0
- data/lib/fluent/plugin/buf_file.rb +184 -0
- data/lib/fluent/plugin/buf_memory.rb +34 -0
- data/lib/fluent/plugin/buffer.rb +617 -0
- data/lib/fluent/plugin/buffer/chunk.rb +221 -0
- data/lib/fluent/plugin/buffer/file_chunk.rb +364 -0
- data/lib/fluent/plugin/buffer/memory_chunk.rb +90 -0
- data/lib/fluent/plugin/compressable.rb +92 -0
- data/lib/fluent/plugin/exec_util.rb +22 -0
- data/lib/fluent/plugin/file_util.rb +22 -0
- data/lib/fluent/plugin/file_wrapper.rb +120 -0
- data/lib/fluent/plugin/filter.rb +93 -0
- data/lib/fluent/plugin/filter_grep.rb +75 -0
- data/lib/fluent/plugin/filter_parser.rb +119 -0
- data/lib/fluent/plugin/filter_record_transformer.rb +322 -0
- data/lib/fluent/plugin/filter_stdout.rb +53 -0
- data/lib/fluent/plugin/formatter.rb +50 -0
- data/lib/fluent/plugin/formatter_csv.rb +52 -0
- data/lib/fluent/plugin/formatter_hash.rb +33 -0
- data/lib/fluent/plugin/formatter_json.rb +55 -0
- data/lib/fluent/plugin/formatter_ltsv.rb +42 -0
- data/lib/fluent/plugin/formatter_msgpack.rb +33 -0
- data/lib/fluent/plugin/formatter_out_file.rb +51 -0
- data/lib/fluent/plugin/formatter_single_value.rb +34 -0
- data/lib/fluent/plugin/formatter_stdout.rb +75 -0
- data/lib/fluent/plugin/formatter_tsv.rb +34 -0
- data/lib/fluent/plugin/in_debug_agent.rb +64 -0
- data/lib/fluent/plugin/in_dummy.rb +139 -0
- data/lib/fluent/plugin/in_exec.rb +108 -0
- data/lib/fluent/plugin/in_forward.rb +455 -0
- data/lib/fluent/plugin/in_gc_stat.rb +56 -0
- data/lib/fluent/plugin/in_http.rb +433 -0
- data/lib/fluent/plugin/in_monitor_agent.rb +448 -0
- data/lib/fluent/plugin/in_object_space.rb +93 -0
- data/lib/fluent/plugin/in_syslog.rb +209 -0
- data/lib/fluent/plugin/in_tail.rb +905 -0
- data/lib/fluent/plugin/in_tcp.rb +85 -0
- data/lib/fluent/plugin/in_udp.rb +81 -0
- data/lib/fluent/plugin/in_unix.rb +201 -0
- data/lib/fluent/plugin/input.rb +37 -0
- data/lib/fluent/plugin/multi_output.rb +157 -0
- data/lib/fluent/plugin/out_copy.rb +46 -0
- data/lib/fluent/plugin/out_exec.rb +105 -0
- data/lib/fluent/plugin/out_exec_filter.rb +317 -0
- data/lib/fluent/plugin/out_file.rb +302 -0
- data/lib/fluent/plugin/out_forward.rb +912 -0
- data/lib/fluent/plugin/out_null.rb +74 -0
- data/lib/fluent/plugin/out_relabel.rb +32 -0
- data/lib/fluent/plugin/out_roundrobin.rb +84 -0
- data/lib/fluent/plugin/out_secondary_file.rb +133 -0
- data/lib/fluent/plugin/out_stdout.rb +75 -0
- data/lib/fluent/plugin/out_stream.rb +130 -0
- data/lib/fluent/plugin/output.rb +1291 -0
- data/lib/fluent/plugin/owned_by_mixin.rb +42 -0
- data/lib/fluent/plugin/parser.rb +191 -0
- data/lib/fluent/plugin/parser_apache.rb +28 -0
- data/lib/fluent/plugin/parser_apache2.rb +84 -0
- data/lib/fluent/plugin/parser_apache_error.rb +26 -0
- data/lib/fluent/plugin/parser_csv.rb +39 -0
- data/lib/fluent/plugin/parser_json.rb +81 -0
- data/lib/fluent/plugin/parser_ltsv.rb +42 -0
- data/lib/fluent/plugin/parser_msgpack.rb +50 -0
- data/lib/fluent/plugin/parser_multiline.rb +105 -0
- data/lib/fluent/plugin/parser_nginx.rb +28 -0
- data/lib/fluent/plugin/parser_none.rb +36 -0
- data/lib/fluent/plugin/parser_regexp.rb +63 -0
- data/lib/fluent/plugin/parser_syslog.rb +121 -0
- data/lib/fluent/plugin/parser_tsv.rb +42 -0
- data/lib/fluent/plugin/socket_util.rb +22 -0
- data/lib/fluent/plugin/storage.rb +84 -0
- data/lib/fluent/plugin/storage_local.rb +159 -0
- data/lib/fluent/plugin/string_util.rb +22 -0
- data/lib/fluent/plugin_helper.rb +70 -0
- data/lib/fluent/plugin_helper/cert_option.rb +159 -0
- data/lib/fluent/plugin_helper/child_process.rb +364 -0
- data/lib/fluent/plugin_helper/compat_parameters.rb +331 -0
- data/lib/fluent/plugin_helper/event_emitter.rb +93 -0
- data/lib/fluent/plugin_helper/event_loop.rb +161 -0
- data/lib/fluent/plugin_helper/extract.rb +104 -0
- data/lib/fluent/plugin_helper/formatter.rb +147 -0
- data/lib/fluent/plugin_helper/inject.rb +151 -0
- data/lib/fluent/plugin_helper/parser.rb +147 -0
- data/lib/fluent/plugin_helper/retry_state.rb +201 -0
- data/lib/fluent/plugin_helper/server.rb +738 -0
- data/lib/fluent/plugin_helper/socket.rb +241 -0
- data/lib/fluent/plugin_helper/socket_option.rb +69 -0
- data/lib/fluent/plugin_helper/storage.rb +349 -0
- data/lib/fluent/plugin_helper/thread.rb +179 -0
- data/lib/fluent/plugin_helper/timer.rb +91 -0
- data/lib/fluent/plugin_id.rb +80 -0
- data/lib/fluent/process.rb +22 -0
- data/lib/fluent/registry.rb +116 -0
- data/lib/fluent/root_agent.rb +323 -0
- data/lib/fluent/rpc.rb +94 -0
- data/lib/fluent/supervisor.rb +741 -0
- data/lib/fluent/system_config.rb +159 -0
- data/lib/fluent/test.rb +58 -0
- data/lib/fluent/test/base.rb +78 -0
- data/lib/fluent/test/driver/base.rb +224 -0
- data/lib/fluent/test/driver/base_owned.rb +70 -0
- data/lib/fluent/test/driver/base_owner.rb +135 -0
- data/lib/fluent/test/driver/event_feeder.rb +98 -0
- data/lib/fluent/test/driver/filter.rb +57 -0
- data/lib/fluent/test/driver/formatter.rb +30 -0
- data/lib/fluent/test/driver/input.rb +31 -0
- data/lib/fluent/test/driver/multi_output.rb +53 -0
- data/lib/fluent/test/driver/output.rb +102 -0
- data/lib/fluent/test/driver/parser.rb +30 -0
- data/lib/fluent/test/driver/test_event_router.rb +45 -0
- data/lib/fluent/test/filter_test.rb +77 -0
- data/lib/fluent/test/formatter_test.rb +65 -0
- data/lib/fluent/test/helpers.rb +134 -0
- data/lib/fluent/test/input_test.rb +174 -0
- data/lib/fluent/test/log.rb +79 -0
- data/lib/fluent/test/output_test.rb +156 -0
- data/lib/fluent/test/parser_test.rb +70 -0
- data/lib/fluent/test/startup_shutdown.rb +46 -0
- data/lib/fluent/time.rb +412 -0
- data/lib/fluent/timezone.rb +133 -0
- data/lib/fluent/unique_id.rb +39 -0
- data/lib/fluent/version.rb +21 -0
- data/lib/fluent/winsvc.rb +71 -0
- data/templates/new_gem/Gemfile +3 -0
- data/templates/new_gem/README.md.erb +43 -0
- data/templates/new_gem/Rakefile +13 -0
- data/templates/new_gem/fluent-plugin.gemspec.erb +27 -0
- data/templates/new_gem/lib/fluent/plugin/filter.rb.erb +14 -0
- data/templates/new_gem/lib/fluent/plugin/formatter.rb.erb +14 -0
- data/templates/new_gem/lib/fluent/plugin/input.rb.erb +11 -0
- data/templates/new_gem/lib/fluent/plugin/output.rb.erb +11 -0
- data/templates/new_gem/lib/fluent/plugin/parser.rb.erb +15 -0
- data/templates/new_gem/test/helper.rb.erb +8 -0
- data/templates/new_gem/test/plugin/test_filter.rb.erb +18 -0
- data/templates/new_gem/test/plugin/test_formatter.rb.erb +18 -0
- data/templates/new_gem/test/plugin/test_input.rb.erb +18 -0
- data/templates/new_gem/test/plugin/test_output.rb.erb +18 -0
- data/templates/new_gem/test/plugin/test_parser.rb.erb +18 -0
- data/templates/plugin_config_formatter/param.md-compact.erb +25 -0
- data/templates/plugin_config_formatter/param.md.erb +34 -0
- data/templates/plugin_config_formatter/section.md.erb +12 -0
- data/test/command/test_binlog_reader.rb +346 -0
- data/test/command/test_fluentd.rb +618 -0
- data/test/command/test_plugin_config_formatter.rb +275 -0
- data/test/command/test_plugin_generator.rb +66 -0
- data/test/compat/test_calls_super.rb +166 -0
- data/test/compat/test_parser.rb +92 -0
- data/test/config/assertions.rb +42 -0
- data/test/config/test_config_parser.rb +513 -0
- data/test/config/test_configurable.rb +1587 -0
- data/test/config/test_configure_proxy.rb +566 -0
- data/test/config/test_dsl.rb +415 -0
- data/test/config/test_element.rb +403 -0
- data/test/config/test_literal_parser.rb +297 -0
- data/test/config/test_section.rb +184 -0
- data/test/config/test_system_config.rb +168 -0
- data/test/config/test_types.rb +191 -0
- data/test/helper.rb +153 -0
- data/test/plugin/data/2010/01/20100102-030405.log +0 -0
- data/test/plugin/data/2010/01/20100102-030406.log +0 -0
- data/test/plugin/data/2010/01/20100102.log +0 -0
- data/test/plugin/data/log/bar +0 -0
- data/test/plugin/data/log/foo/bar.log +0 -0
- data/test/plugin/data/log/foo/bar2 +0 -0
- data/test/plugin/data/log/test.log +0 -0
- data/test/plugin/test_bare_output.rb +118 -0
- data/test/plugin/test_base.rb +115 -0
- data/test/plugin/test_buf_file.rb +843 -0
- data/test/plugin/test_buf_memory.rb +42 -0
- data/test/plugin/test_buffer.rb +1220 -0
- data/test/plugin/test_buffer_chunk.rb +198 -0
- data/test/plugin/test_buffer_file_chunk.rb +844 -0
- data/test/plugin/test_buffer_memory_chunk.rb +338 -0
- data/test/plugin/test_compressable.rb +84 -0
- data/test/plugin/test_file_util.rb +96 -0
- data/test/plugin/test_filter.rb +357 -0
- data/test/plugin/test_filter_grep.rb +119 -0
- data/test/plugin/test_filter_parser.rb +700 -0
- data/test/plugin/test_filter_record_transformer.rb +556 -0
- data/test/plugin/test_filter_stdout.rb +202 -0
- data/test/plugin/test_formatter_csv.rb +111 -0
- data/test/plugin/test_formatter_hash.rb +35 -0
- data/test/plugin/test_formatter_json.rb +51 -0
- data/test/plugin/test_formatter_ltsv.rb +59 -0
- data/test/plugin/test_formatter_msgpack.rb +28 -0
- data/test/plugin/test_formatter_out_file.rb +95 -0
- data/test/plugin/test_formatter_single_value.rb +38 -0
- data/test/plugin/test_in_debug_agent.rb +28 -0
- data/test/plugin/test_in_dummy.rb +192 -0
- data/test/plugin/test_in_exec.rb +245 -0
- data/test/plugin/test_in_forward.rb +1120 -0
- data/test/plugin/test_in_gc_stat.rb +39 -0
- data/test/plugin/test_in_http.rb +588 -0
- data/test/plugin/test_in_monitor_agent.rb +516 -0
- data/test/plugin/test_in_object_space.rb +64 -0
- data/test/plugin/test_in_syslog.rb +271 -0
- data/test/plugin/test_in_tail.rb +1216 -0
- data/test/plugin/test_in_tcp.rb +118 -0
- data/test/plugin/test_in_udp.rb +152 -0
- data/test/plugin/test_in_unix.rb +126 -0
- data/test/plugin/test_input.rb +126 -0
- data/test/plugin/test_multi_output.rb +180 -0
- data/test/plugin/test_out_copy.rb +160 -0
- data/test/plugin/test_out_exec.rb +310 -0
- data/test/plugin/test_out_exec_filter.rb +613 -0
- data/test/plugin/test_out_file.rb +873 -0
- data/test/plugin/test_out_forward.rb +685 -0
- data/test/plugin/test_out_null.rb +105 -0
- data/test/plugin/test_out_relabel.rb +28 -0
- data/test/plugin/test_out_roundrobin.rb +146 -0
- data/test/plugin/test_out_secondary_file.rb +442 -0
- data/test/plugin/test_out_stdout.rb +170 -0
- data/test/plugin/test_out_stream.rb +93 -0
- data/test/plugin/test_output.rb +870 -0
- data/test/plugin/test_output_as_buffered.rb +1932 -0
- data/test/plugin/test_output_as_buffered_compress.rb +165 -0
- data/test/plugin/test_output_as_buffered_overflow.rb +250 -0
- data/test/plugin/test_output_as_buffered_retries.rb +839 -0
- data/test/plugin/test_output_as_buffered_secondary.rb +877 -0
- data/test/plugin/test_output_as_standard.rb +374 -0
- data/test/plugin/test_owned_by.rb +35 -0
- data/test/plugin/test_parser.rb +359 -0
- data/test/plugin/test_parser_apache.rb +42 -0
- data/test/plugin/test_parser_apache2.rb +46 -0
- data/test/plugin/test_parser_apache_error.rb +45 -0
- data/test/plugin/test_parser_csv.rb +103 -0
- data/test/plugin/test_parser_json.rb +114 -0
- data/test/plugin/test_parser_labeled_tsv.rb +128 -0
- data/test/plugin/test_parser_multiline.rb +100 -0
- data/test/plugin/test_parser_nginx.rb +48 -0
- data/test/plugin/test_parser_none.rb +52 -0
- data/test/plugin/test_parser_regexp.rb +281 -0
- data/test/plugin/test_parser_syslog.rb +242 -0
- data/test/plugin/test_parser_tsv.rb +122 -0
- data/test/plugin/test_storage.rb +167 -0
- data/test/plugin/test_storage_local.rb +335 -0
- data/test/plugin/test_string_util.rb +26 -0
- data/test/plugin_helper/test_child_process.rb +794 -0
- data/test/plugin_helper/test_compat_parameters.rb +331 -0
- data/test/plugin_helper/test_event_emitter.rb +51 -0
- data/test/plugin_helper/test_event_loop.rb +52 -0
- data/test/plugin_helper/test_extract.rb +194 -0
- data/test/plugin_helper/test_formatter.rb +255 -0
- data/test/plugin_helper/test_inject.rb +519 -0
- data/test/plugin_helper/test_parser.rb +264 -0
- data/test/plugin_helper/test_retry_state.rb +422 -0
- data/test/plugin_helper/test_server.rb +1677 -0
- data/test/plugin_helper/test_storage.rb +542 -0
- data/test/plugin_helper/test_thread.rb +164 -0
- data/test/plugin_helper/test_timer.rb +132 -0
- data/test/scripts/exec_script.rb +32 -0
- data/test/scripts/fluent/plugin/formatter1/formatter_test1.rb +7 -0
- data/test/scripts/fluent/plugin/formatter2/formatter_test2.rb +7 -0
- data/test/scripts/fluent/plugin/formatter_known.rb +8 -0
- data/test/scripts/fluent/plugin/out_test.rb +81 -0
- data/test/scripts/fluent/plugin/out_test2.rb +80 -0
- data/test/scripts/fluent/plugin/parser_known.rb +4 -0
- data/test/test_clock.rb +164 -0
- data/test/test_config.rb +179 -0
- data/test/test_configdsl.rb +148 -0
- data/test/test_event.rb +515 -0
- data/test/test_event_router.rb +331 -0
- data/test/test_event_time.rb +186 -0
- data/test/test_filter.rb +121 -0
- data/test/test_formatter.rb +312 -0
- data/test/test_input.rb +31 -0
- data/test/test_log.rb +828 -0
- data/test/test_match.rb +137 -0
- data/test/test_mixin.rb +351 -0
- data/test/test_output.rb +273 -0
- data/test/test_plugin.rb +251 -0
- data/test/test_plugin_classes.rb +253 -0
- data/test/test_plugin_helper.rb +81 -0
- data/test/test_plugin_id.rb +101 -0
- data/test/test_process.rb +14 -0
- data/test/test_root_agent.rb +611 -0
- data/test/test_supervisor.rb +373 -0
- data/test/test_test_drivers.rb +135 -0
- data/test/test_time_formatter.rb +282 -0
- data/test/test_time_parser.rb +211 -0
- data/test/test_unique_id.rb +47 -0
- metadata +898 -0
@@ -0,0 +1,1587 @@
|
|
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 Base2 < Base1
|
34
|
+
config_set_default :name2, "base2"
|
35
|
+
config_set_default :name4, "base2"
|
36
|
+
config_set_default :opt1, :bar
|
37
|
+
config_param :name5, :string
|
38
|
+
config_param :name6, :string, default: "base2"
|
39
|
+
config_param :opt3, :enum, list: [:a, :b]
|
40
|
+
|
41
|
+
def get_all
|
42
|
+
ary = super
|
43
|
+
ary + [@name5, @name6]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
class Base3 < Base2
|
48
|
+
config_set_default :opt3, :a
|
49
|
+
config_section :node do
|
50
|
+
config_param :name, :string, default: "node"
|
51
|
+
config_param :type, :string
|
52
|
+
end
|
53
|
+
config_section :branch, required: true, multi: true do
|
54
|
+
config_argument :name, :string
|
55
|
+
config_param :size, :integer, default: 10
|
56
|
+
config_section :leaf, required: false, multi: true do
|
57
|
+
config_param :weight, :integer
|
58
|
+
config_section :worm, param_name: 'worms', multi: true do
|
59
|
+
config_param :type, :string, default: 'ladybird'
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def get_all
|
65
|
+
ary = super
|
66
|
+
ary + [@branch]
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
class Base4 < Base2
|
71
|
+
config_set_default :opt3, :a
|
72
|
+
config_section :node, param_name: :nodes do
|
73
|
+
config_argument :num, :integer
|
74
|
+
config_param :name, :string, default: "node"
|
75
|
+
config_param :type, :string, default: "b4"
|
76
|
+
end
|
77
|
+
config_section :description1, required: false, multi: false do
|
78
|
+
config_argument :note, :string, default: "desc1"
|
79
|
+
config_param :text, :string
|
80
|
+
end
|
81
|
+
config_section :description2, required: true, multi: false do
|
82
|
+
config_argument :note, :string, default: "desc2"
|
83
|
+
config_param :text, :string
|
84
|
+
end
|
85
|
+
config_section :description3, required: true, multi: true do
|
86
|
+
config_argument :note, default: "desc3" do |val|
|
87
|
+
"desc3: #{val}"
|
88
|
+
end
|
89
|
+
config_param :text, :string
|
90
|
+
end
|
91
|
+
|
92
|
+
def get_all
|
93
|
+
ary = super
|
94
|
+
ary + [@nodes, @description1, @description2, @description3]
|
95
|
+
end
|
96
|
+
end
|
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
|
+
|
142
|
+
class Example0
|
143
|
+
include Fluent::Configurable
|
144
|
+
|
145
|
+
config_param :stringvalue, :string
|
146
|
+
config_param :boolvalue, :bool
|
147
|
+
config_param :integervalue, :integer
|
148
|
+
config_param :sizevalue, :size
|
149
|
+
config_param :timevalue, :time
|
150
|
+
config_param :floatvalue, :float
|
151
|
+
config_param :hashvalue, :hash
|
152
|
+
config_param :arrayvalue, :array
|
153
|
+
end
|
154
|
+
|
155
|
+
class Example1
|
156
|
+
include Fluent::Configurable
|
157
|
+
|
158
|
+
config_param :name, :string, alias: :fullname
|
159
|
+
config_param :bool, :bool, alias: :flag
|
160
|
+
config_section :detail, required: false, multi: false, alias: "information" do
|
161
|
+
config_param :address, :string, default: "x"
|
162
|
+
end
|
163
|
+
|
164
|
+
def get_all
|
165
|
+
[@name, @detail]
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
class Example3
|
170
|
+
include Fluent::Configurable
|
171
|
+
|
172
|
+
config_param :age, :integer, default: 10
|
173
|
+
|
174
|
+
config_section :appendix, required: true, multi: false, final: true do
|
175
|
+
config_param :type, :string
|
176
|
+
config_param :name, :string, default: "x"
|
177
|
+
end
|
178
|
+
|
179
|
+
def get_all
|
180
|
+
[@name, @detail]
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
class Example5
|
185
|
+
include Fluent::Configurable
|
186
|
+
|
187
|
+
config_param :normal_param, :string
|
188
|
+
config_param :secret_param, :string, secret: true
|
189
|
+
|
190
|
+
config_section :section do
|
191
|
+
config_param :normal_param2, :string
|
192
|
+
config_param :secret_param2, :string, secret: true
|
193
|
+
end
|
194
|
+
end
|
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
|
409
|
+
class UnRecommended
|
410
|
+
include Fluent::Configurable
|
411
|
+
attr_accessor :log
|
412
|
+
config_param :key1, :string, default: 'deprecated', deprecated: "key1 will be removed."
|
413
|
+
config_param :key2, :string, default: 'obsoleted', obsoleted: "key2 has been removed."
|
414
|
+
end
|
415
|
+
end
|
416
|
+
|
417
|
+
module Fluent::Config
|
418
|
+
class TestConfigurable < ::Test::Unit::TestCase
|
419
|
+
sub_test_case 'class defined without config_section' do
|
420
|
+
sub_test_case '#initialize' do
|
421
|
+
test 'create instance methods and default values by config_param and config_set_default' do
|
422
|
+
obj1 = ConfigurableSpec::Base1.new
|
423
|
+
assert_equal("node", obj1.node)
|
424
|
+
assert_false(obj1.flag1)
|
425
|
+
assert_true(obj1.flag2)
|
426
|
+
assert_nil(obj1.name1)
|
427
|
+
assert_nil(obj1.name2)
|
428
|
+
assert_equal("base1", obj1.name3)
|
429
|
+
assert_equal("base1", obj1.name4)
|
430
|
+
assert_nil(obj1.opt1)
|
431
|
+
assert_equal(:foo, obj1.opt2)
|
432
|
+
end
|
433
|
+
|
434
|
+
test 'create instance methods and default values overwritten by sub class definition' do
|
435
|
+
obj2 = ConfigurableSpec::Base2.new
|
436
|
+
assert_equal("node", obj2.node)
|
437
|
+
assert_false(obj2.flag1)
|
438
|
+
assert_true(obj2.flag2)
|
439
|
+
assert_nil(obj2.name1)
|
440
|
+
assert_equal("base2", obj2.name2)
|
441
|
+
assert_equal("base1", obj2.name3)
|
442
|
+
assert_equal("base2", obj2.name4)
|
443
|
+
assert_nil(obj2.name5)
|
444
|
+
assert_equal("base2", obj2.name6)
|
445
|
+
assert_equal(:bar, obj2.opt1)
|
446
|
+
assert_equal(:foo, obj2.opt2)
|
447
|
+
end
|
448
|
+
end
|
449
|
+
|
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
|
471
|
+
end
|
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
|
506
|
+
test 'returns configurable object itself' do
|
507
|
+
b2 = ConfigurableSpec::Base2.new
|
508
|
+
assert_instance_of(ConfigurableSpec::Base2, b2.configure(config_element("", "", {"name1" => "t1", "name5" => "t5", "opt3" => "a"})))
|
509
|
+
end
|
510
|
+
|
511
|
+
test 'raise errors without any specifications for param without defaults' do
|
512
|
+
b2 = ConfigurableSpec::Base2.new
|
513
|
+
assert_raise(Fluent::ConfigError) { b2.configure(config_element("", "", {})) }
|
514
|
+
assert_raise(Fluent::ConfigError) { b2.configure(config_element("", "", {"name1" => "t1"})) }
|
515
|
+
assert_raise(Fluent::ConfigError) { b2.configure(config_element("", "", {"name5" => "t5"})) }
|
516
|
+
assert_raise(Fluent::ConfigError) { b2.configure(config_element("", "", {"name1" => "t1", "name5" => "t5"})) }
|
517
|
+
assert_nothing_raised { b2.configure(config_element("", "", {"name1" => "t1", "name5" => "t5", "opt3" => "a"})) }
|
518
|
+
|
519
|
+
assert_equal(["node", false, true, "t1", "base2", "base1", "base2", "t5", "base2"], b2.get_all)
|
520
|
+
assert_equal(:a, b2.opt3)
|
521
|
+
end
|
522
|
+
|
523
|
+
test 'can configure bool values' do
|
524
|
+
b2a = ConfigurableSpec::Base2.new
|
525
|
+
assert_nothing_raised { b2a.configure(config_element("", "", {"flag1" => "true", "flag2" => "yes", "name1" => "t1", "name5" => "t5", "opt3" => "a"})) }
|
526
|
+
assert_true(b2a.flag1)
|
527
|
+
assert_true(b2a.flag2)
|
528
|
+
|
529
|
+
b2b = ConfigurableSpec::Base2.new
|
530
|
+
assert_nothing_raised { b2b.configure(config_element("", "", {"flag1" => false, "flag2" => "no", "name1" => "t1", "name5" => "t5", "opt3" => "a"})) }
|
531
|
+
assert_false(b2b.flag1)
|
532
|
+
assert_false(b2b.flag2)
|
533
|
+
end
|
534
|
+
|
535
|
+
test 'overwrites values of defaults' do
|
536
|
+
b2 = ConfigurableSpec::Base2.new
|
537
|
+
b2.configure(config_element("", "", {"name1" => "t1", "name2" => "t2", "name3" => "t3", "name4" => "t4", "name5" => "t5", "opt1" => "foo", "opt3" => "b"}))
|
538
|
+
assert_equal("t1", b2.name1)
|
539
|
+
assert_equal("t2", b2.name2)
|
540
|
+
assert_equal("t3", b2.name3)
|
541
|
+
assert_equal("t4", b2.name4)
|
542
|
+
assert_equal("t5", b2.name5)
|
543
|
+
assert_equal("base2", b2.name6)
|
544
|
+
assert_equal(:foo, b2.opt1)
|
545
|
+
assert_equal(:b, b2.opt3)
|
546
|
+
|
547
|
+
assert_equal(["node", false, true, "t1", "t2", "t3", "t4", "t5", "base2"], b2.get_all)
|
548
|
+
end
|
549
|
+
|
550
|
+
test 'enum type rejects values which does not exist in list' do
|
551
|
+
default = config_element("", "", {"name1" => "t1", "name2" => "t2", "name3" => "t3", "name4" => "t4", "name5" => "t5", "opt1" => "foo", "opt3" => "b"})
|
552
|
+
|
553
|
+
b2 = ConfigurableSpec::Base2.new
|
554
|
+
assert_nothing_raised { b2.configure(default) }
|
555
|
+
assert_raise(Fluent::ConfigError) { b2.configure(default.merge({"opt1" => "bazz"})) }
|
556
|
+
assert_raise(Fluent::ConfigError) { b2.configure(default.merge({"opt2" => "fooooooo"})) }
|
557
|
+
assert_raise(Fluent::ConfigError) { b2.configure(default.merge({"opt3" => "c"})) }
|
558
|
+
end
|
559
|
+
|
560
|
+
sub_test_case 'default values should be duplicated before touched in plugin code' do
|
561
|
+
test 'default object should be dupped for cases configured twice' do
|
562
|
+
x6a = ConfigurableSpec::Example6.new
|
563
|
+
assert_nothing_raised { x6a.configure(config_element("")) }
|
564
|
+
assert_equal({}, x6a.obj1)
|
565
|
+
assert_equal([], x6a.obj2)
|
566
|
+
|
567
|
+
x6b = ConfigurableSpec::Example6.new
|
568
|
+
assert_nothing_raised { x6b.configure(config_element("")) }
|
569
|
+
assert_equal({}, x6b.obj1)
|
570
|
+
assert_equal([], x6b.obj2)
|
571
|
+
|
572
|
+
assert { x6a.obj1.object_id != x6b.obj1.object_id }
|
573
|
+
assert { x6a.obj2.object_id != x6b.obj2.object_id }
|
574
|
+
|
575
|
+
x6c = ConfigurableSpec::Example6.new
|
576
|
+
assert_nothing_raised { x6c.configure(config_element("")) }
|
577
|
+
assert_equal({}, x6c.obj1)
|
578
|
+
assert_equal([], x6c.obj2)
|
579
|
+
|
580
|
+
x6c.obj1['k'] = 'v'
|
581
|
+
x6c.obj2 << 'v'
|
582
|
+
|
583
|
+
assert_equal({'k' => 'v'}, x6c.obj1)
|
584
|
+
assert_equal(['v'], x6c.obj2)
|
585
|
+
|
586
|
+
assert_equal({}, x6a.obj1)
|
587
|
+
assert_equal([], x6a.obj2)
|
588
|
+
end
|
589
|
+
end
|
590
|
+
end
|
591
|
+
end
|
592
|
+
|
593
|
+
sub_test_case 'class defined with config_section' do
|
594
|
+
sub_test_case '#initialize' do
|
595
|
+
test 'create instance methods and default values as nil for params from config_section specified as non-multi' do
|
596
|
+
b4 = ConfigurableSpec::Base4.new
|
597
|
+
assert_nil(b4.description1)
|
598
|
+
assert_nil(b4.description2)
|
599
|
+
end
|
600
|
+
|
601
|
+
test 'create instance methods and default values as [] for params from config_section specified as multi' do
|
602
|
+
b4 = ConfigurableSpec::Base4.new
|
603
|
+
assert_equal([], b4.description3)
|
604
|
+
end
|
605
|
+
|
606
|
+
test 'overwrite base class definition by config_section of sub class definition' do
|
607
|
+
b3 = ConfigurableSpec::Base3.new
|
608
|
+
assert_equal([], b3.node)
|
609
|
+
end
|
610
|
+
|
611
|
+
test 'create instance methods and default values by param_name' do
|
612
|
+
b4 = ConfigurableSpec::Base4.new
|
613
|
+
assert_equal([], b4.nodes)
|
614
|
+
assert_equal("node", b4.node)
|
615
|
+
end
|
616
|
+
|
617
|
+
test 'create non-required and multi without any specifications' do
|
618
|
+
b3 = ConfigurableSpec::Base3.new
|
619
|
+
assert_false(b3.class.merged_configure_proxy.sections[:node].required?)
|
620
|
+
assert_true(b3.class.merged_configure_proxy.sections[:node].multi?)
|
621
|
+
end
|
622
|
+
end
|
623
|
+
|
624
|
+
sub_test_case '#configured_section_create' do
|
625
|
+
test 'raises configuration error if required param exists but no configuration element is specified' do
|
626
|
+
obj = ConfigurableSpec::Base4.new
|
627
|
+
assert_raise(Fluent::ConfigError.new("'<node ARG>' section requires argument")) do
|
628
|
+
obj.configured_section_create(:node)
|
629
|
+
end
|
630
|
+
assert_raise(Fluent::ConfigError.new("'text' parameter is required")) do
|
631
|
+
obj.configured_section_create(:description1)
|
632
|
+
end
|
633
|
+
end
|
634
|
+
|
635
|
+
test 'creates any defined section with default values if name is nil and config is not specified' do
|
636
|
+
obj = ConfigurableSpec::Base4Safe.new
|
637
|
+
node = obj.configured_section_create(:node)
|
638
|
+
assert_equal 0, node.num
|
639
|
+
assert_equal "node", node.name
|
640
|
+
assert_equal "b4", node.type
|
641
|
+
|
642
|
+
desc1 = obj.configured_section_create(:description1)
|
643
|
+
assert_equal "desc1", desc1.note
|
644
|
+
assert_equal "teeeext", desc1.text
|
645
|
+
end
|
646
|
+
|
647
|
+
test 'creates any defined section with default values if name is nil and config is empty element' do
|
648
|
+
obj = ConfigurableSpec::Base4Safe.new
|
649
|
+
node = obj.configured_section_create(:node, config_element())
|
650
|
+
assert_equal 0, node.num
|
651
|
+
assert_equal "node", node.name
|
652
|
+
assert_equal "b4", node.type
|
653
|
+
|
654
|
+
desc1 = obj.configured_section_create(:description1, config_element())
|
655
|
+
assert_equal "desc1", desc1.note
|
656
|
+
assert_equal "teeeext", desc1.text
|
657
|
+
end
|
658
|
+
|
659
|
+
test 'creates any defined section with specified value if name is nil and configuration element is specified' do
|
660
|
+
obj = ConfigurableSpec::Base4Safe.new
|
661
|
+
node = obj.configured_section_create(:node, config_element('node', '1', {'name' => 'node1', 'type' => 'b1'}))
|
662
|
+
assert_equal 1, node.num
|
663
|
+
assert_equal "node1", node.name
|
664
|
+
assert_equal "b1", node.type
|
665
|
+
|
666
|
+
desc1 = obj.configured_section_create(:description1, config_element('description1', 'desc one', {'text' => 't'}))
|
667
|
+
assert_equal "desc one", desc1.note
|
668
|
+
assert_equal "t", desc1.text
|
669
|
+
end
|
670
|
+
|
671
|
+
test 'creates a defined section instance even if it is defined as multi:true' do
|
672
|
+
obj = ConfigurableSpec::Base4Safe.new
|
673
|
+
desc3 = obj.configured_section_create(:description3)
|
674
|
+
assert_equal "desc3", desc3.note
|
675
|
+
assert_equal "yay", desc3.text
|
676
|
+
|
677
|
+
desc3 = obj.configured_section_create(:description3, config_element('description3', 'foo'))
|
678
|
+
assert_equal "desc3: foo", desc3.note
|
679
|
+
assert_equal "yay", desc3.text
|
680
|
+
end
|
681
|
+
end
|
682
|
+
|
683
|
+
sub_test_case '#configure' do
|
684
|
+
BASE_ATTRS = {
|
685
|
+
"name1" => "1", "name2" => "2", "name3" => "3",
|
686
|
+
"name4" => "4", "name5" => "5", "name6" => "6",
|
687
|
+
}
|
688
|
+
test 'checks required subsections' do
|
689
|
+
b3 = ConfigurableSpec::Base3.new
|
690
|
+
# branch sections required
|
691
|
+
assert_raise(Fluent::ConfigError) { b3.configure(config_element('ROOT', '', BASE_ATTRS, [])) }
|
692
|
+
|
693
|
+
# branch argument required
|
694
|
+
msg = "'<branch ARG>' section requires argument, in section branch"
|
695
|
+
#expect{ b3.configure(e('ROOT', '', BASE_ATTRS, [e('branch', '')])) }.to raise_error(Fluent::ConfigError, msg)
|
696
|
+
assert_raise(Fluent::ConfigError.new(msg)) { b3.configure(config_element('ROOT', '', BASE_ATTRS, [config_element('branch', '')])) }
|
697
|
+
|
698
|
+
# leaf is not required
|
699
|
+
assert_nothing_raised { b3.configure(config_element('ROOT', '', BASE_ATTRS, [config_element('branch', 'branch_name')])) }
|
700
|
+
|
701
|
+
# leaf weight required
|
702
|
+
msg = "'weight' parameter is required, in section branch > leaf"
|
703
|
+
branch1 = config_element('branch', 'branch_name', {size: 1}, [config_element('leaf', '10', {"weight" => 1})])
|
704
|
+
assert_nothing_raised { b3.configure(config_element('ROOT', '', BASE_ATTRS, [branch1])) }
|
705
|
+
branch2 = config_element('branch', 'branch_name', {size: 1}, [config_element('leaf', '20')])
|
706
|
+
assert_raise(Fluent::ConfigError.new(msg)) { b3.configure(config_element('ROOT', '', BASE_ATTRS, [branch1, branch2])) }
|
707
|
+
branch3 = config_element('branch', 'branch_name', {size: 1}, [config_element('leaf', '10', {"weight" => 3}), config_element('leaf', '20')])
|
708
|
+
assert_raise(Fluent::ConfigError.new(msg)) { b3.configure(config_element('ROOT', '', BASE_ATTRS, [branch3])) }
|
709
|
+
|
710
|
+
### worm not required
|
711
|
+
|
712
|
+
b4 = ConfigurableSpec::Base4.new
|
713
|
+
|
714
|
+
d1 = config_element('description1', '', {"text" => "d1"})
|
715
|
+
d2 = config_element('description2', '', {"text" => "d2"})
|
716
|
+
d3 = config_element('description3', '', {"text" => "d3"})
|
717
|
+
assert_nothing_raised { b4.configure(config_element('ROOT', '', BASE_ATTRS, [d1.dup, d2.dup, d3.dup])) }
|
718
|
+
|
719
|
+
# description1 cannot be specified 2 or more
|
720
|
+
msg = "'<description1>' section cannot be written twice or more"
|
721
|
+
assert_raise(Fluent::ConfigError.new(msg)) { b4.configure(config_element('ROOT', '', BASE_ATTRS, [d1.dup, d2.dup, d1.dup, d3.dup])) }
|
722
|
+
|
723
|
+
# description2 cannot be specified 2 or more
|
724
|
+
msg = "'<description2>' section cannot be written twice or more"
|
725
|
+
assert_raise(Fluent::ConfigError.new(msg)) { b4.configure(config_element('ROOT', '', BASE_ATTRS, [d1.dup, d2.dup, d3.dup, d2.dup])) }
|
726
|
+
|
727
|
+
# description3 can be specified 2 or more
|
728
|
+
assert_nothing_raised { b4.configure(config_element('ROOT', '', BASE_ATTRS, [d1.dup, d2.dup, d3.dup, d3.dup])) }
|
729
|
+
end
|
730
|
+
|
731
|
+
test 'constructs confuguration object tree for Base3' do
|
732
|
+
conf = config_element(
|
733
|
+
'ROOT',
|
734
|
+
'',
|
735
|
+
BASE_ATTRS,
|
736
|
+
[
|
737
|
+
config_element('node', '', {"type" => "1"}), config_element('node', '', {"name" => "node2","type" => "2"}),
|
738
|
+
config_element('branch', 'b1.*', {}, []),
|
739
|
+
config_element('branch',
|
740
|
+
'b2.*',
|
741
|
+
{"size" => 5},
|
742
|
+
[
|
743
|
+
config_element('leaf', 'THIS IS IGNORED', {"weight" => 55}, []),
|
744
|
+
config_element('leaf', 'THIS IS IGNORED', {"weight" => 50}, [ config_element('worm', '', {}) ]),
|
745
|
+
config_element('leaf', 'THIS IS IGNORED', {"weight" => 50}, [ config_element('worm', '', {"type" => "w1"}), config_element('worm', '', {"type" => "w2"}) ]),
|
746
|
+
]
|
747
|
+
),
|
748
|
+
config_element('branch',
|
749
|
+
'b3.*',
|
750
|
+
{"size" => "503"},
|
751
|
+
[
|
752
|
+
config_element('leaf', 'THIS IS IGNORED', {"weight" => 55}, []),
|
753
|
+
]
|
754
|
+
)
|
755
|
+
],
|
756
|
+
)
|
757
|
+
b3 = ConfigurableSpec::Base3.new.configure(conf)
|
758
|
+
|
759
|
+
assert_not_equal("node", b3.node) # overwritten
|
760
|
+
|
761
|
+
assert_equal("1", b3.name1)
|
762
|
+
assert_equal("2", b3.name2)
|
763
|
+
assert_equal("3", b3.name3)
|
764
|
+
assert_equal("4", b3.name4)
|
765
|
+
assert_equal("5", b3.name5)
|
766
|
+
assert_equal("6", b3.name6)
|
767
|
+
|
768
|
+
assert_instance_of(Array, b3.node)
|
769
|
+
assert_equal(2, b3.node.size)
|
770
|
+
|
771
|
+
assert_equal("node", b3.node[0].name)
|
772
|
+
assert_equal("1", b3.node[0].type)
|
773
|
+
assert_equal(b3.node[0].type, b3.node[0][:type])
|
774
|
+
assert_equal("node2", b3.node[1].name)
|
775
|
+
assert_equal("2", b3.node[1].type)
|
776
|
+
assert_equal(b3.node[1].type, b3.node[1][:type])
|
777
|
+
|
778
|
+
assert_instance_of(Array, b3.branch)
|
779
|
+
assert_equal(3, b3.branch.size)
|
780
|
+
|
781
|
+
assert_equal('b1.*', b3.branch[0].name)
|
782
|
+
assert_equal(10, b3.branch[0].size)
|
783
|
+
assert_equal([], b3.branch[0].leaf)
|
784
|
+
|
785
|
+
assert_equal('b2.*', b3.branch[1].name)
|
786
|
+
assert_equal(5, b3.branch[1].size)
|
787
|
+
assert_equal(3, b3.branch[1].leaf.size)
|
788
|
+
assert_equal(b3.branch[1].leaf, b3.branch[1][:leaf])
|
789
|
+
|
790
|
+
assert_equal(55, b3.branch[1].leaf[0].weight)
|
791
|
+
assert_equal(0, b3.branch[1].leaf[0].worms.size)
|
792
|
+
|
793
|
+
assert_equal(50, b3.branch[1].leaf[1].weight)
|
794
|
+
assert_equal(1, b3.branch[1].leaf[1].worms.size)
|
795
|
+
assert_equal("ladybird", b3.branch[1].leaf[1].worms[0].type)
|
796
|
+
|
797
|
+
assert_equal(50, b3.branch[1].leaf[2].weight)
|
798
|
+
assert_equal(2, b3.branch[1].leaf[2].worms.size)
|
799
|
+
assert_equal("w1", b3.branch[1].leaf[2].worms[0].type)
|
800
|
+
assert_equal("w2", b3.branch[1].leaf[2].worms[1].type)
|
801
|
+
|
802
|
+
assert_equal('b3.*', b3.branch[2].name)
|
803
|
+
assert_equal(503, b3.branch[2].size)
|
804
|
+
assert_equal(1, b3.branch[2].leaf.size)
|
805
|
+
assert_equal(55, b3.branch[2].leaf[0].weight)
|
806
|
+
end
|
807
|
+
|
808
|
+
test 'constructs confuguration object tree for Base4' do
|
809
|
+
conf = config_element(
|
810
|
+
'ROOT',
|
811
|
+
'',
|
812
|
+
BASE_ATTRS,
|
813
|
+
[
|
814
|
+
config_element('node', '1', {"type" => "1"}), config_element('node', '2', {"name" => "node2"}),
|
815
|
+
config_element('description3', '', {"text" => "dddd3-1"}),
|
816
|
+
config_element('description2', 'd-2', {"text" => "dddd2"}),
|
817
|
+
config_element('description1', '', {"text" => "dddd1"}),
|
818
|
+
config_element('description3', 'd-3', {"text" => "dddd3-2"}),
|
819
|
+
config_element('description3', 'd-3a', {"text" => "dddd3-3"}),
|
820
|
+
config_element('node', '4', {"type" => "four"}),
|
821
|
+
],
|
822
|
+
)
|
823
|
+
b4 = ConfigurableSpec::Base4.new.configure(conf)
|
824
|
+
|
825
|
+
assert_equal("node", b4.node)
|
826
|
+
|
827
|
+
assert_equal("1", b4.name1)
|
828
|
+
assert_equal("2", b4.name2)
|
829
|
+
assert_equal("3", b4.name3)
|
830
|
+
assert_equal("4", b4.name4)
|
831
|
+
assert_equal("5", b4.name5)
|
832
|
+
assert_equal("6", b4.name6)
|
833
|
+
|
834
|
+
assert_instance_of(Array, b4.nodes)
|
835
|
+
assert_equal(3, b4.nodes.size)
|
836
|
+
assert_equal(1, b4.nodes[0].num)
|
837
|
+
assert_equal("node", b4.nodes[0].name)
|
838
|
+
assert_equal("1", b4.nodes[0].type)
|
839
|
+
assert_equal(2, b4.nodes[1].num)
|
840
|
+
assert_equal("node2", b4.nodes[1].name)
|
841
|
+
assert_equal("b4", b4.nodes[1].type)
|
842
|
+
assert_equal(4, b4.nodes[2].num)
|
843
|
+
assert_equal("node", b4.nodes[2].name)
|
844
|
+
assert_equal("four", b4.nodes[2].type)
|
845
|
+
|
846
|
+
# config_element('description3', '', {"text" => "dddd3-1"}),
|
847
|
+
# config_element('description3', 'd-3', {"text" => "dddd3-2"}),
|
848
|
+
# config_element('description3', 'd-3a', {"text" => "dddd3-3"}),
|
849
|
+
|
850
|
+
# NoMethodError: undefined method `class' for <Fluent::Config::Section {...}>:Fluent::Config::Section occurred. Should we add class method to Section?
|
851
|
+
#assert_equal('Fluent::Config::Section', b4.description1.class.name)
|
852
|
+
assert_equal("desc1", b4.description1.note)
|
853
|
+
assert_equal("dddd1", b4.description1.text)
|
854
|
+
|
855
|
+
# same with assert_equal('Fluent::Config::Section', b4.description1)
|
856
|
+
#assert_equal('Fluent::Config::Section', b4.description2)
|
857
|
+
assert_equal("d-2", b4.description2.note)
|
858
|
+
assert_equal("dddd2", b4.description2.text)
|
859
|
+
|
860
|
+
assert_instance_of(Array, b4.description3)
|
861
|
+
assert_equal(3, b4.description3.size)
|
862
|
+
assert_equal("desc3", b4.description3[0].note)
|
863
|
+
assert_equal("dddd3-1", b4.description3[0].text)
|
864
|
+
assert_equal('desc3: d-3', b4.description3[1].note)
|
865
|
+
assert_equal('dddd3-2', b4.description3[1].text)
|
866
|
+
assert_equal('desc3: d-3a', b4.description3[2].note)
|
867
|
+
assert_equal('dddd3-3', b4.description3[2].text)
|
868
|
+
end
|
869
|
+
|
870
|
+
test 'checks missing of specifications' do
|
871
|
+
conf0 = config_element('ROOT', '', {}, [])
|
872
|
+
ex01 = ConfigurableSpec::Example0.new
|
873
|
+
assert_raise(Fluent::ConfigError) { ex01.configure(conf0) }
|
874
|
+
|
875
|
+
complete = config_element('ROOT', '', {
|
876
|
+
"stringvalue" => "s1", "boolvalue" => "yes", "integervalue" => "10",
|
877
|
+
"sizevalue" => "10m", "timevalue" => "100s", "floatvalue" => "1.001",
|
878
|
+
"hashvalue" => '{"foo":1, "bar":2}',
|
879
|
+
"arrayvalue" => '[1,"ichi"]',
|
880
|
+
})
|
881
|
+
|
882
|
+
checker = lambda { |conf| ConfigurableSpec::Example0.new.configure(conf) }
|
883
|
+
|
884
|
+
assert_nothing_raised { checker.call(complete) }
|
885
|
+
assert_raise(Fluent::ConfigError) { c = complete.dup; c.delete("stringvalue"); checker.call(c) }
|
886
|
+
assert_raise(Fluent::ConfigError) { c = complete.dup; c.delete("boolvalue"); checker.call(c) }
|
887
|
+
assert_raise(Fluent::ConfigError) { c = complete.dup; c.delete("integervalue"); checker.call(c) }
|
888
|
+
assert_raise(Fluent::ConfigError) { c = complete.dup; c.delete("sizevalue"); checker.call(c) }
|
889
|
+
assert_raise(Fluent::ConfigError) { c = complete.dup; c.delete("timevalue"); checker.call(c) }
|
890
|
+
assert_raise(Fluent::ConfigError) { c = complete.dup; c.delete("floatvalue"); checker.call(c) }
|
891
|
+
assert_raise(Fluent::ConfigError) { c = complete.dup; c.delete("hashvalue"); checker.call(c) }
|
892
|
+
assert_raise(Fluent::ConfigError) { c = complete.dup; c.delete("arrayvalue"); checker.call(c) }
|
893
|
+
end
|
894
|
+
|
895
|
+
test 'generates section with default values for init:true sections' do
|
896
|
+
conf = config_element('ROOT', '', {}, [])
|
897
|
+
init0 = ConfigurableSpec::Init0.new
|
898
|
+
assert_nothing_raised { init0.configure(conf) }
|
899
|
+
assert init0.sec1
|
900
|
+
assert_equal "sec1", init0.sec1.name
|
901
|
+
assert_equal 1, init0.sec2.size
|
902
|
+
assert_equal "sec1", init0.sec2.first.name
|
903
|
+
end
|
904
|
+
|
905
|
+
test 'accepts configuration values as string representation' do
|
906
|
+
conf = config_element('ROOT', '', {
|
907
|
+
"stringvalue" => "s1", "boolvalue" => "yes", "integervalue" => "10",
|
908
|
+
"sizevalue" => "10m", "timevalue" => "10m", "floatvalue" => "1.001",
|
909
|
+
"hashvalue" => '{"foo":1, "bar":2}',
|
910
|
+
"arrayvalue" => '[1,"ichi"]',
|
911
|
+
})
|
912
|
+
ex = ConfigurableSpec::Example0.new.configure(conf)
|
913
|
+
assert_equal("s1", ex.stringvalue)
|
914
|
+
assert_true(ex.boolvalue)
|
915
|
+
assert_equal(10, ex.integervalue)
|
916
|
+
assert_equal(10 * 1024 * 1024, ex.sizevalue)
|
917
|
+
assert_equal(10 * 60, ex.timevalue)
|
918
|
+
assert_equal(1.001, ex.floatvalue)
|
919
|
+
assert_equal({"foo" => 1, "bar" => 2}, ex.hashvalue)
|
920
|
+
assert_equal([1, "ichi"], ex.arrayvalue)
|
921
|
+
end
|
922
|
+
|
923
|
+
test 'accepts configuration values as ruby value representation (especially for DSL)' do
|
924
|
+
conf = config_element('ROOT', '', {
|
925
|
+
"stringvalue" => "s1", "boolvalue" => true, "integervalue" => 10,
|
926
|
+
"sizevalue" => 10 * 1024 * 1024, "timevalue" => 10 * 60, "floatvalue" => 1.001,
|
927
|
+
"hashvalue" => {"foo" => 1, "bar" => 2},
|
928
|
+
"arrayvalue" => [1,"ichi"],
|
929
|
+
})
|
930
|
+
ex = ConfigurableSpec::Example0.new.configure(conf)
|
931
|
+
assert_equal("s1", ex.stringvalue)
|
932
|
+
assert_true(ex.boolvalue)
|
933
|
+
assert_equal(10, ex.integervalue)
|
934
|
+
assert_equal(10 * 1024 * 1024, ex.sizevalue)
|
935
|
+
assert_equal(10 * 60, ex.timevalue)
|
936
|
+
assert_equal(1.001, ex.floatvalue)
|
937
|
+
assert_equal({"foo" => 1, "bar" => 2}, ex.hashvalue)
|
938
|
+
assert_equal([1, "ichi"], ex.arrayvalue)
|
939
|
+
end
|
940
|
+
|
941
|
+
test 'gets both of true(yes) and false(no) for bool value parameter' do
|
942
|
+
conf = config_element('ROOT', '', {
|
943
|
+
"stringvalue" => "s1", "integervalue" => 10,
|
944
|
+
"sizevalue" => 10 * 1024 * 1024, "timevalue" => 10 * 60, "floatvalue" => 1.001,
|
945
|
+
"hashvalue" => {"foo" => 1, "bar" => 2},
|
946
|
+
"arrayvalue" => [1,"ichi"],
|
947
|
+
})
|
948
|
+
ex0 = ConfigurableSpec::Example0.new.configure(conf.merge({"boolvalue" => "true"}))
|
949
|
+
assert_true(ex0.boolvalue)
|
950
|
+
|
951
|
+
ex1 = ConfigurableSpec::Example0.new.configure(conf.merge({"boolvalue" => "yes"}))
|
952
|
+
assert_true(ex1.boolvalue)
|
953
|
+
|
954
|
+
ex2 = ConfigurableSpec::Example0.new.configure(conf.merge({"boolvalue" => true}))
|
955
|
+
assert_true(ex2.boolvalue)
|
956
|
+
|
957
|
+
ex3 = ConfigurableSpec::Example0.new.configure(conf.merge({"boolvalue" => "false"}))
|
958
|
+
assert_false(ex3.boolvalue)
|
959
|
+
|
960
|
+
ex4 = ConfigurableSpec::Example0.new.configure(conf.merge({"boolvalue" => "no"}))
|
961
|
+
assert_false(ex4.boolvalue)
|
962
|
+
|
963
|
+
ex5 = ConfigurableSpec::Example0.new.configure(conf.merge({"boolvalue" => false}))
|
964
|
+
assert_false(ex5.boolvalue)
|
965
|
+
end
|
966
|
+
end
|
967
|
+
|
968
|
+
sub_test_case '.config_section' do
|
969
|
+
CONF1 = config_element('ROOT', '', {
|
970
|
+
'name' => 'tagomoris',
|
971
|
+
'bool' => true,
|
972
|
+
})
|
973
|
+
|
974
|
+
CONF2 = config_element('ROOT', '', {
|
975
|
+
'name' => 'tagomoris',
|
976
|
+
'bool' => true,
|
977
|
+
},
|
978
|
+
[config_element('detail', '', { 'phone_no' => "+81-00-0000-0000" }, [])])
|
979
|
+
|
980
|
+
CONF3 = config_element('ROOT', '', {
|
981
|
+
'name' => 'tagomoris',
|
982
|
+
'bool' => true,
|
983
|
+
},
|
984
|
+
[config_element('detail', '', { 'address' => "Chiyoda Tokyo Japan" }, [])])
|
985
|
+
|
986
|
+
CONF4 = config_element('ROOT', '', {
|
987
|
+
'name' => 'tagomoris',
|
988
|
+
'bool' => true,
|
989
|
+
},
|
990
|
+
[
|
991
|
+
config_element('detail', '', {
|
992
|
+
'address' => "Chiyoda Tokyo Japan",
|
993
|
+
'phone_no' => '+81-00-0000-0000'
|
994
|
+
},
|
995
|
+
[])
|
996
|
+
])
|
997
|
+
|
998
|
+
data(conf1: CONF1,
|
999
|
+
conf2: CONF2,
|
1000
|
+
conf3: CONF3,
|
1001
|
+
conf4: CONF4,)
|
1002
|
+
test 'base class' do |data|
|
1003
|
+
assert_nothing_raised { ConfigurableSpec::Overwrite::Base.new.configure(data) }
|
1004
|
+
end
|
1005
|
+
|
1006
|
+
test 'subclass cannot overwrite required' do
|
1007
|
+
assert_raise(Fluent::ConfigError.new("BUG: subclass cannot overwrite base class's config_section: required")) do
|
1008
|
+
ConfigurableSpec::Overwrite::Required.new.configure(CONF1)
|
1009
|
+
end
|
1010
|
+
end
|
1011
|
+
|
1012
|
+
test 'subclass cannot overwrite multi' do
|
1013
|
+
assert_raise(Fluent::ConfigError.new("BUG: subclass cannot overwrite base class's config_section: multi")) do
|
1014
|
+
ConfigurableSpec::Overwrite::Multi.new.configure(CONF1)
|
1015
|
+
end
|
1016
|
+
end
|
1017
|
+
|
1018
|
+
test 'subclass cannot overwrite alias' do
|
1019
|
+
assert_raise(Fluent::ConfigError.new("BUG: subclass cannot overwrite base class's config_section: alias")) do
|
1020
|
+
ConfigurableSpec::Overwrite::Alias.new.configure(CONF1)
|
1021
|
+
end
|
1022
|
+
end
|
1023
|
+
|
1024
|
+
test 'subclass uses superclass default options' do
|
1025
|
+
base = ConfigurableSpec::Overwrite::Base.new.configure(CONF2)
|
1026
|
+
sub = ConfigurableSpec::Overwrite::DefaultOptions.new.configure(CONF2)
|
1027
|
+
detail_base = base.class.merged_configure_proxy.sections[:detail]
|
1028
|
+
detail_sub = sub.class.merged_configure_proxy.sections[:detail]
|
1029
|
+
detail_base_attributes = {
|
1030
|
+
requried: detail_base.required,
|
1031
|
+
multi: detail_base.multi,
|
1032
|
+
alias: detail_base.alias,
|
1033
|
+
}
|
1034
|
+
detail_sub_attributes = {
|
1035
|
+
requried: detail_sub.required,
|
1036
|
+
multi: detail_sub.multi,
|
1037
|
+
alias: detail_sub.alias,
|
1038
|
+
}
|
1039
|
+
assert_equal(detail_base_attributes, detail_sub_attributes)
|
1040
|
+
end
|
1041
|
+
|
1042
|
+
test 'subclass can overwrite detail.address' do
|
1043
|
+
base = ConfigurableSpec::Overwrite::Base.new.configure(CONF2)
|
1044
|
+
target = ConfigurableSpec::Overwrite::DetailAddressDefault.new.configure(CONF2)
|
1045
|
+
expected_addresses = ["x", "y"]
|
1046
|
+
actual_addresses = [base.detail.address, target.detail.address]
|
1047
|
+
assert_equal(expected_addresses, actual_addresses)
|
1048
|
+
end
|
1049
|
+
|
1050
|
+
test 'subclass can add param' do
|
1051
|
+
assert_raise(Fluent::ConfigError.new("'phone_no' parameter is required, in section detail")) do
|
1052
|
+
ConfigurableSpec::Overwrite::AddParam.new.configure(CONF3)
|
1053
|
+
end
|
1054
|
+
target = ConfigurableSpec::Overwrite::AddParam.new.configure(CONF4)
|
1055
|
+
expected = {
|
1056
|
+
address: "Chiyoda Tokyo Japan",
|
1057
|
+
phone_no: "+81-00-0000-0000"
|
1058
|
+
}
|
1059
|
+
actual = {
|
1060
|
+
address: target.detail.address,
|
1061
|
+
phone_no: target.detail.phone_no
|
1062
|
+
}
|
1063
|
+
assert_equal(expected, actual)
|
1064
|
+
end
|
1065
|
+
|
1066
|
+
test 'subclass can add param with overwriting address' do
|
1067
|
+
assert_raise(Fluent::ConfigError.new("'phone_no' parameter is required, in section detail")) do
|
1068
|
+
ConfigurableSpec::Overwrite::AddParamOverwriteAddress.new.configure(CONF3)
|
1069
|
+
end
|
1070
|
+
target = ConfigurableSpec::Overwrite::AddParamOverwriteAddress.new.configure(CONF4)
|
1071
|
+
expected = {
|
1072
|
+
address: "Chiyoda Tokyo Japan",
|
1073
|
+
phone_no: "+81-00-0000-0000"
|
1074
|
+
}
|
1075
|
+
actual = {
|
1076
|
+
address: target.detail.address,
|
1077
|
+
phone_no: target.detail.phone_no
|
1078
|
+
}
|
1079
|
+
assert_equal(expected, actual)
|
1080
|
+
end
|
1081
|
+
|
1082
|
+
sub_test_case 'final' do
|
1083
|
+
test 'base class has designed params and default values' do
|
1084
|
+
b = ConfigurableSpec::Final::Base.new
|
1085
|
+
appendix_conf = config_element('appendix', '', {"code" => "b", "name" => "base"})
|
1086
|
+
b.configure(config_element('ROOT', '', {}, [appendix_conf]))
|
1087
|
+
|
1088
|
+
assert_equal "b", b.appendix.code
|
1089
|
+
assert_equal "base", b.appendix.name
|
1090
|
+
assert_equal "", b.appendix.address
|
1091
|
+
end
|
1092
|
+
|
1093
|
+
test 'subclass can change type, add default value, change default value of parameters, and add parameters to non-finalized section' do
|
1094
|
+
f = ConfigurableSpec::Final::Finalized.new
|
1095
|
+
appendix_conf = config_element('appendix', '', {"code" => 1})
|
1096
|
+
f.configure(config_element('ROOT', '', {}, [appendix_conf]))
|
1097
|
+
|
1098
|
+
assert_equal 1, f.appendix.code
|
1099
|
+
assert_equal 'y', f.appendix.name
|
1100
|
+
assert_equal "-", f.appendix.address
|
1101
|
+
assert_equal 10, f.appendix.age
|
1102
|
+
end
|
1103
|
+
|
1104
|
+
test 'subclass can add default value, change default value of parameters, and add parameters to finalized section' do
|
1105
|
+
i = ConfigurableSpec::Final::InheritsFinalized.new
|
1106
|
+
appendix_conf = config_element('appendix', '', {"phone_no" => "00-0000-0000"})
|
1107
|
+
i.configure(config_element('ROOT', '', {}, [appendix_conf]))
|
1108
|
+
|
1109
|
+
assert_equal 2, i.appendix.code
|
1110
|
+
assert_equal 0, i.appendix.age
|
1111
|
+
assert_equal "00-0000-0000", i.appendix.phone_no
|
1112
|
+
end
|
1113
|
+
|
1114
|
+
test 'finalized base class works as designed' do
|
1115
|
+
b = ConfigurableSpec::Final::FinalizedBase.new
|
1116
|
+
appendix_conf = config_element('options', '', {"name" => "moris"})
|
1117
|
+
|
1118
|
+
assert_nothing_raised do
|
1119
|
+
b.configure(config_element('ROOT', '', {}, [appendix_conf]))
|
1120
|
+
end
|
1121
|
+
assert b.apd
|
1122
|
+
assert_equal "moris", b.apd.name
|
1123
|
+
end
|
1124
|
+
|
1125
|
+
test 'subclass can change init' do
|
1126
|
+
n = ConfigurableSpec::Final::OverwriteInit.new
|
1127
|
+
|
1128
|
+
assert_nothing_raised do
|
1129
|
+
n.configure(config_element('ROOT', ''))
|
1130
|
+
end
|
1131
|
+
assert n.apd
|
1132
|
+
assert_equal "moris", n.apd.name
|
1133
|
+
assert_equal 0, n.apd.code
|
1134
|
+
end
|
1135
|
+
|
1136
|
+
test 'subclass cannot change parameter types in finalized sections' do
|
1137
|
+
s = ConfigurableSpec::Final::Subclass.new
|
1138
|
+
appendix_conf = config_element('options', '', {"name" => "1"})
|
1139
|
+
|
1140
|
+
assert_nothing_raised do
|
1141
|
+
s.configure(config_element('ROOT', '', {}, [appendix_conf]))
|
1142
|
+
end
|
1143
|
+
assert_equal "1", s.apd.name
|
1144
|
+
end
|
1145
|
+
|
1146
|
+
test 'subclass cannot change param_name of finalized section' do
|
1147
|
+
assert_raise(Fluent::ConfigError.new("BUG: subclass cannot overwrite base class's config_section: param_name")) do
|
1148
|
+
ConfigurableSpec::Final::OverwriteParamName.new
|
1149
|
+
end
|
1150
|
+
end
|
1151
|
+
|
1152
|
+
test 'subclass cannot change final of finalized section' do
|
1153
|
+
assert_raise(Fluent::ConfigError.new("BUG: subclass cannot overwrite finalized base class's config_section")) do
|
1154
|
+
ConfigurableSpec::Final::OverwriteFinal.new
|
1155
|
+
end
|
1156
|
+
end
|
1157
|
+
|
1158
|
+
test 'subclass cannot change required of finalized section' do
|
1159
|
+
assert_raise(Fluent::ConfigError.new("BUG: subclass cannot overwrite base class's config_section: required")) do
|
1160
|
+
ConfigurableSpec::Final::OverwriteRequired.new
|
1161
|
+
end
|
1162
|
+
end
|
1163
|
+
|
1164
|
+
test 'subclass cannot change multi of finalized section' do
|
1165
|
+
assert_raise(Fluent::ConfigError.new("BUG: subclass cannot overwrite base class's config_section: multi")) do
|
1166
|
+
ConfigurableSpec::Final::OverwriteMulti.new
|
1167
|
+
end
|
1168
|
+
end
|
1169
|
+
|
1170
|
+
test 'subclass cannot change alias of finalized section' do
|
1171
|
+
assert_raise(Fluent::ConfigError.new("BUG: subclass cannot overwrite base class's config_section: alias")) do
|
1172
|
+
ConfigurableSpec::Final::OverwriteAlias.new
|
1173
|
+
end
|
1174
|
+
end
|
1175
|
+
end
|
1176
|
+
end
|
1177
|
+
end
|
1178
|
+
|
1179
|
+
sub_test_case 'class defined with config_param/config_section having :alias' do
|
1180
|
+
sub_test_case '#initialize' do
|
1181
|
+
test 'does not create methods for alias' do
|
1182
|
+
ex1 = ConfigurableSpec::Example1.new
|
1183
|
+
assert_nothing_raised { ex1.name }
|
1184
|
+
assert_raise(NoMethodError) { ex1.fullname }
|
1185
|
+
assert_nothing_raised { ex1.bool }
|
1186
|
+
assert_raise(NoMethodError) { ex1.flag }
|
1187
|
+
assert_nothing_raised { ex1.detail }
|
1188
|
+
assert_raise(NoMethodError) { ex1.information}
|
1189
|
+
end
|
1190
|
+
end
|
1191
|
+
|
1192
|
+
sub_test_case '#configure' do
|
1193
|
+
test 'provides accessible data for alias attribute keys' do
|
1194
|
+
ex1 = ConfigurableSpec::Example1.new
|
1195
|
+
conf = config_element('ROOT', '', {
|
1196
|
+
"fullname" => "foo bar",
|
1197
|
+
"bool" => false
|
1198
|
+
},
|
1199
|
+
[config_element('information', '', {"address" => "Mountain View 0"})])
|
1200
|
+
ex1.configure(conf)
|
1201
|
+
assert_equal("foo bar", ex1.name)
|
1202
|
+
assert_not_nil(ex1.bool)
|
1203
|
+
assert_false(ex1.bool)
|
1204
|
+
assert_not_nil(ex1.detail)
|
1205
|
+
assert_equal("Mountain View 0", ex1.detail.address)
|
1206
|
+
end
|
1207
|
+
end
|
1208
|
+
end
|
1209
|
+
|
1210
|
+
sub_test_case 'defaults can be overwritten by owner' do
|
1211
|
+
test 'for feature plugin which has flat parameters with parent' do
|
1212
|
+
owner = ConfigurableSpec::OverwriteDefaults::Owner.new
|
1213
|
+
child = ConfigurableSpec::OverwriteDefaults::FlatChild.new
|
1214
|
+
assert_nil child.class.merged_configure_proxy.configured_in_section
|
1215
|
+
|
1216
|
+
child.owner = owner
|
1217
|
+
child.configure(config_element('ROOT', '', {}, []))
|
1218
|
+
assert_equal "V1", child.key1
|
1219
|
+
end
|
1220
|
+
|
1221
|
+
test 'for feature plugin which has parameters in subsection of parent' do
|
1222
|
+
owner = ConfigurableSpec::OverwriteDefaults::Owner.new
|
1223
|
+
child = ConfigurableSpec::OverwriteDefaults::BufferChild.new
|
1224
|
+
assert_equal :buffer, child.class.merged_configure_proxy.configured_in_section
|
1225
|
+
|
1226
|
+
child.owner = owner
|
1227
|
+
child.configure(config_element('ROOT', '', {}, []))
|
1228
|
+
assert_equal 1024, child.size_of_something
|
1229
|
+
end
|
1230
|
+
|
1231
|
+
test 'even in subclass of owner' do
|
1232
|
+
owner = ConfigurableSpec::OverwriteDefaults::SubOwner.new
|
1233
|
+
child = ConfigurableSpec::OverwriteDefaults::BufferChild.new
|
1234
|
+
assert_equal :buffer, child.class.merged_configure_proxy.configured_in_section
|
1235
|
+
|
1236
|
+
child.owner = owner
|
1237
|
+
child.configure(config_element('ROOT', '', {}, []))
|
1238
|
+
assert_equal 2048, child.size_of_something
|
1239
|
+
end
|
1240
|
+
|
1241
|
+
test 'default values can be overwritten with nil' do
|
1242
|
+
owner = ConfigurableSpec::OverwriteDefaults::NilOwner.new
|
1243
|
+
child = ConfigurableSpec::OverwriteDefaults::BufferChild.new
|
1244
|
+
assert_equal :buffer, child.class.merged_configure_proxy.configured_in_section
|
1245
|
+
|
1246
|
+
child.owner = owner
|
1247
|
+
child.configure(config_element('ROOT', '', {}, []))
|
1248
|
+
assert_nil child.size_of_something
|
1249
|
+
end
|
1250
|
+
|
1251
|
+
test 'the first configured_in (in the order from base class) will be applied' do
|
1252
|
+
child = ConfigurableSpec::OverwriteDefaults::BufferSubclass.new
|
1253
|
+
assert_equal :buffer, child.class.merged_configure_proxy.configured_in_section
|
1254
|
+
|
1255
|
+
child.configure(config_element('ROOT', '', {}, []))
|
1256
|
+
assert_equal 512, child.size_of_something
|
1257
|
+
end
|
1258
|
+
|
1259
|
+
test 'the first configured_in is valid with owner classes' do
|
1260
|
+
owner = ConfigurableSpec::OverwriteDefaults::Owner.new
|
1261
|
+
child = ConfigurableSpec::OverwriteDefaults::BufferSubclass.new
|
1262
|
+
assert_equal :buffer, child.class.merged_configure_proxy.configured_in_section
|
1263
|
+
|
1264
|
+
child.owner = owner
|
1265
|
+
child.configure(config_element('ROOT', '', {}, []))
|
1266
|
+
assert_equal 1024, child.size_of_something
|
1267
|
+
end
|
1268
|
+
|
1269
|
+
test 'the only first configured_in is valid even in subclasses of a class with configured_in' do
|
1270
|
+
child = ConfigurableSpec::OverwriteDefaults::BufferSubSubclass.new
|
1271
|
+
assert_equal :buffer, child.class.merged_configure_proxy.configured_in_section
|
1272
|
+
|
1273
|
+
child.configure(config_element('ROOT', '', {}, []))
|
1274
|
+
assert_equal 512, child.size_of_something
|
1275
|
+
end
|
1276
|
+
end
|
1277
|
+
|
1278
|
+
sub_test_case ':secret option' do
|
1279
|
+
setup do
|
1280
|
+
@conf = config_element('ROOT', '',
|
1281
|
+
{
|
1282
|
+
'normal_param' => 'normal',
|
1283
|
+
'secret_param' => 'secret'
|
1284
|
+
},
|
1285
|
+
[config_element('section', '', {'normal_param2' => 'normal', 'secret_param2' => 'secret'} )])
|
1286
|
+
@example = ConfigurableSpec::Example5.new
|
1287
|
+
@example.configure(@conf)
|
1288
|
+
end
|
1289
|
+
|
1290
|
+
test 'to_s hides secret config_param' do
|
1291
|
+
@conf.to_s.each_line { |line|
|
1292
|
+
key, value = line.strip.split(' ', 2)
|
1293
|
+
assert_secret_param(key, value)
|
1294
|
+
}
|
1295
|
+
end
|
1296
|
+
|
1297
|
+
test 'config returns masked configuration' do
|
1298
|
+
conf = @example.config
|
1299
|
+
conf.each_pair { |key, value|
|
1300
|
+
assert_secret_param(key, value)
|
1301
|
+
}
|
1302
|
+
conf.elements.each { |element|
|
1303
|
+
element.each_pair { |key, value|
|
1304
|
+
assert_secret_param(key, value)
|
1305
|
+
}
|
1306
|
+
}
|
1307
|
+
end
|
1308
|
+
|
1309
|
+
test 'get plugin name when found unknown section' do
|
1310
|
+
@conf = config_element('ROOT', '',
|
1311
|
+
{
|
1312
|
+
'normal_param' => 'normal',
|
1313
|
+
'secret_param' => 'secret'
|
1314
|
+
},
|
1315
|
+
[config_element('unknown', '', {'normal_param2' => 'normal', 'secret_param2' => 'secret'} )])
|
1316
|
+
@example = ConfigurableSpec::Example5.new
|
1317
|
+
@example.configure(@conf)
|
1318
|
+
@conf.elements.each { |e|
|
1319
|
+
assert_equal(['ROOT', nil], e.unused_in)
|
1320
|
+
}
|
1321
|
+
end
|
1322
|
+
|
1323
|
+
def assert_secret_param(key, value)
|
1324
|
+
case key
|
1325
|
+
when 'normal_param', 'normal_param2'
|
1326
|
+
assert_equal 'normal', value
|
1327
|
+
when 'secret_param', 'secret_param2'
|
1328
|
+
assert_equal 'xxxxxx', value
|
1329
|
+
end
|
1330
|
+
end
|
1331
|
+
end
|
1332
|
+
|
1333
|
+
sub_test_case ':skip_accessor option' do
|
1334
|
+
test 'it does not create accessor methods for parameters' do
|
1335
|
+
@example = ConfigurableSpec::Example7.new
|
1336
|
+
@example.configure(config_element('ROOT'))
|
1337
|
+
assert_equal 'example7', @example.instance_variable_get(:@name)
|
1338
|
+
assert_raise NoMethodError.new("undefined method `name' for #{@example}") do
|
1339
|
+
@example.name
|
1340
|
+
end
|
1341
|
+
end
|
1342
|
+
end
|
1343
|
+
|
1344
|
+
sub_test_case 'non-required options for config_param' do
|
1345
|
+
test 'desc must be a string if specified' do
|
1346
|
+
assert_raise ArgumentError.new("key: desc must be a String, but Symbol") do
|
1347
|
+
class InvalidDescClass
|
1348
|
+
include Fluent::Configurable
|
1349
|
+
config_param :key, :string, default: '', desc: :invalid_description
|
1350
|
+
end
|
1351
|
+
end
|
1352
|
+
end
|
1353
|
+
test 'alias must be a symbol if specified' do
|
1354
|
+
assert_raise ArgumentError.new("key: alias must be a Symbol, but String") do
|
1355
|
+
class InvalidAliasClass
|
1356
|
+
include Fluent::Configurable
|
1357
|
+
config_param :key, :string, default: '', alias: 'yay'
|
1358
|
+
end
|
1359
|
+
end
|
1360
|
+
end
|
1361
|
+
test 'secret must be true or false if specified' do
|
1362
|
+
assert_raise ArgumentError.new("key: secret must be true or false, but NilClass") do
|
1363
|
+
class InvalidSecretClass
|
1364
|
+
include Fluent::Configurable
|
1365
|
+
config_param :key, :string, default: '', secret: nil
|
1366
|
+
end
|
1367
|
+
end
|
1368
|
+
assert_raise ArgumentError.new("key: secret must be true or false, but String") do
|
1369
|
+
class InvalidSecret2Class
|
1370
|
+
include Fluent::Configurable
|
1371
|
+
config_param :key, :string, default: '', secret: 'yes'
|
1372
|
+
end
|
1373
|
+
end
|
1374
|
+
end
|
1375
|
+
test 'deprecated must be a string if specified' do
|
1376
|
+
assert_raise ArgumentError.new("key: deprecated must be a String, but TrueClass") do
|
1377
|
+
class InvalidDeprecatedClass
|
1378
|
+
include Fluent::Configurable
|
1379
|
+
config_param :key, :string, default: '', deprecated: true
|
1380
|
+
end
|
1381
|
+
end
|
1382
|
+
end
|
1383
|
+
test 'obsoleted must be a string if specified' do
|
1384
|
+
assert_raise ArgumentError.new("key: obsoleted must be a String, but TrueClass") do
|
1385
|
+
class InvalidObsoletedClass
|
1386
|
+
include Fluent::Configurable
|
1387
|
+
config_param :key, :string, default: '', obsoleted: true
|
1388
|
+
end
|
1389
|
+
end
|
1390
|
+
end
|
1391
|
+
test 'value_type for hash must be a symbol' do
|
1392
|
+
assert_raise ArgumentError.new("key: value_type must be a Symbol, but String") do
|
1393
|
+
class InvalidValueTypeOfHashClass
|
1394
|
+
include Fluent::Configurable
|
1395
|
+
config_param :key, :hash, value_type: 'yay'
|
1396
|
+
end
|
1397
|
+
end
|
1398
|
+
end
|
1399
|
+
test 'value_type for array must be a symbol' do
|
1400
|
+
assert_raise ArgumentError.new("key: value_type must be a Symbol, but String") do
|
1401
|
+
class InvalidValueTypeOfArrayClass
|
1402
|
+
include Fluent::Configurable
|
1403
|
+
config_param :key, :array, value_type: 'yay'
|
1404
|
+
end
|
1405
|
+
end
|
1406
|
+
end
|
1407
|
+
test 'skip_accessor must be true or false if specified' do
|
1408
|
+
assert_raise ArgumentError.new("key: skip_accessor must be true or false, but NilClass") do
|
1409
|
+
class InvalidSkipAccessorClass
|
1410
|
+
include Fluent::Configurable
|
1411
|
+
config_param :key, :string, default: '', skip_accessor: nil
|
1412
|
+
end
|
1413
|
+
end
|
1414
|
+
assert_raise ArgumentError.new("key: skip_accessor must be true or false, but String") do
|
1415
|
+
class InvalidSkipAccessor2Class
|
1416
|
+
include Fluent::Configurable
|
1417
|
+
config_param :key, :string, default: '', skip_accessor: 'yes'
|
1418
|
+
end
|
1419
|
+
end
|
1420
|
+
end
|
1421
|
+
end
|
1422
|
+
sub_test_case 'enum parameters' do
|
1423
|
+
test 'list must be specified as an array of symbols'
|
1424
|
+
end
|
1425
|
+
sub_test_case 'deprecated/obsoleted parameters' do
|
1426
|
+
test 'both cannot be specified at once' do
|
1427
|
+
assert_raise ArgumentError.new("param1: both of deprecated and obsoleted cannot be specified at once") do
|
1428
|
+
class Buggy1
|
1429
|
+
include Fluent::Configurable
|
1430
|
+
config_param :param1, :string, default: '', deprecated: 'yay', obsoleted: 'foo!'
|
1431
|
+
end
|
1432
|
+
end
|
1433
|
+
end
|
1434
|
+
|
1435
|
+
test 'warned if deprecated parameter is configured' do
|
1436
|
+
obj = ConfigurableSpec::UnRecommended.new
|
1437
|
+
obj.log = Fluent::Test::TestLogger.new
|
1438
|
+
obj.configure(config_element('ROOT', '', {'key1' => 'yay'}, []))
|
1439
|
+
|
1440
|
+
assert_equal 'yay', obj.key1
|
1441
|
+
first_log = obj.log.logs.first
|
1442
|
+
assert{ first_log && first_log.include?("[warn]") && first_log.include?("'key1' parameter is deprecated: key1 will be removed.") }
|
1443
|
+
end
|
1444
|
+
|
1445
|
+
test 'error raised if obsoleted parameter is configured' do
|
1446
|
+
obj = ConfigurableSpec::UnRecommended.new
|
1447
|
+
obj.log = Fluent::Test::TestLogger.new
|
1448
|
+
|
1449
|
+
assert_raise Fluent::ObsoletedParameterError.new("'key2' parameter is already removed: key2 has been removed.") do
|
1450
|
+
obj.configure(config_element('ROOT', '', {'key2' => 'yay'}, []))
|
1451
|
+
end
|
1452
|
+
first_log = obj.log.logs.first
|
1453
|
+
assert{ first_log && first_log.include?("[error]") && first_log.include?("config error in:\n<ROOT>\n key2 yay\n</ROOT>") }
|
1454
|
+
end
|
1455
|
+
|
1456
|
+
sub_test_case 'logger is nil' do
|
1457
|
+
test 'nothing raised if deprecated parameter is configured' do
|
1458
|
+
obj = ConfigurableSpec::UnRecommended.new
|
1459
|
+
obj.log = nil
|
1460
|
+
obj.configure(config_element('ROOT', '', {'key1' => 'yay'}, []))
|
1461
|
+
assert_nil(obj.log)
|
1462
|
+
end
|
1463
|
+
|
1464
|
+
test 'NoMethodError is not raised if obsoleted parameter is configured' do
|
1465
|
+
obj = ConfigurableSpec::UnRecommended.new
|
1466
|
+
obj.log = nil
|
1467
|
+
assert_raise Fluent::ObsoletedParameterError.new("'key2' parameter is already removed: key2 has been removed.") do
|
1468
|
+
obj.configure(config_element('ROOT', '', {'key2' => 'yay'}, []))
|
1469
|
+
end
|
1470
|
+
assert_nil(obj.log)
|
1471
|
+
end
|
1472
|
+
end
|
1473
|
+
end
|
1474
|
+
|
1475
|
+
sub_test_case '#config_param without default values cause error if section is configured as init:true' do
|
1476
|
+
setup do
|
1477
|
+
@type_lookup = ->(type) { Fluent::Configurable.lookup_type(type) }
|
1478
|
+
@proxy = Fluent::Config::ConfigureProxy.new(:section, type_lookup: @type_lookup)
|
1479
|
+
end
|
1480
|
+
|
1481
|
+
test 'with simple config_param with default value' do
|
1482
|
+
class InitTestClass01
|
1483
|
+
include Fluent::Configurable
|
1484
|
+
config_section :subsection, init: true do
|
1485
|
+
config_param :param1, :integer, default: 1
|
1486
|
+
end
|
1487
|
+
end
|
1488
|
+
c = InitTestClass01.new
|
1489
|
+
c.configure(config_element('root', ''))
|
1490
|
+
|
1491
|
+
assert_equal 1, c.subsection.size
|
1492
|
+
assert_equal 1, c.subsection.first.param1
|
1493
|
+
end
|
1494
|
+
|
1495
|
+
test 'with simple config_param without default value' do
|
1496
|
+
class InitTestClass02
|
1497
|
+
include Fluent::Configurable
|
1498
|
+
config_section :subsection, init: true do
|
1499
|
+
config_param :param1, :integer
|
1500
|
+
end
|
1501
|
+
end
|
1502
|
+
c = InitTestClass02.new
|
1503
|
+
assert_raises ArgumentError.new("subsection: init is specified, but there're parameters without default values:param1") do
|
1504
|
+
c.configure(config_element('root', ''))
|
1505
|
+
end
|
1506
|
+
|
1507
|
+
c.configure(config_element('root', '', {}, [config_element('subsection', '', {'param1' => '1'})]))
|
1508
|
+
|
1509
|
+
assert_equal 1, c.subsection.size
|
1510
|
+
assert_equal 1, c.subsection.first.param1
|
1511
|
+
end
|
1512
|
+
|
1513
|
+
test 'with config_param with config_set_default' do
|
1514
|
+
module InitTestModule03
|
1515
|
+
include Fluent::Configurable
|
1516
|
+
config_section :subsection, init: true do
|
1517
|
+
config_param :param1, :integer
|
1518
|
+
end
|
1519
|
+
end
|
1520
|
+
class InitTestClass03
|
1521
|
+
include Fluent::Configurable
|
1522
|
+
include InitTestModule03
|
1523
|
+
config_section :subsection do
|
1524
|
+
config_set_default :param1, 1
|
1525
|
+
end
|
1526
|
+
end
|
1527
|
+
|
1528
|
+
c = InitTestClass03.new
|
1529
|
+
c.configure(config_element('root', ''))
|
1530
|
+
|
1531
|
+
assert_equal 1, c.subsection.size
|
1532
|
+
assert_equal 1, c.subsection.first.param1
|
1533
|
+
end
|
1534
|
+
|
1535
|
+
test 'with config_argument with default value' do
|
1536
|
+
class InitTestClass04
|
1537
|
+
include Fluent::Configurable
|
1538
|
+
config_section :subsection, init: true do
|
1539
|
+
config_argument :param0, :string, default: 'yay'
|
1540
|
+
end
|
1541
|
+
end
|
1542
|
+
|
1543
|
+
c = InitTestClass04.new
|
1544
|
+
c.configure(config_element('root', ''))
|
1545
|
+
|
1546
|
+
assert_equal 1, c.subsection.size
|
1547
|
+
assert_equal 'yay', c.subsection.first.param0
|
1548
|
+
end
|
1549
|
+
|
1550
|
+
test 'with config_argument without default value' do
|
1551
|
+
class InitTestClass04
|
1552
|
+
include Fluent::Configurable
|
1553
|
+
config_section :subsection, init: true do
|
1554
|
+
config_argument :param0, :string
|
1555
|
+
end
|
1556
|
+
end
|
1557
|
+
|
1558
|
+
c = InitTestClass04.new
|
1559
|
+
assert_raise ArgumentError.new("subsection: init is specified, but default value of argument is missing") do
|
1560
|
+
c.configure(config_element('root', ''))
|
1561
|
+
end
|
1562
|
+
end
|
1563
|
+
|
1564
|
+
test 'with config_argument with config_set_default' do
|
1565
|
+
module InitTestModule05
|
1566
|
+
include Fluent::Configurable
|
1567
|
+
config_section :subsection, init: true do
|
1568
|
+
config_argument :param0, :string
|
1569
|
+
end
|
1570
|
+
end
|
1571
|
+
class InitTestClass05
|
1572
|
+
include Fluent::Configurable
|
1573
|
+
include InitTestModule05
|
1574
|
+
config_section :subsection do
|
1575
|
+
config_set_default :param0, 'foo'
|
1576
|
+
end
|
1577
|
+
end
|
1578
|
+
|
1579
|
+
c = InitTestClass05.new
|
1580
|
+
c.configure(config_element('root', ''))
|
1581
|
+
|
1582
|
+
assert_equal 1, c.subsection.size
|
1583
|
+
assert_equal 'foo', c.subsection.first.param0
|
1584
|
+
end
|
1585
|
+
end
|
1586
|
+
end
|
1587
|
+
end
|