fluentd 0.14.7-x64-mingw32 → 0.14.10-x64-mingw32

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

Potentially problematic release.


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

Files changed (120) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.travis.yml +2 -0
  4. data/CONTRIBUTING.md +6 -1
  5. data/ChangeLog +95 -0
  6. data/Rakefile +21 -0
  7. data/appveyor.yml +1 -0
  8. data/code-of-conduct.md +3 -0
  9. data/example/out_exec_filter.conf +42 -0
  10. data/fluentd.gemspec +1 -1
  11. data/lib/fluent/agent.rb +2 -2
  12. data/lib/fluent/command/binlog_reader.rb +1 -1
  13. data/lib/fluent/command/cat.rb +15 -4
  14. data/lib/fluent/compat/output.rb +14 -9
  15. data/lib/fluent/compat/parser.rb +141 -11
  16. data/lib/fluent/config/configure_proxy.rb +2 -11
  17. data/lib/fluent/config/section.rb +8 -1
  18. data/lib/fluent/configurable.rb +1 -3
  19. data/lib/fluent/env.rb +1 -1
  20. data/lib/fluent/log.rb +1 -1
  21. data/lib/fluent/plugin/base.rb +17 -0
  22. data/lib/fluent/plugin/filter_parser.rb +108 -0
  23. data/lib/fluent/plugin/filter_record_transformer.rb +14 -35
  24. data/lib/fluent/plugin/filter_stdout.rb +1 -1
  25. data/lib/fluent/plugin/formatter.rb +5 -0
  26. data/lib/fluent/plugin/formatter_msgpack.rb +4 -0
  27. data/lib/fluent/plugin/formatter_stdout.rb +3 -2
  28. data/lib/fluent/plugin/formatter_tsv.rb +34 -0
  29. data/lib/fluent/plugin/in_exec.rb +48 -93
  30. data/lib/fluent/plugin/in_forward.rb +66 -265
  31. data/lib/fluent/plugin/in_http.rb +68 -65
  32. data/lib/fluent/plugin/in_monitor_agent.rb +8 -4
  33. data/lib/fluent/plugin/in_syslog.rb +42 -58
  34. data/lib/fluent/plugin/in_tail.rb +29 -14
  35. data/lib/fluent/plugin/in_tcp.rb +54 -14
  36. data/lib/fluent/plugin/in_udp.rb +49 -13
  37. data/lib/fluent/plugin/multi_output.rb +1 -3
  38. data/lib/fluent/plugin/out_exec.rb +58 -71
  39. data/lib/fluent/plugin/out_exec_filter.rb +199 -279
  40. data/lib/fluent/plugin/out_file.rb +172 -81
  41. data/lib/fluent/plugin/out_forward.rb +229 -206
  42. data/lib/fluent/plugin/out_stdout.rb +6 -21
  43. data/lib/fluent/plugin/output.rb +90 -59
  44. data/lib/fluent/plugin/parser.rb +121 -61
  45. data/lib/fluent/plugin/parser_csv.rb +9 -3
  46. data/lib/fluent/plugin/parser_json.rb +37 -35
  47. data/lib/fluent/plugin/parser_ltsv.rb +11 -19
  48. data/lib/fluent/plugin/parser_msgpack.rb +50 -0
  49. data/lib/fluent/plugin/parser_regexp.rb +15 -42
  50. data/lib/fluent/plugin/parser_tsv.rb +8 -3
  51. data/lib/fluent/plugin_helper.rb +10 -1
  52. data/lib/fluent/plugin_helper/child_process.rb +139 -73
  53. data/lib/fluent/plugin_helper/compat_parameters.rb +93 -4
  54. data/lib/fluent/plugin_helper/event_emitter.rb +14 -1
  55. data/lib/fluent/plugin_helper/event_loop.rb +24 -6
  56. data/lib/fluent/plugin_helper/extract.rb +16 -4
  57. data/lib/fluent/plugin_helper/formatter.rb +9 -11
  58. data/lib/fluent/plugin_helper/inject.rb +16 -1
  59. data/lib/fluent/plugin_helper/parser.rb +3 -3
  60. data/lib/fluent/plugin_helper/server.rb +494 -0
  61. data/lib/fluent/plugin_helper/socket.rb +101 -0
  62. data/lib/fluent/plugin_helper/socket_option.rb +84 -0
  63. data/lib/fluent/plugin_helper/timer.rb +1 -0
  64. data/lib/fluent/root_agent.rb +1 -1
  65. data/lib/fluent/test/driver/base.rb +95 -49
  66. data/lib/fluent/test/driver/base_owner.rb +18 -8
  67. data/lib/fluent/test/driver/multi_output.rb +2 -1
  68. data/lib/fluent/test/driver/output.rb +29 -6
  69. data/lib/fluent/test/helpers.rb +3 -1
  70. data/lib/fluent/test/log.rb +4 -0
  71. data/lib/fluent/test/startup_shutdown.rb +13 -0
  72. data/lib/fluent/time.rb +14 -8
  73. data/lib/fluent/version.rb +1 -1
  74. data/lib/fluent/winsvc.rb +1 -1
  75. data/test/command/test_binlog_reader.rb +5 -1
  76. data/test/compat/test_parser.rb +10 -0
  77. data/test/config/test_configurable.rb +193 -0
  78. data/test/config/test_configure_proxy.rb +0 -43
  79. data/test/helper.rb +36 -1
  80. data/test/plugin/test_base.rb +16 -0
  81. data/test/plugin/test_filter_parser.rb +665 -0
  82. data/test/plugin/test_filter_record_transformer.rb +36 -100
  83. data/test/plugin/test_filter_stdout.rb +18 -27
  84. data/test/plugin/test_in_dummy.rb +1 -1
  85. data/test/plugin/test_in_exec.rb +206 -94
  86. data/test/plugin/test_in_forward.rb +268 -347
  87. data/test/plugin/test_in_http.rb +310 -186
  88. data/test/plugin/test_in_monitor_agent.rb +65 -35
  89. data/test/plugin/test_in_syslog.rb +39 -3
  90. data/test/plugin/test_in_tcp.rb +78 -62
  91. data/test/plugin/test_in_udp.rb +101 -80
  92. data/test/plugin/test_out_exec.rb +223 -68
  93. data/test/plugin/test_out_exec_filter.rb +520 -169
  94. data/test/plugin/test_out_file.rb +637 -177
  95. data/test/plugin/test_out_forward.rb +242 -234
  96. data/test/plugin/test_out_null.rb +1 -1
  97. data/test/plugin/test_out_secondary_file.rb +4 -2
  98. data/test/plugin/test_out_stdout.rb +14 -35
  99. data/test/plugin/test_output_as_buffered.rb +60 -2
  100. data/test/plugin/test_parser.rb +359 -0
  101. data/test/plugin/test_parser_csv.rb +1 -2
  102. data/test/plugin/test_parser_json.rb +3 -4
  103. data/test/plugin/test_parser_labeled_tsv.rb +1 -2
  104. data/test/plugin/test_parser_none.rb +1 -2
  105. data/test/plugin/test_parser_regexp.rb +8 -4
  106. data/test/plugin/test_parser_tsv.rb +4 -3
  107. data/test/plugin_helper/test_child_process.rb +184 -0
  108. data/test/plugin_helper/test_compat_parameters.rb +88 -1
  109. data/test/plugin_helper/test_extract.rb +0 -1
  110. data/test/plugin_helper/test_formatter.rb +5 -2
  111. data/test/plugin_helper/test_inject.rb +21 -0
  112. data/test/plugin_helper/test_parser.rb +6 -5
  113. data/test/plugin_helper/test_server.rb +905 -0
  114. data/test/test_event_time.rb +3 -1
  115. data/test/test_output.rb +53 -2
  116. data/test/test_plugin_classes.rb +20 -0
  117. data/test/test_root_agent.rb +139 -0
  118. data/test/test_test_drivers.rb +135 -0
  119. metadata +28 -8
  120. data/test/plugin/test_parser_base.rb +0 -32
@@ -37,10 +37,11 @@ module Fluent
37
37
  end
38
38
 
39
39
  def run_actual(**kwargs, &block)
40
- super(**kwargs, &block)
40
+ val = super(**kwargs, &block)
41
41
  if @flush_buffer_at_cleanup
42
42
  @instance.outputs.each{|o| o.force_flush }
43
43
  end
44
+ val
44
45
  end
45
46
 
46
47
  def flush
@@ -29,23 +29,31 @@ module Fluent
29
29
  def initialize(klass, opts: {}, &block)
30
30
  super
31
31
  raise ArgumentError, "plugin is not an instance of Fluent::Plugin::Output" unless @instance.is_a? Fluent::Plugin::Output
32
- @instance.in_tests = true
33
32
  @flush_buffer_at_cleanup = nil
33
+ @wait_flush_completion = nil
34
+ @force_flush_retry = nil
34
35
  @format_hook = nil
35
36
  @format_results = []
36
37
  end
37
38
 
38
- def run(flush: true, **kwargs, &block)
39
+ def run(flush: true, wait_flush_completion: true, force_flush_retry: false, **kwargs, &block)
39
40
  @flush_buffer_at_cleanup = flush
41
+ @wait_flush_completion = wait_flush_completion
42
+ @force_flush_retry = force_flush_retry
40
43
  super(**kwargs, &block)
41
44
  end
42
45
 
43
46
  def run_actual(**kwargs, &block)
44
- super(**kwargs, &block)
47
+ if @force_flush_retry
48
+ @instance.retry_for_error_chunk = true
49
+ end
50
+ val = super(**kwargs, &block)
45
51
  if @flush_buffer_at_cleanup
46
- @instance.force_flush
47
- Timeout.timeout(10){ sleep 0.1 until !@instance.buffer || @instance.buffer.queue.size == 0 }
52
+ self.flush
48
53
  end
54
+ val
55
+ ensure
56
+ @instance.retry_for_error_chunk = false
49
57
  end
50
58
 
51
59
  def formatted
@@ -54,7 +62,22 @@ module Fluent
54
62
 
55
63
  def flush
56
64
  @instance.force_flush
57
- Timeout.timeout(10){ sleep 0.1 until !@instance.buffer || @instance.buffer.queue.size == 0 }
65
+ wait_flush_completion if @wait_flush_completion
66
+ end
67
+
68
+ def wait_flush_completion
69
+ buffer_queue = ->(){ @instance.buffer && @instance.buffer.queue.size > 0 }
70
+ dequeued_chunks = ->(){
71
+ @instance.dequeued_chunks_mutex &&
72
+ @instance.dequeued_chunks &&
73
+ @instance.dequeued_chunks_mutex.synchronize{ @instance.dequeued_chunks.size > 0 }
74
+ }
75
+
76
+ Timeout.timeout(10) do
77
+ while buffer_queue.call || dequeued_chunks.call
78
+ sleep 0.1
79
+ end
80
+ end
58
81
  end
59
82
 
60
83
  def instance_hook_after_started
@@ -23,7 +23,9 @@ module Fluent
23
23
  module Helpers
24
24
  # See "Example Custom Assertion: http://test-unit.github.io/test-unit/en/Test/Unit/Assertions.html
25
25
  def assert_equal_event_time(expected, actual, message = nil)
26
- message = build_message(message, <<EOT, expected, actual)
26
+ expected_s = "#{Time.at(expected.sec)} (nsec #{expected.nsec})"
27
+ actual_s = "#{Time.at(actual.sec) } (nsec #{actual.nsec})"
28
+ message = build_message(message, <<EOT, expected_s, actual_s)
27
29
  <?> expected but was
28
30
  <?>.
29
31
  EOT
@@ -26,6 +26,7 @@ module Fluent
26
26
  def initialize
27
27
  @logs = []
28
28
  @flush_logs = true
29
+ @use_stderr = false
29
30
  end
30
31
 
31
32
  def reset
@@ -41,6 +42,9 @@ module Fluent
41
42
  end
42
43
 
43
44
  def write(message)
45
+ if @use_stderr
46
+ STDERR.write message
47
+ end
44
48
  @logs.push message
45
49
  end
46
50
 
@@ -15,6 +15,7 @@
15
15
  #
16
16
 
17
17
  require 'serverengine'
18
+ require 'fileutils'
18
19
 
19
20
  module Fluent
20
21
  module Test
@@ -28,6 +29,18 @@ module Fluent
28
29
  def shutdown
29
30
  @server.close
30
31
  end
32
+
33
+ def self.setup
34
+ @socket_manager_path = ServerEngine::SocketManager::Server.generate_path
35
+ @server = ServerEngine::SocketManager::Server.open(@socket_manager_path)
36
+ ENV['SERVERENGINE_SOCKETMANAGER_PATH'] = @socket_manager_path.to_s
37
+ end
38
+
39
+ def self.teardown
40
+ @server.close
41
+ # on Windows, socket_manager_path is a TCP port number
42
+ FileUtils.rm_f @socket_manager_path unless Fluent.windows?
43
+ end
31
44
  end
32
45
  end
33
46
  end
@@ -50,6 +50,10 @@ module Fluent
50
50
  @sec
51
51
  end
52
52
 
53
+ def to_f
54
+ @sec + @nsec / 1_000_000_000.0
55
+ end
56
+
53
57
  # for Time.at
54
58
  def to_r
55
59
  Rational(@sec * 1_000_000_000 + @nsec, 1_000_000_000)
@@ -107,6 +111,8 @@ module Fluent
107
111
  end
108
112
 
109
113
  module TimeMixin
114
+ TIME_TYPES = ['string', 'unixtime', 'float']
115
+
110
116
  TIME_PARAMETERS = [
111
117
  [:time_format, :string, {default: nil}],
112
118
  [:localtime, :bool, {default: true}], # UTC if :localtime is false and :timezone is nil
@@ -115,7 +121,7 @@ module Fluent
115
121
  ]
116
122
  TIME_FULL_PARAMETERS = [
117
123
  # To avoid to define :time_type twice (in plugin_helper/inject)
118
- [:time_type, :enum, {default: :string, list: [:string, :unixtime, :float]}],
124
+ [:time_type, :enum, {default: :string, list: TIME_TYPES.map(&:to_sym)}],
119
125
  ] + TIME_PARAMETERS
120
126
 
121
127
  module TimeParameters
@@ -197,7 +203,7 @@ module Fluent
197
203
  else Time.now.localtime.utc_offset # utc
198
204
  end
199
205
 
200
- strptime = format && (Strptime.new(time_format) rescue nil)
206
+ strptime = format && (Strptime.new(format) rescue nil)
201
207
 
202
208
  @parse = case
203
209
  when format_with_timezone && strptime then ->(v){ Fluent::EventTime.from_time(strptime.exec(v)) }
@@ -248,8 +254,8 @@ module Fluent
248
254
  end
249
255
 
250
256
  def parse_unixtime(value)
251
- unless value.is_a?(String)
252
- raise TimeParseError, "value must be a string: #{value}"
257
+ unless value.is_a?(String) || value.is_a?(Numeric)
258
+ raise TimeParseError, "value must be a string or a number: #{value}(value.class)"
253
259
  end
254
260
 
255
261
  if @cache1_key == value
@@ -279,8 +285,8 @@ module Fluent
279
285
  ## parse_by_to_r (full): 28.722362 sec
280
286
  ## parse_by_to_r (msec): 28.232856 sec
281
287
  def parse_float(value)
282
- unless value.is_a?(String)
283
- raise TimeParseError, "value must be a string: #{value}"
288
+ unless value.is_a?(String) || value.is_a?(Numeric)
289
+ raise TimeParseError, "value must be a string or a number: #{value}(value.class)"
284
290
  end
285
291
 
286
292
  if @cache1_key == value
@@ -290,8 +296,8 @@ module Fluent
290
296
  end
291
297
 
292
298
  begin
293
- sec_s, nsec_s, _ = value.split('.', 3) # throw away second-dot and later
294
- nsec_s = nsec_s[0..9]
299
+ sec_s, nsec_s, _ = value.to_s.split('.', 3) # throw away second-dot and later
300
+ nsec_s = nsec_s && nsec_s[0..9] || '0'
295
301
  nsec_s += '0' * (9 - nsec_s.size) if nsec_s.size < 9
296
302
  time = Fluent::EventTime.new(sec_s.to_i, nsec_s.to_i)
297
303
  rescue => e
@@ -16,6 +16,6 @@
16
16
 
17
17
  module Fluent
18
18
 
19
- VERSION = '0.14.7'
19
+ VERSION = '0.14.10'
20
20
 
21
21
  end
@@ -58,7 +58,7 @@ begin
58
58
  ev.set
59
59
  ev.close
60
60
  if @pid > 0
61
- Porcess.waitpid(@pid)
61
+ Process.waitpid(@pid)
62
62
  end
63
63
  end
64
64
  end
@@ -58,9 +58,13 @@ class TestBaseCommand < ::Test::Unit::TestCase
58
58
  def create_message_packed_file(path, times = [event_time], records = [{ 'message' => 'dummy' }])
59
59
  es = Fluent::MultiEventStream.new(times, records)
60
60
  v = es.to_msgpack_stream
61
- File.open("#{TMP_DIR}/#{path}", 'w') do |f|
61
+ out_path = "#{TMP_DIR}/#{path}"
62
+ File.open(out_path, 'wb') do |f|
62
63
  f.print(v)
63
64
  end
65
+ waiting(5) do
66
+ sleep 0.5 until File.size(out_path) == v.bytesize
67
+ end
64
68
  end
65
69
 
66
70
  def setup
@@ -79,4 +79,14 @@ class TextParserTest < ::Test::Unit::TestCase
79
79
  p2.configure('format' => 'none')
80
80
  assert_equal false, p2.parser.estimate_current_event
81
81
  end
82
+
83
+ data(ignorecase: Regexp::IGNORECASE,
84
+ multiline: Regexp::MULTILINE,
85
+ both: Regexp::IGNORECASE & Regexp::MULTILINE)
86
+ def test_regexp_parser_config(options)
87
+ source = "a"
88
+ parser = Fluent::TextParser::RegexpParser.new(Regexp.new(source, options), { "dummy" => "dummy" })
89
+ regexp = parser.instance_variable_get("@regexp")
90
+ assert_equal(options, regexp.options)
91
+ end
82
92
  end
@@ -334,6 +334,12 @@ module ConfigurableSpec
334
334
  end
335
335
  end
336
336
 
337
+ class NilOwner < Owner
338
+ config_section :buffer do
339
+ config_set_default :size_of_something, nil
340
+ end
341
+ end
342
+
337
343
  class FlatChild
338
344
  include Fluent::Configurable
339
345
  attr_accessor :owner
@@ -346,6 +352,19 @@ module ConfigurableSpec
346
352
  configured_in :buffer
347
353
  config_param :size_of_something, :size, default: 128
348
354
  end
355
+
356
+ class BufferBase
357
+ include Fluent::Configurable
358
+ end
359
+
360
+ class BufferSubclass < BufferBase
361
+ attr_accessor :owner
362
+ configured_in :buffer
363
+ config_param :size_of_something, :size, default: 512
364
+ end
365
+
366
+ class BufferSubSubclass < BufferSubclass
367
+ end
349
368
  end
350
369
  class UnRecommended
351
370
  include Fluent::Configurable
@@ -1038,6 +1057,8 @@ module Fluent::Config
1038
1057
  test 'for feature plugin which has flat parameters with parent' do
1039
1058
  owner = ConfigurableSpec::OverwriteDefaults::Owner.new
1040
1059
  child = ConfigurableSpec::OverwriteDefaults::FlatChild.new
1060
+ assert_nil child.class.merged_configure_proxy.configured_in_section
1061
+
1041
1062
  child.owner = owner
1042
1063
  child.configure(config_element('ROOT', '', {}, []))
1043
1064
  assert_equal "V1", child.key1
@@ -1046,6 +1067,8 @@ module Fluent::Config
1046
1067
  test 'for feature plugin which has parameters in subsection of parent' do
1047
1068
  owner = ConfigurableSpec::OverwriteDefaults::Owner.new
1048
1069
  child = ConfigurableSpec::OverwriteDefaults::BufferChild.new
1070
+ assert_equal :buffer, child.class.merged_configure_proxy.configured_in_section
1071
+
1049
1072
  child.owner = owner
1050
1073
  child.configure(config_element('ROOT', '', {}, []))
1051
1074
  assert_equal 1024, child.size_of_something
@@ -1054,10 +1077,48 @@ module Fluent::Config
1054
1077
  test 'even in subclass of owner' do
1055
1078
  owner = ConfigurableSpec::OverwriteDefaults::SubOwner.new
1056
1079
  child = ConfigurableSpec::OverwriteDefaults::BufferChild.new
1080
+ assert_equal :buffer, child.class.merged_configure_proxy.configured_in_section
1081
+
1057
1082
  child.owner = owner
1058
1083
  child.configure(config_element('ROOT', '', {}, []))
1059
1084
  assert_equal 2048, child.size_of_something
1060
1085
  end
1086
+
1087
+ test 'default values can be overwritten with nil' do
1088
+ owner = ConfigurableSpec::OverwriteDefaults::NilOwner.new
1089
+ child = ConfigurableSpec::OverwriteDefaults::BufferChild.new
1090
+ assert_equal :buffer, child.class.merged_configure_proxy.configured_in_section
1091
+
1092
+ child.owner = owner
1093
+ child.configure(config_element('ROOT', '', {}, []))
1094
+ assert_nil child.size_of_something
1095
+ end
1096
+
1097
+ test 'the first configured_in (in the order from base class) will be applied' do
1098
+ child = ConfigurableSpec::OverwriteDefaults::BufferSubclass.new
1099
+ assert_equal :buffer, child.class.merged_configure_proxy.configured_in_section
1100
+
1101
+ child.configure(config_element('ROOT', '', {}, []))
1102
+ assert_equal 512, child.size_of_something
1103
+ end
1104
+
1105
+ test 'the first configured_in is valid with owner classes' do
1106
+ owner = ConfigurableSpec::OverwriteDefaults::Owner.new
1107
+ child = ConfigurableSpec::OverwriteDefaults::BufferSubclass.new
1108
+ assert_equal :buffer, child.class.merged_configure_proxy.configured_in_section
1109
+
1110
+ child.owner = owner
1111
+ child.configure(config_element('ROOT', '', {}, []))
1112
+ assert_equal 1024, child.size_of_something
1113
+ end
1114
+
1115
+ test 'the only first configured_in is valid even in subclasses of a class with configured_in' do
1116
+ child = ConfigurableSpec::OverwriteDefaults::BufferSubSubclass.new
1117
+ assert_equal :buffer, child.class.merged_configure_proxy.configured_in_section
1118
+
1119
+ child.configure(config_element('ROOT', '', {}, []))
1120
+ assert_equal 512, child.size_of_something
1121
+ end
1061
1122
  end
1062
1123
 
1063
1124
  sub_test_case ':secret option' do
@@ -1234,6 +1295,138 @@ module Fluent::Config
1234
1295
  assert_raise Fluent::ObsoletedParameterError.new("'key2' parameter is already removed: key2 has been removed.") do
1235
1296
  obj.configure(config_element('ROOT', '', {'key2' => 'yay'}, []))
1236
1297
  end
1298
+ first_log = obj.log.logs.first
1299
+ assert{ first_log && first_log.include?("[error]") && first_log.include?("config error in:\n<ROOT>\n key2 yay\n</ROOT>") }
1300
+ end
1301
+
1302
+ sub_test_case 'logger is nil' do
1303
+ test 'nothing raised if deprecated parameter is configured' do
1304
+ obj = ConfigurableSpec::UnRecommended.new
1305
+ obj.log = nil
1306
+ obj.configure(config_element('ROOT', '', {'key1' => 'yay'}, []))
1307
+ assert_nil(obj.log)
1308
+ end
1309
+
1310
+ test 'NoMethodError is not raised if obsoleted parameter is configured' do
1311
+ obj = ConfigurableSpec::UnRecommended.new
1312
+ obj.log = nil
1313
+ assert_raise Fluent::ObsoletedParameterError.new("'key2' parameter is already removed: key2 has been removed.") do
1314
+ obj.configure(config_element('ROOT', '', {'key2' => 'yay'}, []))
1315
+ end
1316
+ assert_nil(obj.log)
1317
+ end
1318
+ end
1319
+ end
1320
+
1321
+ sub_test_case '#config_param without default values cause error if section is configured as init:true' do
1322
+ setup do
1323
+ @type_lookup = ->(type) { Fluent::Configurable.lookup_type(type) }
1324
+ @proxy = Fluent::Config::ConfigureProxy.new(:section, type_lookup: @type_lookup)
1325
+ end
1326
+
1327
+ test 'with simple config_param with default value' do
1328
+ class InitTestClass01
1329
+ include Fluent::Configurable
1330
+ config_section :subsection, init: true do
1331
+ config_param :param1, :integer, default: 1
1332
+ end
1333
+ end
1334
+ c = InitTestClass01.new
1335
+ c.configure(config_element('root', ''))
1336
+
1337
+ assert_equal 1, c.subsection.size
1338
+ assert_equal 1, c.subsection.first.param1
1339
+ end
1340
+
1341
+ test 'with simple config_param without default value' do
1342
+ class InitTestClass02
1343
+ include Fluent::Configurable
1344
+ config_section :subsection, init: true do
1345
+ config_param :param1, :integer
1346
+ end
1347
+ end
1348
+ c = InitTestClass02.new
1349
+ assert_raises ArgumentError.new("subsection: init is specified, but there're parameters without default values:param1") do
1350
+ c.configure(config_element('root', ''))
1351
+ end
1352
+
1353
+ c.configure(config_element('root', '', {}, [config_element('subsection', '', {'param1' => '1'})]))
1354
+
1355
+ assert_equal 1, c.subsection.size
1356
+ assert_equal 1, c.subsection.first.param1
1357
+ end
1358
+
1359
+ test 'with config_param with config_set_default' do
1360
+ module InitTestModule03
1361
+ include Fluent::Configurable
1362
+ config_section :subsection, init: true do
1363
+ config_param :param1, :integer
1364
+ end
1365
+ end
1366
+ class InitTestClass03
1367
+ include Fluent::Configurable
1368
+ include InitTestModule03
1369
+ config_section :subsection do
1370
+ config_set_default :param1, 1
1371
+ end
1372
+ end
1373
+
1374
+ c = InitTestClass03.new
1375
+ c.configure(config_element('root', ''))
1376
+
1377
+ assert_equal 1, c.subsection.size
1378
+ assert_equal 1, c.subsection.first.param1
1379
+ end
1380
+
1381
+ test 'with config_argument with default value' do
1382
+ class InitTestClass04
1383
+ include Fluent::Configurable
1384
+ config_section :subsection, init: true do
1385
+ config_argument :param0, :string, default: 'yay'
1386
+ end
1387
+ end
1388
+
1389
+ c = InitTestClass04.new
1390
+ c.configure(config_element('root', ''))
1391
+
1392
+ assert_equal 1, c.subsection.size
1393
+ assert_equal 'yay', c.subsection.first.param0
1394
+ end
1395
+
1396
+ test 'with config_argument without default value' do
1397
+ class InitTestClass04
1398
+ include Fluent::Configurable
1399
+ config_section :subsection, init: true do
1400
+ config_argument :param0, :string
1401
+ end
1402
+ end
1403
+
1404
+ c = InitTestClass04.new
1405
+ assert_raise ArgumentError.new("subsection: init is specified, but default value of argument is missing") do
1406
+ c.configure(config_element('root', ''))
1407
+ end
1408
+ end
1409
+
1410
+ test 'with config_argument with config_set_default' do
1411
+ module InitTestModule05
1412
+ include Fluent::Configurable
1413
+ config_section :subsection, init: true do
1414
+ config_argument :param0, :string
1415
+ end
1416
+ end
1417
+ class InitTestClass05
1418
+ include Fluent::Configurable
1419
+ include InitTestModule05
1420
+ config_section :subsection do
1421
+ config_set_default :param0, 'foo'
1422
+ end
1423
+ end
1424
+
1425
+ c = InitTestClass05.new
1426
+ c.configure(config_element('root', ''))
1427
+
1428
+ assert_equal 1, c.subsection.size
1429
+ assert_equal 'foo', c.subsection.first.param0
1237
1430
  end
1238
1431
  end
1239
1432
  end