58 lines
1.7 KiB
Ruby
58 lines
1.7 KiB
Ruby
# frozen_string_literal: true
|
|||
|
|
|
||
|
|
require "test_helper"
|
||
|
|
require "tmpdir"
|
||
|
|
|
||
|
|
class ConfigTest < Minitest::Test
|
||
|
|
MISSING = "/nonexistent/volumen.toml"
|
||
|
|
|
||
|
|
def test_defaults_when_file_missing
|
||
|
|
config = Volumen::Config.load(path: MISSING)
|
||
|
|
assert_equal 9090, config.port
|
||
|
|
assert_equal "en", config.language
|
||
|
|
end
|
||
|
|
|
||
|
|
def test_overrides_apply
|
||
|
|
config = Volumen::Config.load(
|
||
|
|
path: MISSING,
|
||
|
|
overrides: { host: "127.0.0.1", port: 9000, content: "/srv/posts" }
|
||
|
|
)
|
||
|
|
assert_equal "127.0.0.1", config.host
|
||
|
|
assert_equal 9000, config.port
|
||
|
|
assert_equal "/srv/posts", config.content_dir
|
||
|
|
end
|
||
|
|
|
||
|
|
def test_does_not_mutate_defaults
|
||
|
|
Volumen::Config.load(path: MISSING, overrides: { host: "10.0.0.1" })
|
||
|
|
assert_equal "0.0.0.0", Volumen::Config.load(path: MISSING).host
|
||
|
|
end
|
||
|
|
|
||
|
|
def test_loads_and_merges_file
|
||
|
|
Dir.mktmpdir do |dir|
|
||
|
|
path = File.join(dir, "config.toml")
|
||
|
|
File.write(path, "[site]\ntitle = \"Custom\"\n")
|
||
|
|
config = Volumen::Config.load(path: path)
|
||
|
|
assert_equal "Custom", config.site["title"]
|
||
|
|
assert_equal 9090, config.port
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
def test_generate_default_writes_template
|
||
|
|
Dir.mktmpdir do |dir|
|
||
|
|
path = File.join(dir, "sub", "config.toml")
|
||
|
|
assert_equal path, Volumen::Config.generate_default(path)
|
||
|
|
assert_path_exists path
|
||
|
|
assert_equal 9090, Volumen::Config.load(path: path).port
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
def test_generate_default_skips_existing
|
||
|
|
Dir.mktmpdir do |dir|
|
||
|
|
path = File.join(dir, "config.toml")
|
||
|
|
File.write(path, "[server]\nport = 9999\n")
|
||
|
|
assert_nil Volumen::Config.generate_default(path)
|
||
|
|
assert_equal 9999, Volumen::Config.load(path: path).port
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|