fluentd 0.10.53 → 0.10.54
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.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/ChangeLog +10 -0
- data/Rakefile +3 -12
- data/example/v1_literal_example.conf +36 -0
- data/fluentd.gemspec +1 -1
- data/lib/fluent/command/fluentd.rb +4 -0
- data/lib/fluent/config/basic_parser.rb +5 -0
- data/lib/fluent/config/element.rb +2 -5
- data/lib/fluent/config/literal_parser.rb +26 -7
- data/lib/fluent/config/v1_parser.rb +1 -1
- data/lib/fluent/parser.rb +14 -3
- data/lib/fluent/plugin/in_http.rb +9 -1
- data/lib/fluent/plugin/in_stream.rb +10 -1
- data/lib/fluent/plugin/in_syslog.rb +10 -1
- data/lib/fluent/plugin/socket_util.rb +9 -1
- data/lib/fluent/version.rb +1 -1
- data/test/config/assertions.rb +42 -0
- data/test/config/test_config_parser.rb +354 -0
- data/test/config/test_configurable.rb +530 -0
- data/test/config/test_configure_proxy.rb +99 -0
- data/test/config/test_dsl.rb +237 -0
- data/test/config/test_literal_parser.rb +293 -0
- data/test/config/test_section.rb +102 -0
- data/test/config/test_system_config.rb +49 -0
- data/test/helper.rb +25 -0
- data/test/plugin/test_in_http.rb +1 -1
- data/test/test_parser.rb +7 -1
- metadata +33 -33
- data/lib/fluent/plugin/buf_zfile.rb +0 -84
- data/spec/config/config_parser_spec.rb +0 -314
- data/spec/config/configurable_spec.rb +0 -524
- data/spec/config/configure_proxy_spec.rb +0 -96
- data/spec/config/dsl_spec.rb +0 -239
- data/spec/config/helper.rb +0 -49
- data/spec/config/literal_parser_spec.rb +0 -222
- data/spec/config/section_spec.rb +0 -97
- data/spec/config/system_config_spec.rb +0 -49
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'fluent/config/section'
|
3
|
+
|
4
|
+
module Fluent::Config
|
5
|
+
class TestSection < ::Test::Unit::TestCase
|
6
|
+
sub_test_case Fluent::Config::Section do
|
7
|
+
sub_test_case 'class' do
|
8
|
+
sub_test_case '.name' do
|
9
|
+
test 'returns its full module name as String' do
|
10
|
+
assert_equal('Fluent::Config::Section', Fluent::Config::Section.name)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
sub_test_case 'instance object' do
|
16
|
+
sub_test_case '#initialize' do
|
17
|
+
test 'creates blank object without argument' do
|
18
|
+
s = Fluent::Config::Section.new
|
19
|
+
assert_equal({}, s.instance_eval{ @params })
|
20
|
+
end
|
21
|
+
|
22
|
+
test 'creates object which contains specified hash object itself' do
|
23
|
+
hash = {
|
24
|
+
name: 'tagomoris',
|
25
|
+
age: 34,
|
26
|
+
send: 'email',
|
27
|
+
class: 'normal',
|
28
|
+
keys: 5,
|
29
|
+
}
|
30
|
+
s1 = Fluent::Config::Section.new(hash)
|
31
|
+
assert_equal(hash, s1.instance_eval { @params })
|
32
|
+
assert_equal("tagomoris", s1[:name])
|
33
|
+
assert_equal(34, s1[:age])
|
34
|
+
assert_equal("email", s1[:send])
|
35
|
+
assert_equal("normal", s1[:class])
|
36
|
+
assert_equal(5, s1[:keys])
|
37
|
+
|
38
|
+
assert_equal("tagomoris", s1.name)
|
39
|
+
assert_equal(34, s1.age)
|
40
|
+
assert_equal("email", s1.send)
|
41
|
+
assert_equal("normal", s1.class)
|
42
|
+
assert_equal(5, s1.keys)
|
43
|
+
|
44
|
+
assert_raise(NoMethodError) { s1.dup }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
sub_test_case '#to_h' do
|
49
|
+
test 'returns internal hash itself' do
|
50
|
+
hash = {
|
51
|
+
name: 'tagomoris',
|
52
|
+
age: 34,
|
53
|
+
send: 'email',
|
54
|
+
class: 'normal',
|
55
|
+
keys: 5,
|
56
|
+
}
|
57
|
+
s = Fluent::Config::Section.new(hash)
|
58
|
+
assert_equal(hash, s.to_h)
|
59
|
+
assert_instance_of(Hash, s.to_h)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
sub_test_case '#instance_of?' do
|
64
|
+
test 'can judge whether it is a Section object or not' do
|
65
|
+
s = Fluent::Config::Section.new
|
66
|
+
assert_true(s.instance_of?(Fluent::Config::Section))
|
67
|
+
assert_false(s.instance_of?(BasicObject))
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
sub_test_case '#is_a?' do
|
72
|
+
test 'can judge whether it belongs to or not' do
|
73
|
+
s = Fluent::Config::Section.new
|
74
|
+
assert_true(s.is_a?(Fluent::Config::Section))
|
75
|
+
assert_true(s.kind_of?(Fluent::Config::Section))
|
76
|
+
assert_true(s.is_a?(BasicObject))
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
sub_test_case '#+' do
|
81
|
+
test 'can merge 2 sections: argument side is primary, internal hash is newly created' do
|
82
|
+
h1 = {name: "s1", num: 10, class: "A"}
|
83
|
+
s1 = Fluent::Config::Section.new(h1)
|
84
|
+
|
85
|
+
h2 = {name: "s2", class: "A", num2: "5", num3: "8"}
|
86
|
+
s2 = Fluent::Config::Section.new(h2)
|
87
|
+
s = s1 + s2
|
88
|
+
|
89
|
+
assert_not_equal(h1.object_id, s.to_h.object_id)
|
90
|
+
assert_not_equal(h2.object_id, s.to_h.object_id)
|
91
|
+
|
92
|
+
assert_equal("s2", s.name)
|
93
|
+
assert_equal(10, s.num)
|
94
|
+
assert_equal("A", s.class)
|
95
|
+
assert_equal("5", s.num2)
|
96
|
+
assert_equal("8", s.num3)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'fluent/configurable'
|
3
|
+
require 'fluent/config/element'
|
4
|
+
require 'fluent/config/section'
|
5
|
+
require 'fluent/supervisor'
|
6
|
+
|
7
|
+
module Fluent::Config
|
8
|
+
class TestSystemConfig < ::Test::Unit::TestCase
|
9
|
+
def parse_text(text)
|
10
|
+
basepath = File.expand_path(File.dirname(__FILE__) + '/../../')
|
11
|
+
Fluent::Config.parse(text, '(test)', basepath, true).elements.find { |e| e.name == 'system' }
|
12
|
+
end
|
13
|
+
|
14
|
+
test 'should not override default configurations when no parameters' do
|
15
|
+
conf = parse_text(<<EOS)
|
16
|
+
<system>
|
17
|
+
</system>
|
18
|
+
EOS
|
19
|
+
sc = Fluent::Supervisor::SystemConfig.new(conf)
|
20
|
+
assert_nil(sc.log_level)
|
21
|
+
assert_nil(sc.suppress_repeated_stacktrace)
|
22
|
+
assert_nil(sc.emit_error_log_interval)
|
23
|
+
assert_nil(sc.suppress_config_dump)
|
24
|
+
assert_nil(sc.without_source)
|
25
|
+
assert_empty(sc.to_opt)
|
26
|
+
end
|
27
|
+
|
28
|
+
{'log_level' => 'error', 'suppress_repeated_stacktrace' => true, 'emit_error_log_interval' => 60, 'suppress_config_dump' => true, 'without_source' => true}.each { |k, v|
|
29
|
+
test "accepts #{k} parameter" do
|
30
|
+
conf = parse_text(<<EOS)
|
31
|
+
<system>
|
32
|
+
#{k} #{v}
|
33
|
+
</system>
|
34
|
+
EOS
|
35
|
+
sc = Fluent::Supervisor::SystemConfig.new(conf)
|
36
|
+
assert_not_nil(sc.instance_variable_get("@#{k}"))
|
37
|
+
key = (k == 'emit_error_log_interval' ? :suppress_interval : k.to_sym)
|
38
|
+
assert_include(sc.to_opt, key)
|
39
|
+
end
|
40
|
+
}
|
41
|
+
|
42
|
+
{'foo' => 'bar', 'hoge' => 'fuga'}.each { |k, v|
|
43
|
+
test "should not affect settable parameters with unknown #{k} parameter" do
|
44
|
+
sc = Fluent::Supervisor::SystemConfig.new({k => v})
|
45
|
+
assert_empty(sc.to_opt)
|
46
|
+
end
|
47
|
+
}
|
48
|
+
end
|
49
|
+
end
|
data/test/helper.rb
CHANGED
@@ -1,3 +1,28 @@
|
|
1
|
+
# simplecov must be loaded before any of target code
|
2
|
+
if ENV['SIMPLE_COV']
|
3
|
+
require 'simplecov'
|
4
|
+
if defined?(SimpleCov::SourceFile)
|
5
|
+
mod = SimpleCov::SourceFile
|
6
|
+
def mod.new(*args, &block)
|
7
|
+
m = allocate
|
8
|
+
m.instance_eval do
|
9
|
+
begin
|
10
|
+
initialize(*args, &block)
|
11
|
+
rescue Encoding::UndefinedConversionError
|
12
|
+
@src = "".force_encoding('UTF-8')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
m
|
16
|
+
end
|
17
|
+
end
|
18
|
+
unless SimpleCov.running
|
19
|
+
SimpleCov.start do
|
20
|
+
add_filter '/test/'
|
21
|
+
add_filter '/gems/'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
1
26
|
require 'test/unit'
|
2
27
|
require 'fileutils'
|
3
28
|
require 'fluent/log'
|
data/test/plugin/test_in_http.rb
CHANGED
data/test/test_parser.rb
CHANGED
@@ -34,7 +34,7 @@ module ParserTest
|
|
34
34
|
parser = TextParser::TimeParser.new(nil)
|
35
35
|
|
36
36
|
[[], {}, nil, true, 10000].each { |v|
|
37
|
-
assert_raise
|
37
|
+
assert_raise Fluent::TextParser::ParserError do
|
38
38
|
parser.parse(v)
|
39
39
|
end
|
40
40
|
}
|
@@ -288,6 +288,12 @@ module ParserTest
|
|
288
288
|
assert_nil time, "parser return nil w/o time and if specified so"
|
289
289
|
}
|
290
290
|
end
|
291
|
+
|
292
|
+
def test_call_with_invalid_time
|
293
|
+
assert_raise Fluent::TextParser::ParserError do
|
294
|
+
@parser.call('{"time":[],"k":"v"}') { |time, record| }
|
295
|
+
end
|
296
|
+
end
|
291
297
|
end
|
292
298
|
|
293
299
|
class NginxParserTest < ::Test::Unit::TestCase
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluentd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.10.
|
4
|
+
version: 0.10.54
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sadayuki Furuhashi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: msgpack
|
@@ -184,20 +184,6 @@ dependencies:
|
|
184
184
|
- - ">="
|
185
185
|
- !ruby/object:Gem::Version
|
186
186
|
version: 0.15.3
|
187
|
-
- !ruby/object:Gem::Dependency
|
188
|
-
name: rspec
|
189
|
-
requirement: !ruby/object:Gem::Requirement
|
190
|
-
requirements:
|
191
|
-
- - "~>"
|
192
|
-
- !ruby/object:Gem::Version
|
193
|
-
version: 3.0.0
|
194
|
-
type: :development
|
195
|
-
prerelease: false
|
196
|
-
version_requirements: !ruby/object:Gem::Requirement
|
197
|
-
requirements:
|
198
|
-
- - "~>"
|
199
|
-
- !ruby/object:Gem::Version
|
200
|
-
version: 3.0.0
|
201
187
|
- !ruby/object:Gem::Dependency
|
202
188
|
name: simplecov
|
203
189
|
requirement: !ruby/object:Gem::Requirement
|
@@ -240,6 +226,20 @@ dependencies:
|
|
240
226
|
- - ">="
|
241
227
|
- !ruby/object:Gem::Version
|
242
228
|
version: 0.3.0
|
229
|
+
- !ruby/object:Gem::Dependency
|
230
|
+
name: test-unit
|
231
|
+
requirement: !ruby/object:Gem::Requirement
|
232
|
+
requirements:
|
233
|
+
- - "~>"
|
234
|
+
- !ruby/object:Gem::Version
|
235
|
+
version: 3.0.2
|
236
|
+
type: :development
|
237
|
+
prerelease: false
|
238
|
+
version_requirements: !ruby/object:Gem::Requirement
|
239
|
+
requirements:
|
240
|
+
- - "~>"
|
241
|
+
- !ruby/object:Gem::Version
|
242
|
+
version: 3.0.2
|
243
243
|
description: Fluentd is an open source data collector designed to scale and simplify
|
244
244
|
log management. It can collect, process and ship many kinds of data in near real-time.
|
245
245
|
email:
|
@@ -266,6 +266,7 @@ files:
|
|
266
266
|
- bin/fluent-debug
|
267
267
|
- bin/fluent-gem
|
268
268
|
- bin/fluentd
|
269
|
+
- example/v1_literal_example.conf
|
269
270
|
- fluent.conf
|
270
271
|
- fluentd.gemspec
|
271
272
|
- lib/fluent/buffer.rb
|
@@ -299,7 +300,6 @@ files:
|
|
299
300
|
- lib/fluent/plugin.rb
|
300
301
|
- lib/fluent/plugin/buf_file.rb
|
301
302
|
- lib/fluent/plugin/buf_memory.rb
|
302
|
-
- lib/fluent/plugin/buf_zfile.rb
|
303
303
|
- lib/fluent/plugin/exec_util.rb
|
304
304
|
- lib/fluent/plugin/in_debug_agent.rb
|
305
305
|
- lib/fluent/plugin/in_exec.rb
|
@@ -334,15 +334,15 @@ files:
|
|
334
334
|
- lib/fluent/test/input_test.rb
|
335
335
|
- lib/fluent/test/output_test.rb
|
336
336
|
- lib/fluent/version.rb
|
337
|
-
- spec/config/config_parser_spec.rb
|
338
|
-
- spec/config/configurable_spec.rb
|
339
|
-
- spec/config/configure_proxy_spec.rb
|
340
|
-
- spec/config/dsl_spec.rb
|
341
|
-
- spec/config/helper.rb
|
342
|
-
- spec/config/literal_parser_spec.rb
|
343
|
-
- spec/config/section_spec.rb
|
344
|
-
- spec/config/system_config_spec.rb
|
345
337
|
- spec/spec_helper.rb
|
338
|
+
- test/config/assertions.rb
|
339
|
+
- test/config/test_config_parser.rb
|
340
|
+
- test/config/test_configurable.rb
|
341
|
+
- test/config/test_configure_proxy.rb
|
342
|
+
- test/config/test_dsl.rb
|
343
|
+
- test/config/test_literal_parser.rb
|
344
|
+
- test/config/test_section.rb
|
345
|
+
- test/config/test_system_config.rb
|
346
346
|
- test/helper.rb
|
347
347
|
- test/plugin/data/2010/01/20100102-030405.log
|
348
348
|
- test/plugin/data/2010/01/20100102-030406.log
|
@@ -403,15 +403,15 @@ signing_key:
|
|
403
403
|
specification_version: 4
|
404
404
|
summary: Fluentd event collector
|
405
405
|
test_files:
|
406
|
-
- spec/config/config_parser_spec.rb
|
407
|
-
- spec/config/configurable_spec.rb
|
408
|
-
- spec/config/configure_proxy_spec.rb
|
409
|
-
- spec/config/dsl_spec.rb
|
410
|
-
- spec/config/helper.rb
|
411
|
-
- spec/config/literal_parser_spec.rb
|
412
|
-
- spec/config/section_spec.rb
|
413
|
-
- spec/config/system_config_spec.rb
|
414
406
|
- spec/spec_helper.rb
|
407
|
+
- test/config/assertions.rb
|
408
|
+
- test/config/test_config_parser.rb
|
409
|
+
- test/config/test_configurable.rb
|
410
|
+
- test/config/test_configure_proxy.rb
|
411
|
+
- test/config/test_dsl.rb
|
412
|
+
- test/config/test_literal_parser.rb
|
413
|
+
- test/config/test_section.rb
|
414
|
+
- test/config/test_system_config.rb
|
415
415
|
- test/helper.rb
|
416
416
|
- test/plugin/data/2010/01/20100102-030405.log
|
417
417
|
- test/plugin/data/2010/01/20100102-030406.log
|
@@ -1,84 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Fluent
|
3
|
-
#
|
4
|
-
# Copyright (C) 2011 FURUHASHI Sadayuki
|
5
|
-
#
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
-
# See the License for the specific language governing permissions and
|
16
|
-
# limitations under the License.
|
17
|
-
#
|
18
|
-
module Fluent
|
19
|
-
|
20
|
-
|
21
|
-
class ZFileBufferChunk < FileBufferChunk
|
22
|
-
def initialize(path)
|
23
|
-
super(path)
|
24
|
-
@z = Zlib::Deflate.new
|
25
|
-
end
|
26
|
-
|
27
|
-
def <<(data)
|
28
|
-
zdata = @z.deflate(data, Z_NO_FLUSH)
|
29
|
-
unless zdata.empty?
|
30
|
-
super(zdata)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def close_write
|
35
|
-
zdata = @z.flush
|
36
|
-
unless zdata.empty?
|
37
|
-
@file.write(zdata)
|
38
|
-
@size += zdata.bytesize
|
39
|
-
end
|
40
|
-
super
|
41
|
-
end
|
42
|
-
|
43
|
-
def close
|
44
|
-
@z.close
|
45
|
-
super
|
46
|
-
end
|
47
|
-
|
48
|
-
def purge
|
49
|
-
@z.close
|
50
|
-
super
|
51
|
-
end
|
52
|
-
|
53
|
-
# TODO
|
54
|
-
#def open(&block)
|
55
|
-
#end
|
56
|
-
end
|
57
|
-
|
58
|
-
|
59
|
-
class ZFileBuffer < FileBuffer
|
60
|
-
# TODO
|
61
|
-
#Plugin.register_buffer('zfile', self)
|
62
|
-
|
63
|
-
def initialize
|
64
|
-
require 'zlib'
|
65
|
-
super
|
66
|
-
end
|
67
|
-
|
68
|
-
def resume_queue
|
69
|
-
queue = resume_queue_paths.map {|path|
|
70
|
-
ZFileBufferChunk.new(path)
|
71
|
-
}
|
72
|
-
top = new_chunk
|
73
|
-
return queue, top
|
74
|
-
end
|
75
|
-
|
76
|
-
def new_chunk
|
77
|
-
path = new_chunk_path
|
78
|
-
ZFileBufferChunk.new(path)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
|
83
|
-
end
|
84
|
-
|
@@ -1,314 +0,0 @@
|
|
1
|
-
require "json"
|
2
|
-
require "config/helper"
|
3
|
-
require "fluent/config/error"
|
4
|
-
require "fluent/config/basic_parser"
|
5
|
-
require "fluent/config/literal_parser"
|
6
|
-
require "fluent/config/v1_parser"
|
7
|
-
|
8
|
-
describe Fluent::Config::V1Parser do
|
9
|
-
include_context 'config_helper'
|
10
|
-
|
11
|
-
def read_config(path)
|
12
|
-
path = File.expand_path(path)
|
13
|
-
data = File.read(path)
|
14
|
-
Fluent::Config::V1Parser.parse(data, File.basename(path), File.dirname(path))
|
15
|
-
end
|
16
|
-
|
17
|
-
def parse_text(text)
|
18
|
-
basepath = File.expand_path(File.dirname(__FILE__) + '/../../')
|
19
|
-
Fluent::Config::V1Parser.parse(text, '(test)', basepath, nil)
|
20
|
-
end
|
21
|
-
|
22
|
-
def root(*elements)
|
23
|
-
if elements.first.is_a?(Fluent::Config::Element)
|
24
|
-
attrs = {}
|
25
|
-
else
|
26
|
-
attrs = elements.shift || {}
|
27
|
-
end
|
28
|
-
Fluent::Config::Element.new('ROOT', '', attrs, elements)
|
29
|
-
end
|
30
|
-
|
31
|
-
def e(name, arg='', attrs={}, elements=[])
|
32
|
-
Fluent::Config::Element.new(name, arg, attrs, elements)
|
33
|
-
end
|
34
|
-
|
35
|
-
describe 'attribute parsing' do
|
36
|
-
it "parses attributes" do
|
37
|
-
expect(%[
|
38
|
-
k1 v1
|
39
|
-
k2 v2
|
40
|
-
]).to be_parsed_as(e('ROOT', '', {"k1"=>"v1", "k2"=>"v2"}))
|
41
|
-
end
|
42
|
-
|
43
|
-
it "allows attribute without value" do
|
44
|
-
expect(%[
|
45
|
-
k1
|
46
|
-
k2 v2
|
47
|
-
]).to be_parsed_as(e('ROOT', '', {"k1"=>"", "k2"=>"v2"}))
|
48
|
-
end
|
49
|
-
|
50
|
-
it "parses attribute key always string" do
|
51
|
-
expect("1 1").to be_parsed_as(e('ROOT', '', {"1" => "1"}))
|
52
|
-
end
|
53
|
-
|
54
|
-
[
|
55
|
-
"_.%$!,",
|
56
|
-
"/=~-~@\`:?",
|
57
|
-
"()*{}.[]",
|
58
|
-
].each do |v|
|
59
|
-
it "parses a value with symbol #{v.inspect}" do
|
60
|
-
expect("k #{v}").to be_parsed_as(e('ROOT', '', {"k" => v}))
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
it "ignores spacing around value" do
|
65
|
-
expect(" k1 a ").to be_parsed_as(e('ROOT', '', {"k1" => "a"}))
|
66
|
-
end
|
67
|
-
|
68
|
-
it "allows spaces in value" do
|
69
|
-
expect("k1 a b c").to be_parsed_as(e('ROOT', '', {"k1" => "a b c"}))
|
70
|
-
end
|
71
|
-
|
72
|
-
it "ignores comments after value" do
|
73
|
-
expect(" k1 a#comment").to be_parsed_as(e('ROOT', '', {"k1" => "a"}))
|
74
|
-
end
|
75
|
-
|
76
|
-
it "allows # in value if quoted" do
|
77
|
-
expect(' k1 "a#comment"').to be_parsed_as(e('ROOT', '', {"k1" => "a#comment"}))
|
78
|
-
end
|
79
|
-
|
80
|
-
it "rejects characters after quoted string" do
|
81
|
-
expect(' k1 "a" 1').to be_parse_error
|
82
|
-
end
|
83
|
-
|
84
|
-
it "rejects @ prefix in parameter name" do
|
85
|
-
expect(' @k v').to be_parse_error
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
describe 'element parsing' do
|
90
|
-
it do
|
91
|
-
expect("").to be_parsed_as(root)
|
92
|
-
end
|
93
|
-
|
94
|
-
it "accepts empty element" do
|
95
|
-
expect(%[
|
96
|
-
<test>
|
97
|
-
</test>
|
98
|
-
]).to be_parsed_as(
|
99
|
-
root(
|
100
|
-
e("test")
|
101
|
-
)
|
102
|
-
)
|
103
|
-
end
|
104
|
-
|
105
|
-
it "accepts argument and attributes" do
|
106
|
-
expect(%[
|
107
|
-
<test var>
|
108
|
-
key val
|
109
|
-
</test>
|
110
|
-
]).to be_parsed_as(root(
|
111
|
-
e("test", 'var', {'key'=>"val"})
|
112
|
-
))
|
113
|
-
end
|
114
|
-
|
115
|
-
it "accepts nested elements" do
|
116
|
-
expect(%[
|
117
|
-
<test var>
|
118
|
-
key 1
|
119
|
-
<nested1>
|
120
|
-
</nested1>
|
121
|
-
<nested2>
|
122
|
-
</nested2>
|
123
|
-
</test>
|
124
|
-
]).to be_parsed_as(root(
|
125
|
-
e("test", 'var', {'key'=>'1'}, [
|
126
|
-
e('nested1'),
|
127
|
-
e('nested2')
|
128
|
-
])
|
129
|
-
))
|
130
|
-
end
|
131
|
-
|
132
|
-
it "accepts multiline json values" do
|
133
|
-
expect(%[
|
134
|
-
<test var>
|
135
|
-
key ["a",
|
136
|
-
"b", "c",
|
137
|
-
"d"]
|
138
|
-
</test>
|
139
|
-
]).to be_parsed_as(root(
|
140
|
-
e("test", 'var', {'key'=>"[\"a\",\"b\",\"c\",\"d\"]"})
|
141
|
-
))
|
142
|
-
end
|
143
|
-
|
144
|
-
[
|
145
|
-
"**",
|
146
|
-
"*.*",
|
147
|
-
"1",
|
148
|
-
"_.%$!",
|
149
|
-
"/",
|
150
|
-
"()*{}.[]",
|
151
|
-
].each do |arg|
|
152
|
-
it "parses element argument #{arg.inspect}" do
|
153
|
-
expect(%[
|
154
|
-
<test #{arg}>
|
155
|
-
</test>
|
156
|
-
]).to be_parsed_as(root(
|
157
|
-
e("test", arg)
|
158
|
-
))
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
it "parses empty element argument to nil" do
|
163
|
-
expect(%[
|
164
|
-
<test >
|
165
|
-
</test>
|
166
|
-
]).to be_parsed_as(root(
|
167
|
-
e("test", '')
|
168
|
-
))
|
169
|
-
end
|
170
|
-
|
171
|
-
it "ignores spacing around element argument" do
|
172
|
-
expect(%[
|
173
|
-
<test a >
|
174
|
-
</test>
|
175
|
-
]).to be_parsed_as(root(
|
176
|
-
e("test", "a")
|
177
|
-
))
|
178
|
-
end
|
179
|
-
|
180
|
-
it "considers comments in element argument" do
|
181
|
-
expect(%[
|
182
|
-
<test #a>
|
183
|
-
</test>
|
184
|
-
]).to be_parse_error
|
185
|
-
end
|
186
|
-
|
187
|
-
it "requires line_end after begin tag" do
|
188
|
-
expect(%[
|
189
|
-
<test></test>
|
190
|
-
]).to be_parse_error
|
191
|
-
end
|
192
|
-
|
193
|
-
it "requires line_end after end tag" do
|
194
|
-
expect(%[
|
195
|
-
<test>
|
196
|
-
</test><test>
|
197
|
-
</test>
|
198
|
-
]).to be_parse_error
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
# port from test_config.rb
|
203
|
-
describe '@include parsing' do
|
204
|
-
TMP_DIR = File.dirname(__FILE__) + "/tmp/v1_config#{ENV['TEST_ENV_NUMBER']}"
|
205
|
-
|
206
|
-
def write_config(path, data)
|
207
|
-
FileUtils.mkdir_p(File.dirname(path))
|
208
|
-
File.open(path, "w") { |f| f.write data }
|
209
|
-
end
|
210
|
-
|
211
|
-
def prepare_config
|
212
|
-
write_config "#{TMP_DIR}/config_test_1.conf", %[
|
213
|
-
k1 root_config
|
214
|
-
include dir/config_test_2.conf #
|
215
|
-
@include #{TMP_DIR}/config_test_4.conf
|
216
|
-
include file://#{TMP_DIR}/config_test_5.conf
|
217
|
-
@include config.d/*.conf
|
218
|
-
]
|
219
|
-
write_config "#{TMP_DIR}/dir/config_test_2.conf", %[
|
220
|
-
k2 relative_path_include
|
221
|
-
@include ../config_test_3.conf
|
222
|
-
]
|
223
|
-
write_config "#{TMP_DIR}/config_test_3.conf", %[
|
224
|
-
k3 relative_include_in_included_file
|
225
|
-
]
|
226
|
-
write_config "#{TMP_DIR}/config_test_4.conf", %[
|
227
|
-
k4 absolute_path_include
|
228
|
-
]
|
229
|
-
write_config "#{TMP_DIR}/config_test_5.conf", %[
|
230
|
-
k5 uri_include
|
231
|
-
]
|
232
|
-
write_config "#{TMP_DIR}/config.d/config_test_6.conf", %[
|
233
|
-
k6 wildcard_include_1
|
234
|
-
<elem1 name>
|
235
|
-
include normal_parameter
|
236
|
-
</elem1>
|
237
|
-
]
|
238
|
-
write_config "#{TMP_DIR}/config.d/config_test_7.conf", %[
|
239
|
-
k7 wildcard_include_2
|
240
|
-
]
|
241
|
-
write_config "#{TMP_DIR}/config.d/config_test_8.conf", %[
|
242
|
-
<elem2 name>
|
243
|
-
@include ../dir/config_test_9.conf
|
244
|
-
</elem2>
|
245
|
-
]
|
246
|
-
write_config "#{TMP_DIR}/dir/config_test_9.conf", %[
|
247
|
-
k9 embeded
|
248
|
-
<elem3 name>
|
249
|
-
nested nested_value
|
250
|
-
include hoge
|
251
|
-
</elem3>
|
252
|
-
]
|
253
|
-
write_config "#{TMP_DIR}/config.d/00_config_test_8.conf", %[
|
254
|
-
k8 wildcard_include_3
|
255
|
-
<elem4 name>
|
256
|
-
include normal_parameter
|
257
|
-
</elem4>
|
258
|
-
]
|
259
|
-
end
|
260
|
-
|
261
|
-
it 'parses @include / include correctly' do
|
262
|
-
prepare_config
|
263
|
-
c = read_config("#{TMP_DIR}/config_test_1.conf")
|
264
|
-
expect(c['k1']).to eq('root_config')
|
265
|
-
expect(c['k2']).to eq('relative_path_include')
|
266
|
-
expect(c['k3']).to eq('relative_include_in_included_file')
|
267
|
-
expect(c['k4']).to eq('absolute_path_include')
|
268
|
-
expect(c['k5']).to eq('uri_include')
|
269
|
-
expect(c['k6']).to eq('wildcard_include_1')
|
270
|
-
expect(c['k7']).to eq('wildcard_include_2')
|
271
|
-
expect(c['k8']).to eq('wildcard_include_3')
|
272
|
-
expect(c.keys).to eq([
|
273
|
-
'k1',
|
274
|
-
'k2',
|
275
|
-
'k3',
|
276
|
-
'k4',
|
277
|
-
'k5',
|
278
|
-
'k8', # Because of the file name this comes first.
|
279
|
-
'k6',
|
280
|
-
'k7',
|
281
|
-
])
|
282
|
-
|
283
|
-
elem1 = c.elements.find { |e| e.name == 'elem1' }
|
284
|
-
expect(elem1).to be
|
285
|
-
expect(elem1.arg).to eq('name')
|
286
|
-
expect(elem1['include']).to eq('normal_parameter')
|
287
|
-
|
288
|
-
elem2 = c.elements.find { |e| e.name == 'elem2' }
|
289
|
-
expect(elem2).to be
|
290
|
-
expect(elem2.arg).to eq('name')
|
291
|
-
expect(elem2['k9']).to eq('embeded')
|
292
|
-
expect(elem2.has_key?('include')).to be(false)
|
293
|
-
|
294
|
-
elem3 = elem2.elements.find { |e| e.name == 'elem3' }
|
295
|
-
expect(elem3).to be
|
296
|
-
expect(elem3['nested']).to eq('nested_value')
|
297
|
-
expect(elem3['include']).to eq('hoge')
|
298
|
-
end
|
299
|
-
|
300
|
-
# TODO: Add uri based include spec
|
301
|
-
end
|
302
|
-
|
303
|
-
describe 'unescape parameter' do
|
304
|
-
it 'parses dumpped configuration' do
|
305
|
-
original = %q!a\\\\\n\r\f\b\\'\\"z!
|
306
|
-
expected = %!a\\\n\r\f\b'"z!
|
307
|
-
|
308
|
-
conf = parse_text(%[k1 #{original}])
|
309
|
-
expect(conf['k1']).to eq(expected) # escape check
|
310
|
-
conf2 = parse_text(conf.to_s) # use dumpped configuration to check unescape
|
311
|
-
expect(conf2.elements.first['k1']).to eq(expected)
|
312
|
-
end
|
313
|
-
end
|
314
|
-
end
|