diff --git a/test/test_config.rb b/test/test_config.rb
index 2382f7d8bc..f6099ba426 100644
--- a/test/test_config.rb
+++ b/test/test_config.rb
@@ -151,16 +151,16 @@ def test_check_not_fetchd
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 => ""
+ :config_path => "#{TMP_DIR}/config_test_1.conf",
+ :inline_config => ""
}
assert_nothing_raised do
Fluent::Supervisor.new(opts)
@@ -175,5 +175,27 @@ def create_warn_dummy_logger
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
diff --git a/test/test_supervisor.rb b/test/test_supervisor.rb
index a8754b2f09..2eb431cb02 100644
--- a/test/test_supervisor.rb
+++ b/test/test_supervisor.rb
@@ -30,81 +30,6 @@ def write_config(path, data)
File.open(path, "w") {|f| f.write data }
end
- def test_read_config
- create_info_dummy_logger
-
- tmp_dir = "#{TMP_DIR}/dir/test_read_config.conf"
- conf_str = %[
-
-
- @type stdout
- @id stdout_output
-
-]
- write_config tmp_dir, conf_str
- opts = Fluent::Supervisor.default_options
- sv = Fluent::Supervisor.new(opts)
-
- use_v1_config = {}
- use_v1_config['use_v1_config'] = true
-
- sv.instance_variable_set(:@config_path, tmp_dir)
- sv.instance_variable_set(:@use_v1_config, use_v1_config)
-
- conf = sv.__send__(:read_config)
- elem = conf.elements.find { |e| e.name == 'source' }
- assert_equal "forward", elem['@type']
- assert_equal "forward_input", elem['@id']
-
- elem = conf.elements.find { |e| e.name == 'match' }
- assert_equal "debug.**", elem.arg
- assert_equal "stdout", elem['@type']
- assert_equal "stdout_output", elem['@id']
-
- $log.out.reset
- end
-
- def test_read_config_with_multibyte_string
- tmp_path = "#{TMP_DIR}/dir/test_multibyte_config.conf"
- conf_str = %[
-
-
-]
- FileUtils.mkdir_p(File.dirname(tmp_path))
- File.open(tmp_path, "w:utf-8") {|file| file.write(conf_str) }
-
- opts = Fluent::Supervisor.default_options
- sv = Fluent::Supervisor.new(opts)
-
- use_v1_config = {}
- use_v1_config['use_v1_config'] = true
-
- sv.instance_variable_set(:@config_path, tmp_path)
- sv.instance_variable_set(:@use_v1_config, use_v1_config)
-
- conf = sv.__send__(:read_config)
- label = conf.elements.detect {|e| e.name == "label" }
- filter = label.elements.detect {|e| e.name == "filter" }
- record_transformer = filter.elements.detect {|e| e.name = "record_transformer" }
- assert_equal(Encoding::UTF_8, record_transformer["message"].encoding)
- end
def test_system_config
opts = Fluent::Supervisor.default_options
@@ -416,7 +341,7 @@ def test_inline_config
inline_config = '\n@type stdout\n'
stub(STDIN).read { inline_config }
- stub(sv).read_config # to skip
+ stub(Fluent::Config).build # to skip
stub(sv).build_system_config { Fluent::SystemConfig.new } # to skip
sv.configure