From 6a4b9a7849f4c60fdd2b016b288e01f2a6fd03f2 Mon Sep 17 00:00:00 2001 From: Nikhil Benesch Date: Mon, 13 Jan 2014 00:00:31 -0500 Subject: CHEF-4725: Validate 'log_location' setting on log initialization Previously, a Mixlib::Config setter method verified that 'log_location' was set to a writeable file or a valid IO stream. Due to the way Mixlib::Config handles `default` and `merge!`, this setter method would not fire if the 'log_location' was left unconfigured or if it was set on the command line, resulting in inconsistent error handling. This commit moves the validation logic out of the configuration layer and into the log initializion layer. This ensures that error handling is consistent, regardless of where the 'log_location' setting is configured. Validation logic is also simplified, relying on the MonoLogger class to open and configure any necessary IO streams. --- spec/unit/config_spec.rb | 30 ------------------------------ 1 file changed, 30 deletions(-) (limited to 'spec/unit/config_spec.rb') diff --git a/spec/unit/config_spec.rb b/spec/unit/config_spec.rb index 77870e84d8..2bf003bbdb 100644 --- a/spec/unit/config_spec.rb +++ b/spec/unit/config_spec.rb @@ -121,29 +121,6 @@ describe Chef::Config do end - describe "config attribute writer: log_method=" do - describe "when given an object that responds to sync= e.g. IO" do - it "should configure itself to use the IO as log_location" do - Chef::Config.log_location = STDOUT - Chef::Config.log_location.should == STDOUT - end - end - - describe "when given an object that is stringable (to_str)" do - before do - @mockfile = mock("File", :path => "/var/log/chef/client.log", :sync= => true) - File.should_receive(:new). - with("/var/log/chef/client.log", "a"). - and_return(@mockfile) - end - - it "should configure itself to use a File object based upon the String" do - Chef::Config.log_location = "/var/log/chef/client.log" - Chef::Config.log_location.path.should == "/var/log/chef/client.log" - end - end - end - describe "class method: plaform_specific_path" do it "should return given path on non-windows systems" do platform_mock :unix do @@ -354,13 +331,6 @@ describe Chef::Config do end end - describe "Chef::Config[:log_location]" do - it "raises ConfigurationError when log_location directory is missing" do - missing_path = "/tmp/non-existing-dir/file" - expect{Chef::Config.log_location = missing_path}.to raise_error Chef::Exceptions::ConfigurationError - end - end - describe "Chef::Config[:event_handlers]" do it "sets a event_handlers to an empty array by default" do Chef::Config[:event_handlers].should eq([]) -- cgit v1.2.1