diff --git a/lib/riemann/dash/browser_config.rb b/lib/riemann/dash/browser_config.rb index 23a3fe7..9958dcd 100644 --- a/lib/riemann/dash/browser_config.rb +++ b/lib/riemann/dash/browser_config.rb @@ -1,3 +1,5 @@ +require 'pp' + module Riemann::Dash::BrowserConfig def self.backend @@ -24,7 +26,7 @@ module Riemann::Dash::BrowserConfig end private - + # TODO: this is gonna take significant restructuring of the dashboard itself, # but we should move to http://arxiv.org/abs/1201.1784 or equivalent CRDTs. @@ -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, diff --git a/test/browser_config_test.rb b/test/browser_config_test.rb index dac3e27..867f4e7 100644 --- a/test/browser_config_test.rb +++ b/test/browser_config_test.rb @@ -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