diff options
author | Bryan McLellan <btm@loftninjas.org> | 2012-10-25 18:45:30 -0400 |
---|---|---|
committer | Bryan McLellan <btm@loftninjas.org> | 2012-10-25 18:45:30 -0400 |
commit | 5b771324a7b4d244cbabe996804664d004efce4a (patch) | |
tree | f080b99581b47335ba834b7a157558896f4fb952 | |
parent | f0db9ad9f3e17627ad00df2b94613fa05526f077 (diff) | |
download | chef-5b771324a7b4d244cbabe996804664d004efce4a.tar.gz |
CHEF-3554: limit unix only specs
Because we're hacking out functionality to fix CHEF-3554, we need to skip
the related tests as well. These must be fixed for CHEF-3557.
-rw-r--r-- | chef/spec/unit/mixin/enforce_ownership_and_permissions_spec.rb | 2 | ||||
-rw-r--r-- | chef/spec/unit/provider/directory_spec.rb | 138 | ||||
-rw-r--r-- | chef/spec/unit/provider/file_spec.rb | 138 |
3 files changed, 146 insertions, 132 deletions
diff --git a/chef/spec/unit/mixin/enforce_ownership_and_permissions_spec.rb b/chef/spec/unit/mixin/enforce_ownership_and_permissions_spec.rb index de6a9dd0c6..1f4c11d367 100644 --- a/chef/spec/unit/mixin/enforce_ownership_and_permissions_spec.rb +++ b/chef/spec/unit/mixin/enforce_ownership_and_permissions_spec.rb @@ -79,6 +79,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/chef/spec/unit/provider/directory_spec.rb b/chef/spec/unit/provider/directory_spec.rb index 4f297e0115..5118d086fc 100644 --- a/chef/spec/unit/provider/directory_spec.rb +++ b/chef/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/chef/spec/unit/provider/file_spec.rb b/chef/spec/unit/provider/file_spec.rb index 13b79e4bd6..28d2aac2b5 100644 --- a/chef/spec/unit/provider/file_spec.rb +++ b/chef/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"))) |