more tests for config

This commit is contained in:
Roman Heinrich 2013-03-11 19:37:06 +02:00
parent 29869a4ef0
commit 9903cfdab6
3 changed files with 29 additions and 3 deletions

View file

@ -120,6 +120,7 @@ class Riemann::Dash::Config
def update_ws_config(update)
update = MultiJson.decode(update)
# Read old config
if File.exists? ws_config_file
old = MultiJson.decode File.read(ws_config_file)
@ -132,13 +133,13 @@ class Riemann::Dash::Config
# Server
new_config['server'] = update['server'] or old['server']
p update['workspaces']
#p update['workspaces']
new_config['workspaces'] = update['workspaces'] or old['workspaces']
# Save new config
FileUtils.mkdir_p 'config'
FileUtils.mkdir_p File.dirname(ws_config_file)
File.open(ws_config_file, 'w') do |f|
f.write(MultiJson.encode(new_config))
f.write(MultiJson.encode(new_config, :pretty => true))
end
end
end

View file

@ -19,6 +19,12 @@ describe "Riemann::Dash::Config" do
@config.load_config("test/fixtures/config/basic_config.rb")
Riemann::Dash::App.settings.settings_loaded.must_equal "yes"
end
it "will apply settings from file to self" do
@config.store[:views].wont_equal "/some/path/to/views"
@config.load_config("test/fixtures/config/basic_config.rb")
@config.store[:views].must_equal "/some/path/to/views"
end
end
describe :setup_default_values do
@ -57,6 +63,10 @@ describe "Riemann::Dash::Config" do
end
describe "workspace config" do
before do
FileUtils.rm_rf "test/tmp/"
end
describe :read_ws_config do
it "retuns hash for empty configs" do
@config.read_ws_config.must_equal "{}"
@ -70,7 +80,21 @@ describe "Riemann::Dash::Config" do
end
describe :update_ws_config do
it "works" do
@config.store[:ws_config] = "test/tmp/config.json"
@config.update_ws_config("{\"server\":\"10.10.10.10\",\"workspaces\":[]}")
end
it "pretty-prints the config" do
@config.store[:ws_config] = "test/tmp/config.json"
@config.update_ws_config("{\"server\":\"10.10.10.10\",\"workspaces\":[]}")
File.read("test/tmp/config.json").must_equal "{
\"server\": \"10.10.10.10\",
\"workspaces\": [
]
}"
end
end
end
end

View file

@ -1 +1,2 @@
set :settings_loaded, "yes"
config.store[:views] = "/some/path/to/views"