fluentd 1.11.4-x64-mingw32 → 1.12.3-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 (108) hide show
  1. checksums.yaml +4 -4
  2. data/.deepsource.toml +13 -0
  3. data/.github/ISSUE_TEMPLATE/bug_report.md +1 -1
  4. data/.github/ISSUE_TEMPLATE/config.yml +5 -0
  5. data/.github/workflows/linux-test.yaml +36 -0
  6. data/.github/workflows/macos-test.yaml +30 -0
  7. data/.github/workflows/stale-actions.yml +22 -0
  8. data/.github/workflows/windows-test.yaml +35 -0
  9. data/.gitlab-ci.yml +41 -19
  10. data/CHANGELOG.md +166 -0
  11. data/MAINTAINERS.md +5 -2
  12. data/README.md +7 -4
  13. data/bin/fluent-cap-ctl +7 -0
  14. data/bin/fluent-ctl +7 -0
  15. data/fluentd.gemspec +7 -5
  16. data/lib/fluent/capability.rb +87 -0
  17. data/lib/fluent/command/bundler_injection.rb +1 -1
  18. data/lib/fluent/command/ca_generate.rb +6 -3
  19. data/lib/fluent/command/cap_ctl.rb +174 -0
  20. data/lib/fluent/command/cat.rb +0 -1
  21. data/lib/fluent/command/ctl.rb +177 -0
  22. data/lib/fluent/command/fluentd.rb +4 -0
  23. data/lib/fluent/command/plugin_config_formatter.rb +18 -2
  24. data/lib/fluent/command/plugin_generator.rb +31 -1
  25. data/lib/fluent/compat/parser.rb +2 -2
  26. data/lib/fluent/config/section.rb +2 -2
  27. data/lib/fluent/config/types.rb +2 -2
  28. data/lib/fluent/env.rb +4 -0
  29. data/lib/fluent/event.rb +3 -13
  30. data/lib/fluent/load.rb +0 -1
  31. data/lib/fluent/plugin.rb +5 -0
  32. data/lib/fluent/plugin/buffer.rb +2 -21
  33. data/lib/fluent/plugin/file_wrapper.rb +39 -3
  34. data/lib/fluent/plugin/formatter.rb +24 -0
  35. data/lib/fluent/plugin/formatter_csv.rb +1 -1
  36. data/lib/fluent/plugin/formatter_hash.rb +3 -1
  37. data/lib/fluent/plugin/formatter_json.rb +3 -1
  38. data/lib/fluent/plugin/formatter_ltsv.rb +7 -5
  39. data/lib/fluent/plugin/formatter_out_file.rb +6 -4
  40. data/lib/fluent/plugin/formatter_single_value.rb +4 -2
  41. data/lib/fluent/plugin/formatter_tsv.rb +4 -2
  42. data/lib/fluent/plugin/in_http.rb +24 -3
  43. data/lib/fluent/plugin/in_monitor_agent.rb +1 -1
  44. data/lib/fluent/plugin/in_tail.rb +129 -41
  45. data/lib/fluent/plugin/in_tail/position_file.rb +39 -14
  46. data/lib/fluent/plugin/in_tcp.rb +1 -0
  47. data/lib/fluent/plugin/out_copy.rb +18 -5
  48. data/lib/fluent/plugin/out_exec_filter.rb +3 -3
  49. data/lib/fluent/plugin/out_forward.rb +61 -28
  50. data/lib/fluent/plugin/out_http.rb +28 -3
  51. data/lib/fluent/plugin/output.rb +18 -10
  52. data/lib/fluent/plugin/parser_csv.rb +2 -2
  53. data/lib/fluent/plugin/parser_syslog.rb +2 -2
  54. data/lib/fluent/plugin/storage_local.rb +4 -4
  55. data/lib/fluent/plugin_helper/http_server/compat/server.rb +1 -1
  56. data/lib/fluent/plugin_helper/inject.rb +4 -2
  57. data/lib/fluent/plugin_helper/retry_state.rb +4 -0
  58. data/lib/fluent/plugin_helper/server.rb +4 -2
  59. data/lib/fluent/plugin_helper/socket_option.rb +2 -2
  60. data/lib/fluent/supervisor.rb +153 -48
  61. data/lib/fluent/system_config.rb +2 -1
  62. data/lib/fluent/time.rb +58 -1
  63. data/lib/fluent/version.rb +1 -1
  64. data/lib/fluent/winsvc.rb +22 -4
  65. data/templates/new_gem/fluent-plugin.gemspec.erb +3 -3
  66. data/templates/plugin_config_formatter/param.md-table.erb +10 -0
  67. data/test/command/test_binlog_reader.rb +22 -6
  68. data/test/command/test_cap_ctl.rb +100 -0
  69. data/test/command/test_ctl.rb +57 -0
  70. data/test/command/test_fluentd.rb +38 -0
  71. data/test/command/test_plugin_config_formatter.rb +124 -2
  72. data/test/config/test_configurable.rb +1 -1
  73. data/test/plugin/in_tail/test_position_file.rb +46 -26
  74. data/test/plugin/test_file_wrapper.rb +105 -0
  75. data/test/plugin/test_filter_stdout.rb +6 -1
  76. data/test/plugin/test_formatter_hash.rb +6 -3
  77. data/test/plugin/test_formatter_json.rb +14 -4
  78. data/test/plugin/test_formatter_ltsv.rb +13 -5
  79. data/test/plugin/test_formatter_out_file.rb +35 -14
  80. data/test/plugin/test_formatter_single_value.rb +12 -6
  81. data/test/plugin/test_formatter_tsv.rb +12 -4
  82. data/test/plugin/test_in_exec.rb +1 -1
  83. data/test/plugin/test_in_http.rb +25 -0
  84. data/test/plugin/test_in_tail.rb +503 -42
  85. data/test/plugin/test_out_copy.rb +87 -0
  86. data/test/plugin/test_out_file.rb +23 -18
  87. data/test/plugin/test_out_forward.rb +94 -6
  88. data/test/plugin/test_out_http.rb +20 -1
  89. data/test/plugin/test_output.rb +15 -3
  90. data/test/plugin/test_output_as_buffered_backup.rb +2 -0
  91. data/test/plugin/test_parser_csv.rb +14 -0
  92. data/test/plugin/test_parser_syslog.rb +16 -2
  93. data/test/plugin/test_sd_file.rb +1 -1
  94. data/test/plugin_helper/service_discovery/test_manager.rb +1 -1
  95. data/test/plugin_helper/test_child_process.rb +5 -2
  96. data/test/plugin_helper/test_compat_parameters.rb +7 -2
  97. data/test/plugin_helper/test_http_server_helper.rb +4 -2
  98. data/test/plugin_helper/test_inject.rb +29 -0
  99. data/test/plugin_helper/test_server.rb +26 -7
  100. data/test/test_capability.rb +74 -0
  101. data/test/test_event.rb +16 -0
  102. data/test/test_formatter.rb +64 -10
  103. data/test/test_output.rb +8 -3
  104. data/test/test_supervisor.rb +150 -1
  105. data/test/test_time_parser.rb +109 -0
  106. metadata +87 -33
  107. data/.travis.yml +0 -57
  108. data/appveyor.yml +0 -28
@@ -56,6 +56,32 @@ class TestFluentPluginConfigFormatter < Test::Unit::TestCase
56
56
  end
57
57
  end
58
58
 
59
+ class FakeStorage < ::Fluent::Plugin::Storage
60
+ ::Fluent::Plugin.register_storage('fake', self)
61
+
62
+ def get(key)
63
+ end
64
+
65
+ def fetch(key, defval)
66
+ end
67
+
68
+ def put(key, value)
69
+ end
70
+
71
+ def delete(key)
72
+ end
73
+
74
+ def update(key, &block)
75
+ end
76
+ end
77
+
78
+ class FakeServiceDiscovery < ::Fluent::Plugin::ServiceDiscovery
79
+ ::Fluent::Plugin.register_sd('fake', self)
80
+
81
+ desc "hostname"
82
+ config_param :hostname, :string
83
+ end
84
+
59
85
  class SimpleInput < ::Fluent::Plugin::Input
60
86
  ::Fluent::Plugin.register_input("simple", self)
61
87
  helpers :inject, :compat_parameters
@@ -88,6 +114,13 @@ class TestFluentPluginConfigFormatter < Test::Unit::TestCase
88
114
  end
89
115
  end
90
116
 
117
+ class SimpleServiceDiscovery < ::Fluent::Plugin::ServiceDiscovery
118
+ ::Fluent::Plugin.register_sd('simple', self)
119
+
120
+ desc "servers"
121
+ config_param :servers, :array
122
+ end
123
+
91
124
  sub_test_case "json" do
92
125
  data(input: [FakeInput, "input"],
93
126
  output: [FakeOutput, "output"],
@@ -196,6 +229,52 @@ TEXT
196
229
  assert_equal(expected, dumped_config)
197
230
  end
198
231
 
232
+ test "input simple (table)" do
233
+ dumped_config = capture_stdout do
234
+ FluentPluginConfigFormatter.new(["--format=markdown", "--table", "input", "simple"]).call
235
+ end
236
+ expected = <<TEXT
237
+ ## Plugin helpers
238
+
239
+ * [inject](https://docs.fluentd.org/v/1.0/plugin-helper-overview/api-plugin-helper-inject)
240
+ * [compat_parameters](https://docs.fluentd.org/v/1.0/plugin-helper-overview/api-plugin-helper-compat_parameters)
241
+
242
+ * See also: [Input Plugin Overview](https://docs.fluentd.org/v/1.0/input#overview)
243
+
244
+ ## TestFluentPluginConfigFormatter::SimpleInput
245
+
246
+ ### Configuration
247
+
248
+ |parameter|type|description|default|
249
+ |---|---|---|---|
250
+ |path|string (required)|path to something||
251
+
252
+ TEXT
253
+ assert_equal(expected, dumped_config)
254
+ end
255
+
256
+ data("abbrev" => "sd",
257
+ "normal" => "service_discovery")
258
+ test "service_discovery simple" do |data|
259
+ plugin_type = data
260
+ dumped_config = capture_stdout do
261
+ FluentPluginConfigFormatter.new(["--format=markdown", plugin_type, "simple"]).call
262
+ end
263
+ expected = <<TEXT
264
+ * See also: [ServiceDiscovery Plugin Overview](https://docs.fluentd.org/v/1.0/servicediscovery#overview)
265
+
266
+ ## TestFluentPluginConfigFormatter::SimpleServiceDiscovery
267
+
268
+ ### servers (array) (required)
269
+
270
+ servers
271
+
272
+
273
+ TEXT
274
+ assert_equal(expected, dumped_config)
275
+ end
276
+
277
+
199
278
  test "output complex" do
200
279
  dumped_config = capture_stdout do
201
280
  FluentPluginConfigFormatter.new(["--format=markdown", "output", "complex"]).call
@@ -243,6 +322,49 @@ Default value: `normal`.
243
322
 
244
323
 
245
324
 
325
+ TEXT
326
+ assert_equal(expected, dumped_config)
327
+ end
328
+
329
+ test "output complex (table)" do
330
+ dumped_config = capture_stdout do
331
+ FluentPluginConfigFormatter.new(["--format=markdown", "--table", "output", "complex"]).call
332
+ end
333
+ expected = <<TEXT
334
+ ## Plugin helpers
335
+
336
+ * [inject](https://docs.fluentd.org/v/1.0/plugin-helper-overview/api-plugin-helper-inject)
337
+ * [compat_parameters](https://docs.fluentd.org/v/1.0/plugin-helper-overview/api-plugin-helper-compat_parameters)
338
+
339
+ * See also: [Output Plugin Overview](https://docs.fluentd.org/v/1.0/output#overview)
340
+
341
+ ## TestFluentPluginConfigFormatter::ComplexOutput
342
+
343
+
344
+ ### \\<authentication\\> section (required) (single)
345
+
346
+ ### Configuration
347
+
348
+ |parameter|type|description|default|
349
+ |---|---|---|---|
350
+ |username|string (required)|username||
351
+ |password|string (required)|password||
352
+
353
+
354
+ ### \\<parent\\> section (optional) (multiple)
355
+
356
+
357
+ #### \\<child\\> section (optional) (multiple)
358
+
359
+ ### Configuration
360
+
361
+ |parameter|type|description|default|
362
+ |---|---|---|---|
363
+ |names|array (required)|names||
364
+ |difficulty|enum (optional)|difficulty (`easy`, `normal`, `hard`)|`normal`|
365
+
366
+
367
+
246
368
  TEXT
247
369
  assert_equal(expected, dumped_config)
248
370
  end
@@ -251,7 +373,7 @@ TEXT
251
373
  sub_test_case "arguments" do
252
374
  data do
253
375
  hash = {}
254
- ["input", "output", "filter", "parser", "formatter"].each do |type|
376
+ ["input", "output", "filter", "parser", "formatter", "storage", "service_discovery"].each do |type|
255
377
  ["txt", "json", "markdown"].each do |format|
256
378
  argv = ["--format=#{format}"]
257
379
  [
@@ -259,7 +381,7 @@ TEXT
259
381
  ["--verbose"],
260
382
  ["--compact"]
261
383
  ].each do |options|
262
- hash[(argv + options).join(" ")] = argv + options + [type, "fake"]
384
+ hash["[#{type}] " + (argv + options).join(" ")] = argv + options + [type, "fake"]
263
385
  end
264
386
  end
265
387
  end
@@ -1453,7 +1453,7 @@ module Fluent::Config
1453
1453
  @example = ConfigurableSpec::ExampleWithSkipAccessor.new
1454
1454
  @example.configure(config_element('ROOT'))
1455
1455
  assert_equal 'example7', @example.instance_variable_get(:@name)
1456
- assert_raise NoMethodError.new("undefined method `name' for #{@example}") do
1456
+ assert_raise NoMethodError do
1457
1457
  @example.name
1458
1458
  end
1459
1459
  end
@@ -1,5 +1,6 @@
1
1
  require_relative '../../helper'
2
2
  require 'fluent/plugin/in_tail/position_file'
3
+ require 'fluent/plugin/in_tail'
3
4
 
4
5
  require 'fileutils'
5
6
  require 'tempfile'
@@ -27,9 +28,15 @@ class IntailPositionFileTest < Test::Unit::TestCase
27
28
  f.seek(0)
28
29
  end
29
30
 
31
+ def follow_inodes_block
32
+ [true, false].each do |follow_inodes|
33
+ yield follow_inodes
34
+ end
35
+ end
36
+
30
37
  test '.load' do
31
38
  write_data(@file, TEST_CONTENT)
32
- Fluent::Plugin::TailInput::PositionFile.load(@file, logger: $log)
39
+ Fluent::Plugin::TailInput::PositionFile.load(@file, false, {}, **{logger: $log})
33
40
 
34
41
  @file.seek(0)
35
42
  lines = @file.readlines
@@ -41,7 +48,7 @@ class IntailPositionFileTest < Test::Unit::TestCase
41
48
  sub_test_case '#try_compact' do
42
49
  test 'compact invalid and convert 32 bit inode value' do
43
50
  write_data(@file, TEST_CONTENT)
44
- Fluent::Plugin::TailInput::PositionFile.new(@file, logger: $log).try_compact
51
+ Fluent::Plugin::TailInput::PositionFile.new(@file, false, {}, **{logger: $log}).try_compact
45
52
 
46
53
  @file.seek(0)
47
54
  lines = @file.readlines
@@ -55,7 +62,7 @@ class IntailPositionFileTest < Test::Unit::TestCase
55
62
  valid_path\t0000000000000002\t0000000000000001
56
63
  valid_path\t0000000000000003\t0000000000000004
57
64
  EOF
58
- Fluent::Plugin::TailInput::PositionFile.new(@file, logger: $log).try_compact
65
+ Fluent::Plugin::TailInput::PositionFile.new(@file, false, {}, **{logger: $log}).try_compact
59
66
 
60
67
  @file.seek(0)
61
68
  lines = @file.readlines
@@ -64,7 +71,7 @@ class IntailPositionFileTest < Test::Unit::TestCase
64
71
 
65
72
  test 'does not change when the file is changed' do
66
73
  write_data(@file, TEST_CONTENT)
67
- pf = Fluent::Plugin::TailInput::PositionFile.new(@file, logger: $log)
74
+ pf = Fluent::Plugin::TailInput::PositionFile.new(@file, false, {}, **{logger: $log})
68
75
 
69
76
  mock.proxy(pf).fetch_compacted_entries do |r|
70
77
  @file.write("unwatched\t#{UNWATCHED_STR}\t0000000000000000\n")
@@ -78,12 +85,17 @@ class IntailPositionFileTest < Test::Unit::TestCase
78
85
  assert_equal 5, lines.size
79
86
  end
80
87
 
81
- test 'update seek postion of remained position entry' do
82
- pf = Fluent::Plugin::TailInput::PositionFile.new(@file, logger: $log)
83
- pf['path1']
84
- pf['path2']
85
- pf['path3']
86
- pf.unwatch('path1')
88
+ test 'update seek position of remained position entry' do
89
+ pf = Fluent::Plugin::TailInput::PositionFile.new(@file, false, {}, **{logger: $log})
90
+ target_info1 = Fluent::Plugin::TailInput::TargetInfo.new('path1', -1)
91
+ target_info2 = Fluent::Plugin::TailInput::TargetInfo.new('path2', -1)
92
+ target_info3 = Fluent::Plugin::TailInput::TargetInfo.new('path3', -1)
93
+ pf[target_info1]
94
+ pf[target_info2]
95
+ pf[target_info3]
96
+
97
+ target_info1_2 = Fluent::Plugin::TailInput::TargetInfo.new('path1', 1234)
98
+ pf.unwatch(target_info1_2)
87
99
 
88
100
  pf.try_compact
89
101
 
@@ -93,8 +105,10 @@ class IntailPositionFileTest < Test::Unit::TestCase
93
105
  assert_equal "path3\t0000000000000000\t0000000000000000\n", lines[1]
94
106
  assert_equal 2, lines.size
95
107
 
96
- pf.unwatch('path2')
97
- pf.unwatch('path3')
108
+ target_info2_2 = Fluent::Plugin::TailInput::TargetInfo.new('path2', 1235)
109
+ target_info3_2 = Fluent::Plugin::TailInput::TargetInfo.new('path3', 1236)
110
+ pf.unwatch(target_info2_2)
111
+ pf.unwatch(target_info3_2)
98
112
  @file.seek(0)
99
113
  lines = @file.readlines
100
114
  assert_equal "path2\t#{UNWATCHED_STR}\t0000000000000000\n", lines[0]
@@ -106,7 +120,7 @@ class IntailPositionFileTest < Test::Unit::TestCase
106
120
  sub_test_case '#load' do
107
121
  test 'compact invalid and convert 32 bit inode value' do
108
122
  write_data(@file, TEST_CONTENT)
109
- Fluent::Plugin::TailInput::PositionFile.load(@file, logger: $log)
123
+ Fluent::Plugin::TailInput::PositionFile.load(@file, false, {}, **{logger: $log})
110
124
 
111
125
  @file.seek(0)
112
126
  lines = @file.readlines
@@ -120,7 +134,7 @@ class IntailPositionFileTest < Test::Unit::TestCase
120
134
  valid_path\t0000000000000002\t0000000000000001
121
135
  valid_path\t0000000000000003\t0000000000000004
122
136
  EOF
123
- Fluent::Plugin::TailInput::PositionFile.new(@file, logger: $log).load
137
+ Fluent::Plugin::TailInput::PositionFile.new(@file, false, {}, **{logger: $log}).load
124
138
 
125
139
  @file.seek(0)
126
140
  lines = @file.readlines
@@ -131,9 +145,10 @@ class IntailPositionFileTest < Test::Unit::TestCase
131
145
  sub_test_case '#[]' do
132
146
  test 'return entry' do
133
147
  write_data(@file, TEST_CONTENT)
134
- pf = Fluent::Plugin::TailInput::PositionFile.load(@file, logger: $log)
148
+ pf = Fluent::Plugin::TailInput::PositionFile.load(@file, false, {}, **{logger: $log})
135
149
 
136
- f = pf['valid_path']
150
+ valid_target_info = Fluent::Plugin::TailInput::TargetInfo.new('valid_path', File.stat(@file).ino)
151
+ f = pf[valid_target_info]
137
152
  assert_equal Fluent::Plugin::TailInput::FilePositionEntry, f.class
138
153
  assert_equal 2, f.read_pos
139
154
  assert_equal 1, f.read_inode
@@ -142,7 +157,8 @@ class IntailPositionFileTest < Test::Unit::TestCase
142
157
  lines = @file.readlines
143
158
  assert_equal 2, lines.size
144
159
 
145
- f = pf['nonexist_path']
160
+ nonexistent_target_info = Fluent::Plugin::TailInput::TargetInfo.new('nonexist_path', -1)
161
+ f = pf[nonexistent_target_info]
146
162
  assert_equal Fluent::Plugin::TailInput::FilePositionEntry, f.class
147
163
  assert_equal 0, f.read_pos
148
164
  assert_equal 0, f.read_inode
@@ -155,19 +171,19 @@ class IntailPositionFileTest < Test::Unit::TestCase
155
171
 
156
172
  test 'does not change other value position if other entry try to write' do
157
173
  write_data(@file, TEST_CONTENT)
158
- pf = Fluent::Plugin::TailInput::PositionFile.load(@file, logger: $log)
174
+ pf = Fluent::Plugin::TailInput::PositionFile.load(@file, false, {}, logger: $log)
159
175
 
160
- f = pf['nonexist_path']
176
+ f = pf[Fluent::Plugin::TailInput::TargetInfo.new('nonexist_path', -1)]
161
177
  assert_equal 0, f.read_inode
162
178
  assert_equal 0, f.read_pos
163
179
 
164
- pf['valid_path'].update(1, 2)
180
+ pf[Fluent::Plugin::TailInput::TargetInfo.new('valid_path', File.stat(@file).ino)].update(1, 2)
165
181
 
166
- f = pf['nonexist_path']
182
+ f = pf[Fluent::Plugin::TailInput::TargetInfo.new('nonexist_path', -1)]
167
183
  assert_equal 0, f.read_inode
168
184
  assert_equal 0, f.read_pos
169
185
 
170
- pf['nonexist_path'].update(1, 2)
186
+ pf[Fluent::Plugin::TailInput::TargetInfo.new('nonexist_path', -1)].update(1, 2)
171
187
  assert_equal 1, f.read_inode
172
188
  assert_equal 2, f.read_pos
173
189
  end
@@ -176,14 +192,18 @@ class IntailPositionFileTest < Test::Unit::TestCase
176
192
  sub_test_case '#unwatch' do
177
193
  test 'deletes entry by path' do
178
194
  write_data(@file, TEST_CONTENT)
179
- pf = Fluent::Plugin::TailInput::PositionFile.load(@file, logger: $log)
180
- p1 = pf['valid_path']
195
+ pf = Fluent::Plugin::TailInput::PositionFile.load(@file, false, {}, logger: $log)
196
+ inode1 = File.stat(@file).ino
197
+ target_info1 = Fluent::Plugin::TailInput::TargetInfo.new('valid_path', inode1)
198
+ p1 = pf[target_info1]
181
199
  assert_equal Fluent::Plugin::TailInput::FilePositionEntry, p1.class
182
200
 
183
- pf.unwatch('valid_path')
201
+ pf.unwatch(target_info1)
184
202
  assert_equal p1.read_pos, Fluent::Plugin::TailInput::PositionFile::UNWATCHED_POSITION
185
203
 
186
- p2 = pf['valid_path']
204
+ inode2 = File.stat(@file).ino
205
+ target_info2 = Fluent::Plugin::TailInput::TargetInfo.new('valid_path', inode2)
206
+ p2 = pf[target_info2]
187
207
  assert_equal Fluent::Plugin::TailInput::FilePositionEntry, p2.class
188
208
 
189
209
  assert_not_equal p1, p2
@@ -0,0 +1,105 @@
1
+ require_relative '../helper'
2
+ require 'fluent/plugin/file_wrapper'
3
+
4
+ class FileWrapperTest < Test::Unit::TestCase
5
+ require 'windows/file'
6
+ require 'windows/error'
7
+ include Windows::File
8
+ include Windows::Error
9
+
10
+ TMP_DIR = File.dirname(__FILE__) + "/../tmp/file_wrapper#{ENV['TEST_ENV_NUMBER']}"
11
+
12
+ def setup
13
+ FileUtils.mkdir_p(TMP_DIR)
14
+ end
15
+
16
+ def teardown
17
+ FileUtils.rm_rf(TMP_DIR)
18
+ end
19
+
20
+ sub_test_case 'Win32Error' do
21
+ test 'equal' do
22
+ assert_equal(Fluent::Win32Error.new(ERROR_SHARING_VIOLATION, "message"),
23
+ Fluent::Win32Error.new(ERROR_SHARING_VIOLATION, "message"))
24
+ end
25
+
26
+ test 'different error code' do
27
+ assert_not_equal(Fluent::Win32Error.new(ERROR_FILE_NOT_FOUND),
28
+ Fluent::Win32Error.new(ERROR_SHARING_VIOLATION))
29
+ end
30
+
31
+ test 'different error message' do
32
+ assert_not_equal(Fluent::Win32Error.new(ERROR_FILE_NOT_FOUND, "message1"),
33
+ Fluent::Win32Error.new(ERROR_FILE_NOT_FOUND, "message2"))
34
+ end
35
+
36
+ test 'different class' do
37
+ assert_not_equal(Errno::EPIPE,
38
+ Fluent::Win32Error.new(ERROR_SHARING_VIOLATION))
39
+ end
40
+
41
+ test 'ERROR_SHARING_VIOLATION message' do
42
+ assert_equal(Fluent::Win32Error.new(ERROR_SHARING_VIOLATION).message,
43
+ "Fluent::Win32Error: code: 32, The process cannot access the file because it is being used by another process.")
44
+ end
45
+
46
+ test 'ERROR_SHARING_VIOLATION with a message' do
47
+ assert_equal(Fluent::Win32Error.new(ERROR_SHARING_VIOLATION, "cannot open the file").message,
48
+ "Fluent::Win32Error: code: 32, The process cannot access the file because it is being used by another process." +
49
+ " - cannot open the file")
50
+ end
51
+
52
+ test 'to_s' do
53
+ assert_equal("Fluent::Win32Error: code: 32, The process cannot access the file because it is being used by another process. - C:\file.txt",
54
+ Fluent::Win32Error.new(ERROR_SHARING_VIOLATION, "C:\file.txt").to_s)
55
+ end
56
+
57
+ test 'inspect' do
58
+ assert_equal("#<Fluent::Win32Error: code: 32, The process cannot access the file because it is being used by another process. - C:\file.txt>",
59
+ Fluent::Win32Error.new(ERROR_SHARING_VIOLATION, "C:\file.txt").inspect)
60
+ end
61
+ end
62
+
63
+ sub_test_case 'WindowsFile exceptions' do
64
+ test 'nothing raised' do
65
+ begin
66
+ path = "#{TMP_DIR}/test_windows_file.txt"
67
+ file1 = file2 = nil
68
+ file1 = File.open(path, "wb") do |f|
69
+ end
70
+ assert_nothing_raised do
71
+ file2 = Fluent::WindowsFile.new(path)
72
+ ensure
73
+ file2.close
74
+ end
75
+ ensure
76
+ file1.close if file1
77
+ end
78
+ end
79
+
80
+ test 'Errno::ENOENT raised' do
81
+ path = "#{TMP_DIR}/nofile.txt"
82
+ file = nil
83
+ assert_raise(Errno::ENOENT) do
84
+ file = Fluent::WindowsFile.new(path)
85
+ ensure
86
+ file.close if file
87
+ end
88
+ end
89
+
90
+ test 'ERROR_SHARING_VIOLATION raised' do
91
+ begin
92
+ path = "#{TMP_DIR}/test_windows_file.txt"
93
+ file1 = file2 = nil
94
+ file1 = File.open(path, "wb")
95
+ assert_raise(Fluent::Win32Error.new(ERROR_SHARING_VIOLATION, path)) do
96
+ file2 = Fluent::WindowsFile.new(path, 'r', FILE_SHARE_READ)
97
+ ensure
98
+ file2.close if file2
99
+ end
100
+ ensure
101
+ file1.close if file1
102
+ end
103
+ end
104
+ end
105
+ end if Fluent.windows?