diff options
Diffstat (limited to 'test/test_config.rb')
-rw-r--r-- | test/test_config.rb | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/test/test_config.rb b/test/test_config.rb new file mode 100644 index 0000000..2afcecb --- /dev/null +++ b/test/test_config.rb @@ -0,0 +1,56 @@ +# Copyright (C) 2013, Eric Wong <normalperson@yhbt.net> and all contributors +# License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt) +require_relative 'helper' +require 'rack/lobster' + +class TestConfig < Testcase + parallelize_me! + + def test_initialize + cfg = Yahns::Config.new + assert_instance_of Yahns::Config, cfg + end + + def test_multi_conf_example + tmpdir = Dir.mktmpdir + + # modify the example config file for testing + path = "examples/yahns_multi.conf.rb" + cfgs = File.read(path) + cfgs.gsub!(%r{/path/to/}, "#{tmpdir}/") + conf = File.open("#{tmpdir}/yahns_multi.conf.rb", "w") + conf.sync = true + conf.write(cfgs) + File.open("#{tmpdir}/another.ru", "w") do |fp| + fp.puts("run Rack::Lobster.new\n") + end + FileUtils.mkpath("#{tmpdir}/another") + + cfg = GTL.synchronize { Yahns::Config.new(conf.path) } + assert_instance_of Yahns::Config, cfg + ensure + FileUtils.rm_rf(tmpdir) if tmpdir + end + + def test_rack_basic_conf_example + tmpdir = Dir.mktmpdir + + # modify the example config file for testing + path = "examples/yahns_rack_basic.conf.rb" + cfgs = File.read(path) + cfgs.gsub!(%r{/path/to/}, "#{tmpdir}/") + Dir.mkdir("#{tmpdir}/my_app") + Dir.mkdir("#{tmpdir}/my_logs") + Dir.mkdir("#{tmpdir}/my_pids") + conf = File.open("#{tmpdir}/yahns_rack_basic.conf.rb", "w") + conf.sync = true + conf.write(cfgs) + File.open("#{tmpdir}/my_app/config.ru", "w") do |fp| + fp.puts("run Rack::Lobster.new\n") + end + cfg = GTL.synchronize { Yahns::Config.new(conf.path) } + assert_instance_of Yahns::Config, cfg + ensure + FileUtils.rm_rf(tmpdir) if tmpdir + end +end |