summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/unit/application/solo_spec.rb4
-rw-r--r--spec/unit/mixin/enforce_ownership_and_permissions_spec.rb2
-rw-r--r--spec/unit/provider/directory_spec.rb138
-rw-r--r--spec/unit/provider/file_spec.rb138
-rw-r--r--spec/unit/provider/remote_directory_spec.rb7
-rw-r--r--spec/unit/resource_reporter_spec.rb19
6 files changed, 170 insertions, 138 deletions
diff --git a/spec/unit/application/solo_spec.rb b/spec/unit/application/solo_spec.rb
index 148fb3cf87..96c89a37a6 100644
--- a/spec/unit/application/solo_spec.rb
+++ b/spec/unit/application/solo_spec.rb
@@ -71,7 +71,7 @@ describe Chef::Application::Solo do
it "should perform a RESTful GET on the supplied URL" do
@app.reconfigure
- @app.chef_solo_json.should == {"a" => "b"}
+ @app.instance_variable_get(:@chef_client_json).should == {"a" => "b"}
end
end
@@ -84,7 +84,7 @@ describe Chef::Application::Solo do
it "should parse the json out of the file" do
@app.reconfigure
- @app.chef_solo_json.should == {"a" => "b"}
+ @app.instance_variable_get(:@chef_client_json).should == {"a" => "b"}
end
end
diff --git a/spec/unit/mixin/enforce_ownership_and_permissions_spec.rb b/spec/unit/mixin/enforce_ownership_and_permissions_spec.rb
index 53a8260cdc..efbbe9218e 100644
--- a/spec/unit/mixin/enforce_ownership_and_permissions_spec.rb
+++ b/spec/unit/mixin/enforce_ownership_and_permissions_spec.rb
@@ -84,6 +84,8 @@ describe Chef::Mixin::EnforceOwnershipAndPermissions do
end
it "sets updated_by_last_action on the new resource" do
+ @provider.new_resource.owner(0) # CHEF-3557 hack - Set these because we don't for windows
+ @provider.new_resource.group(0) # CHEF-3557 hack - Set these because we don't for windows
@provider.new_resource.should_receive(:updated_by_last_action)
Chef::FileAccessControl.any_instance.stub(:set_all)
@provider.run_action(:create)
diff --git a/spec/unit/provider/directory_spec.rb b/spec/unit/provider/directory_spec.rb
index 4f297e0115..5118d086fc 100644
--- a/spec/unit/provider/directory_spec.rb
+++ b/spec/unit/provider/directory_spec.rb
@@ -33,74 +33,80 @@ describe Chef::Provider::Directory do
@directory = Chef::Provider::Directory.new(@new_resource, @run_context)
end
- it "should load the current resource based on the new resource" do
- File.stub!(:exist?).and_return(true)
- cstats = mock("stats")
- cstats.stub!(:uid).and_return(500)
- cstats.stub!(:gid).and_return(500)
- cstats.stub!(:mode).and_return(0755)
- File.should_receive(:stat).twice.and_return(cstats)
- @directory.load_current_resource
- @directory.current_resource.path.should eql(@new_resource.path)
- @directory.current_resource.owner.should eql(500)
- @directory.current_resource.group.should eql(500)
- @directory.current_resource.mode.should == 00755
- end
-
- it "should create a new directory on create, setting updated to true" do
- @new_resource.path "/tmp/foo"
-
- File.should_receive(:exist?).exactly(3).and_return(false)
- Dir.should_receive(:mkdir).with(@new_resource.path).once.and_return(true)
-
- @directory.should_receive(:set_all_access_controls)
- @directory.stub!(:update_new_file_state)
- @directory.run_action(:create)
- @directory.new_resource.should be_updated
- end
-
- it "should raise an exception if the parent directory does not exist and recursive is false" do
- @new_resource.path "/tmp/some/dir"
- @new_resource.recursive false
- lambda { @directory.run_action(:create) }.should raise_error(Chef::Exceptions::EnclosingDirectoryDoesNotExist)
- end
-
- it "should create a new directory when parent directory does not exist if recursive is true and permissions are correct" do
- @new_resource.path "/path/to/dir"
- @new_resource.recursive true
- File.should_receive(:exist?).with(@new_resource.path).ordered.and_return(false)
- File.should_receive(:exist?).with(@new_resource.path).ordered.and_return(false)
-
- File.should_receive(:exist?).with('/path/to').ordered.and_return(false)
- File.should_receive(:exist?).with('/path').ordered.and_return(true)
- File.should_receive(:writable?).with('/path').ordered.and_return(true)
- File.should_receive(:exist?).with(@new_resource.path).ordered.and_return(false)
-
- FileUtils.should_receive(:mkdir_p).with(@new_resource.path).and_return(true)
- @directory.should_receive(:set_all_access_controls)
- @directory.stub!(:update_new_file_state)
- @directory.run_action(:create)
- @new_resource.should be_updated
- end
-
- # it "should raise an error when creating a directory recursively and permissions do not allow creation" do
+ context "load_current_resource_attrs", :unix_only do
+ it "should load the current resource based on the new resource" do
+ File.stub!(:exist?).and_return(true)
+ cstats = mock("stats")
+ cstats.stub!(:uid).and_return(500)
+ cstats.stub!(:gid).and_return(500)
+ cstats.stub!(:mode).and_return(0755)
+ File.should_receive(:stat).twice.and_return(cstats)
+ @directory.load_current_resource
+ @directory.current_resource.path.should eql(@new_resource.path)
+ @directory.current_resource.owner.should eql(500)
+ @directory.current_resource.group.should eql(500)
+ @directory.current_resource.mode.should == 00755
+ end
+
+ it "should create a new directory on create, setting updated to true" do
+ @new_resource.path "/tmp/foo"
+
+ File.should_receive(:exist?).exactly(3).and_return(false)
+ Dir.should_receive(:mkdir).with(@new_resource.path).once.and_return(true)
+
+ @directory.should_receive(:set_all_access_controls)
+ @directory.stub!(:update_new_file_state)
+ @directory.run_action(:create)
+ @directory.new_resource.should be_updated
+ end
+
+ it "should raise an exception if the parent directory does not exist and recursive is false" do
+ @new_resource.path "/tmp/some/dir"
+ @new_resource.recursive false
+ lambda { @directory.run_action(:create) }.should raise_error(Chef::Exceptions::EnclosingDirectoryDoesNotExist)
+ end
+
+ it "should create a new directory when parent directory does not exist if recursive is true and permissions are correct" do
+ @new_resource.path "/path/to/dir"
+ @new_resource.recursive true
+ File.should_receive(:exist?).with(@new_resource.path).ordered.and_return(false)
+ File.should_receive(:exist?).with(@new_resource.path).ordered.and_return(false)
+
+ File.should_receive(:exist?).with('/path/to').ordered.and_return(false)
+ File.should_receive(:exist?).with('/path').ordered.and_return(true)
+ File.should_receive(:writable?).with('/path').ordered.and_return(true)
+ File.should_receive(:exist?).with(@new_resource.path).ordered.and_return(false)
+
+ FileUtils.should_receive(:mkdir_p).with(@new_resource.path).and_return(true)
+ @directory.should_receive(:set_all_access_controls)
+ @directory.stub!(:update_new_file_state)
+ @directory.run_action(:create)
+ @new_resource.should be_updated
+ end
+
+ # it "should raise an error when creating a directory recursively and permissions do not allow creation" do
+
+ # end
+
+ it "should raise an error when creating a directory when parent directory is a file" do
+ File.should_receive(:directory?).and_return(false)
+ Dir.should_not_receive(:mkdir).with(@new_resource.path)
+ lambda { @directory.run_action(:create) }.should raise_error(Chef::Exceptions::EnclosingDirectoryDoesNotExist)
+ @directory.new_resource.should_not be_updated
+ end
- # end
-
- it "should raise an error when creating a directory when parent directory is a file" do
- File.should_receive(:directory?).and_return(false)
- Dir.should_not_receive(:mkdir).with(@new_resource.path)
- lambda { @directory.run_action(:create) }.should raise_error(Chef::Exceptions::EnclosingDirectoryDoesNotExist)
- @directory.new_resource.should_not be_updated
+ it "should not create the directory if it already exists" do
+ stub_file_cstats
+ @new_resource.path "/tmp/foo"
+ File.should_receive(:exist?).exactly(3).and_return(true)
+ Dir.should_not_receive(:mkdir).with(@new_resource.path)
+ @directory.should_receive(:set_all_access_controls)
+ @directory.run_action(:create)
+ end
end
-
- it "should not create the directory if it already exists" do
- stub_file_cstats
- @new_resource.path "/tmp/foo"
- File.should_receive(:exist?).exactly(3).and_return(true)
- Dir.should_not_receive(:mkdir).with(@new_resource.path)
- @directory.should_receive(:set_all_access_controls)
- @directory.run_action(:create)
+
+ context "load_current_resource_attrs", :windows_only do
+ pending "CHEF-3557: Fix implicit resource change collection on Windows"
end
it "should delete the directory if it exists, and is writable with action_delete" do
diff --git a/spec/unit/provider/file_spec.rb b/spec/unit/provider/file_spec.rb
index 13b79e4bd6..28d2aac2b5 100644
--- a/spec/unit/provider/file_spec.rb
+++ b/spec/unit/provider/file_spec.rb
@@ -53,76 +53,82 @@ describe Chef::Provider::File do
@provider.current_resource.content.should eql(nil)
end
- it "should collect the current state of the file on the filesystem and populate current_resource" do
- # test setup
- stat_struct = mock("::File.stat", :mode => 0600, :uid => 0, :gid => 0, :mtime => 10000)
- ::File.should_receive(:stat).exactly(3).with(@resource.path).and_return(stat_struct)
-
- # test execution
- @provider.load_current_resource
-
- # post-condition checks
- @provider.current_resource.mode.should == 0600
- @provider.current_resource.owner.should == 0
- @provider.current_resource.group.should == 0
- end
-
- it "should NOT update the new_resource state with the current_resourse state if new_resource state is already specified" do
- # test setup
- stat_struct = mock("::File.stat", :mode => 0600, :uid => 0, :gid => 0, :mtime => 10000)
- ::File.should_receive(:stat).exactly(3).with(@resource.path).and_return(stat_struct)
-
- @provider.new_resource.group(1)
- @provider.new_resource.owner(1)
- @provider.new_resource.mode(0644)
-
- # test execution
- @provider.load_current_resource
-
- # post-condition checks
- @provider.new_resource.group.should == 1
- @provider.new_resource.owner.should == 1
- @provider.new_resource.mode.should == 0644
+ context "load_current_resource_attrs", :unix_only do
+ it "should collect the current state of the file on the filesystem and populate current_resource" do
+ # test setup
+ stat_struct = mock("::File.stat", :mode => 0600, :uid => 0, :gid => 0, :mtime => 10000)
+ ::File.should_receive(:stat).exactly(3).with(@resource.path).and_return(stat_struct)
+
+ # test execution
+ @provider.load_current_resource
+
+ # post-condition checks
+ @provider.current_resource.mode.should == 0600
+ @provider.current_resource.owner.should == 0
+ @provider.current_resource.group.should == 0
+ end
+
+ it "should NOT update the new_resource state with the current_resourse state if new_resource state is already specified" do
+ # test setup
+ stat_struct = mock("::File.stat", :mode => 0600, :uid => 0, :gid => 0, :mtime => 10000)
+ ::File.should_receive(:stat).exactly(3).with(@resource.path).and_return(stat_struct)
+
+ @provider.new_resource.group(1)
+ @provider.new_resource.owner(1)
+ @provider.new_resource.mode(0644)
+
+ # test execution
+ @provider.load_current_resource
+
+ # post-condition checks
+ @provider.new_resource.group.should == 1
+ @provider.new_resource.owner.should == 1
+ @provider.new_resource.mode.should == 0644
+ end
+
+ it "should update the new_resource state with the current_resource state if the new_resource state is not specified." do
+ # test setup
+ stat_struct = mock("::File.stat", :mode => 0600, :uid => 0, :gid => 0, :mtime => 10000)
+ ::File.should_receive(:stat).exactly(3).with(@resource.path).and_return(stat_struct)
+
+ @provider.new_resource.group(nil)
+ @provider.new_resource.owner(nil)
+ @provider.new_resource.mode(nil)
+
+ # test execution
+ @provider.load_current_resource
+
+ # post-condition checks
+ @provider.new_resource.group.should eql(@provider.current_resource.group)
+ @provider.new_resource.owner.should eql(@provider.current_resource.owner)
+ @provider.new_resource.mode.should eql(@provider.current_resource.mode)
+ end
+
+ it "should update the new_resource when attempting to set the new state" do
+ # test setup
+ stat_struct = mock("::File.stat", :mode => 0600, :uid => 0, :gid => 0, :mtime => 10000)
+ # called once in update_new_file_state and once in checksum
+ ::File.should_receive(:stat).twice.with(@provider.new_resource.path).and_return(stat_struct)
+ ::File.should_receive(:directory?).once.with(@provider.new_resource.path).and_return(false)
+
+ @provider.new_resource.group(nil)
+ @provider.new_resource.owner(nil)
+ @provider.new_resource.mode(nil)
+
+ # test exectution
+ @provider.update_new_file_state
+
+ # post-condition checks
+ @provider.new_resource.group.should == 0
+ @provider.new_resource.owner.should == 0
+ @provider.new_resource.mode.should == 0600
+ end
end
- it "should update the new_resource state with the current_resource state if the new_resource state is not specified." do
- # test setup
- stat_struct = mock("::File.stat", :mode => 0600, :uid => 0, :gid => 0, :mtime => 10000)
- ::File.should_receive(:stat).exactly(3).with(@resource.path).and_return(stat_struct)
-
- @provider.new_resource.group(nil)
- @provider.new_resource.owner(nil)
- @provider.new_resource.mode(nil)
-
- # test execution
- @provider.load_current_resource
-
- # post-condition checks
- @provider.new_resource.group.should eql(@provider.current_resource.group)
- @provider.new_resource.owner.should eql(@provider.current_resource.owner)
- @provider.new_resource.mode.should eql(@provider.current_resource.mode)
+ context "load_current_resource_attrs", :windows_only do
+ pending "CHEF-3557: Fix implicit resource change collection on Windows"
end
- it "should update the new_resource when attempting to set the new state" do
- # test setup
- stat_struct = mock("::File.stat", :mode => 0600, :uid => 0, :gid => 0, :mtime => 10000)
- # called once in update_new_file_state and once in checksum
- ::File.should_receive(:stat).twice.with(@provider.new_resource.path).and_return(stat_struct)
- ::File.should_receive(:directory?).once.with(@provider.new_resource.path).and_return(false)
-
- @provider.new_resource.group(nil)
- @provider.new_resource.owner(nil)
- @provider.new_resource.mode(nil)
-
- # test exectution
- @provider.update_new_file_state
-
- # post-condition checks
- @provider.new_resource.group.should == 0
- @provider.new_resource.owner.should == 0
- @provider.new_resource.mode.should == 0600
-end
-
it "should load a mostly blank current resource if the file specified in new_resource doesn't exist/isn't readable" do
resource = Chef::Resource::File.new("seattle")
resource.path(File.expand_path(File.join(CHEF_SPEC_DATA, "templates", "woot.txt")))
diff --git a/spec/unit/provider/remote_directory_spec.rb b/spec/unit/provider/remote_directory_spec.rb
index 19a17c269f..0171853eb3 100644
--- a/spec/unit/provider/remote_directory_spec.rb
+++ b/spec/unit/provider/remote_directory_spec.rb
@@ -100,6 +100,13 @@ describe Chef::Provider::RemoteDirectory do
after {FileUtils.rm_rf(@destination_dir)}
+ # CHEF-3552
+ it "creates the toplevel directory without error " do
+ @resource.recursive(false)
+ @provider.run_action(:create)
+ ::File.exist?(@destination_dir).should be_true
+ end
+
it "transfers the directory with all contents" do
@provider.run_action(:create)
::File.exist?(@destination_dir + '/remote_dir_file1.txt').should be_true
diff --git a/spec/unit/resource_reporter_spec.rb b/spec/unit/resource_reporter_spec.rb
index bc8e3995f7..51f4ba7c19 100644
--- a/spec/unit/resource_reporter_spec.rb
+++ b/spec/unit/resource_reporter_spec.rb
@@ -413,18 +413,24 @@ describe Chef::ResourceReporter do
@rest_client.should_receive(:post_rest).
with("reports/nodes/spitfire/runs", {:action => :begin}).
and_raise(@error)
- @resource_reporter.node_load_completed(@node, :expanded_run_list, :config)
end
it "assumes the feature is not enabled" do
+ @resource_reporter.node_load_completed(@node, :expanded_run_list, :config)
@resource_reporter.reporting_enabled?.should be_false
end
it "does not send a resource report to the server" do
+ @resource_reporter.node_load_completed(@node, :expanded_run_list, :config)
@rest_client.should_not_receive(:post_rest)
@resource_reporter.run_completed(@node)
end
+ it "prints an error about the 404" do
+ Chef::Log.should_receive(:debug).with(/404/)
+ @resource_reporter.node_load_completed(@node, :expanded_run_list, :config)
+ end
+
end
context "when the server returns a 500 to the client" do
@@ -435,18 +441,23 @@ describe Chef::ResourceReporter do
@rest_client.should_receive(:post_rest).
with("reports/nodes/spitfire/runs", {:action => :begin}).
and_raise(@error)
- @resource_reporter.node_load_completed(@node, :expanded_run_list, :config)
end
it "assumes the feature is not enabled" do
+ @resource_reporter.node_load_completed(@node, :expanded_run_list, :config)
@resource_reporter.reporting_enabled?.should be_false
end
it "does not send a resource report to the server" do
+ @resource_reporter.node_load_completed(@node, :expanded_run_list, :config)
@rest_client.should_not_receive(:post_rest)
@resource_reporter.run_completed(@node)
end
+ it "prints an error about the error" do
+ Chef::Log.should_receive(:info).with(/500/)
+ @resource_reporter.node_load_completed(@node, :expanded_run_list, :config)
+ end
end
context "when the server returns a 500 to the client and enable_reporting_url_fatals is true" do
@@ -465,12 +476,12 @@ describe Chef::ResourceReporter do
Chef::Config[:enable_reporting_url_fatals] = @enable_reporting_url_fatals
end
- it "fails the run" do
+ it "fails the run and prints an message about the error" do
+ Chef::Log.should_receive(:error).with(/500/)
lambda {
@resource_reporter.node_load_completed(@node, :expanded_run_list, :config)
}.should raise_error(Net::HTTPServerException)
end
-
end
context "after creating the run history document" do