Adding tests around merge_configs

This commit is contained in:
Andy Marks 2014-12-03 11:53:58 +11:00
parent b953d36537
commit f1a40e2e35
2 changed files with 45 additions and 1 deletions

View file

@ -1,3 +1,5 @@
require 'pp'
module Riemann::Dash::BrowserConfig
def self.backend
@ -63,6 +65,9 @@ module Riemann::Dash::BrowserConfig
def self.merge_workspaces(as, bs)
return as unless bs
return bs unless as
pp as
pp bs
merge_lists(lambda { |x| x['name'] },
method(:merge_workspace),
as,

View file

@ -26,4 +26,43 @@ describe "Riemann::Dash::BrowserConfig" do
@mock_backend.verify
end
end
describe :merge_configs do
before do
@first_config = {'server' => 'first_server', 'server_type' => 'first_type'}
@second_config = {'server' => 'second_server', 'server_type' => 'second_type'}
end
describe "when merging the server value" do
it "prioritises the value from the first config" do
merged_configs = Riemann::Dash::BrowserConfig.merge_configs(@first_config, @second_config)
assert_equal 'first_server', merged_configs['server']
end
it "uses the value from the second config if no other exists" do
@first_config = {}
merged_configs = Riemann::Dash::BrowserConfig.merge_configs(@first_config, @second_config)
assert_equal 'second_server', merged_configs['server']
end
end
describe "when merging the server_type value" do
it "prioritises the value from the first config" do
merged_configs = Riemann::Dash::BrowserConfig.merge_configs(@first_config, @second_config)
assert_equal 'first_type', merged_configs['server_type']
end
it "uses the value from the second config if no other exists" do
@first_config = {}
merged_configs = Riemann::Dash::BrowserConfig.merge_configs(@first_config, @second_config)
assert_equal 'second_type', merged_configs['server_type']
end
end
end
end