test/test_config.rb in fluentd-1.8.1 vs test/test_config.rb in fluentd-1.9.0.rc1
- old
+ new
@@ -149,20 +149,20 @@
before_size = match_conf.unused.size
10.times { match_conf['type'] }
assert_equal before_size, match_conf.unused.size
end
- def write_config(path, data)
+ def write_config(path, data, encoding: 'utf-8')
FileUtils.mkdir_p(File.dirname(path))
- File.open(path, "w") {|f| f.write data }
+ File.open(path, "w:#{encoding}:utf-8") {|f| f.write data }
end
def test_inline
prepare_config
opts = {
- :config_path => "#{TMP_DIR}/config_test_1.conf",
- :inline_config => "<source>\n type http\n port 2222\n </source>"
+ :config_path => "#{TMP_DIR}/config_test_1.conf",
+ :inline_config => "<source>\n type http\n port 2222\n </source>"
}
assert_nothing_raised do
Fluent::Supervisor.new(opts)
end
create_warn_dummy_logger
@@ -173,7 +173,29 @@
dl_opts[:log_level] = ServerEngine::DaemonLogger::WARN
logdev = Fluent::Test::DummyLogDevice.new
logger = ServerEngine::DaemonLogger.new(logdev, dl_opts)
$log = Fluent::Log.new(logger)
end
-end
+ sub_test_case '.build' do
+ test 'read config' do
+ write_config("#{TMP_DIR}/build/config_build.conf", 'key value')
+ c = Fluent::Config.build(config_path: "#{TMP_DIR}/build/config_build.conf")
+ assert_equal('value', c['key'])
+ end
+
+ test 'read config with encoding' do
+ write_config("#{TMP_DIR}/build/config_build2.conf", "#てすと\nkey value", encoding: 'shift_jis')
+
+ c = Fluent::Config.build(config_path: "#{TMP_DIR}/build/config_build2.conf", encoding: 'shift_jis')
+ assert_equal('value', c['key'])
+ end
+
+ test 'read config with additional_config' do
+ write_config("#{TMP_DIR}/build/config_build2.conf", "key value")
+
+ c = Fluent::Config.build(config_path: "#{TMP_DIR}/build/config_build2.conf", additional_config: 'key2 value2')
+ assert_equal('value', c['key'])
+ assert_equal('value2', c['key2'])
+ end
+ end
+end