summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraliasgar16 <aliasgar.batterywala@clogeny.com>2016-09-01 15:44:43 +0530
committeraliasgar16 <aliasgar.batterywala@clogeny.com>2016-09-01 15:44:43 +0530
commit4ce8d8d050ddcb4c642bcd2e4ac71bedcc743787 (patch)
tree886fc4692ef18692cfaca8e1a53ca35dfd36228e
parent719718f35169670bd79be8cd595bdf0fe4b0e221 (diff)
downloadchef-4ce8d8d050ddcb4c642bcd2e4ac71bedcc743787.tar.gz
Added RSpecs for the fix.
-rw-r--r--spec/unit/provider/link_spec.rb155
1 files changed, 155 insertions, 0 deletions
diff --git a/spec/unit/provider/link_spec.rb b/spec/unit/provider/link_spec.rb
index 6bb08551a2..8931b781ad 100644
--- a/spec/unit/provider/link_spec.rb
+++ b/spec/unit/provider/link_spec.rb
@@ -249,4 +249,159 @@ describe Chef::Resource::Link, :not_supported_on_win2k3 do
end
end
end
+
+ describe 'action_delete' do
+ before(:each) do
+ stat = double("stats", :ino => 5)
+ allow(stat).to receive(:uid).and_return(501)
+ allow(stat).to receive(:gid).and_return(501)
+ allow(stat).to receive(:mode).and_return(0755)
+ allow(provider.file_class).to receive(:stat).with(
+ "#{CHEF_SPEC_DATA}/fofile-link").and_return(stat)
+
+ provider.load_current_resource
+ end
+
+ shared_context 'delete link to directories on Windows' do
+ before do
+ allow(::File).to receive(:directory?).with(
+ "#{CHEF_SPEC_DATA}/fofile-link").and_return(true)
+ end
+
+ it 'invokes Dir.delete method to delete the link' do
+ expect(::Dir).to receive(:delete).with(provider.new_resource.target_file)
+ expect(Chef::Log).to receive(:info).with("#{provider.new_resource} deleted")
+ provider.run_action(:delete)
+ end
+ end
+
+ shared_context 'delete link to directories on Linux' do
+ before do
+ allow(::File).to receive(:directory?).with(
+ "#{CHEF_SPEC_DATA}/fofile-link").and_return(true)
+ end
+
+ it 'invokes File.delete method to delete the link' do
+ expect(::File).to receive(:delete).with(provider.new_resource.target_file)
+ expect(Chef::Log).to receive(:info).with("#{provider.new_resource} deleted")
+ provider.run_action(:delete)
+ end
+ end
+
+ shared_context 'delete link to files' do
+ before do
+ allow(::File).to receive(:directory?).with(
+ "#{CHEF_SPEC_DATA}/fofile-link").and_return(false)
+ end
+
+ it 'invokes File.delete method to delete the link' do
+ expect(::File).to receive(:delete).with(provider.new_resource.target_file)
+ expect(Chef::Log).to receive(:info).with("#{provider.new_resource} deleted")
+ provider.run_action(:delete)
+ end
+ end
+
+ shared_context 'soft links prerequisites' do
+ before(:each) do
+ allow(provider.file_class).to receive(:symlink?).with(
+ "#{CHEF_SPEC_DATA}/fofile-link").and_return(true)
+ allow(provider.file_class).to receive(:readlink).with(
+ "#{CHEF_SPEC_DATA}/fofile-link").and_return("#{CHEF_SPEC_DATA}/fofile")
+ end
+ end
+
+ shared_context 'hard links prerequisites' do
+ let(:new_resource) do
+ result = Chef::Resource::Link.new("#{CHEF_SPEC_DATA}/fofile-link")
+ result.to "#{CHEF_SPEC_DATA}/fofile"
+ result.link_type :hard
+ result
+ end
+
+ before(:each) do
+ stat = double("stats", :ino => 5)
+ allow(stat).to receive(:uid).and_return(502)
+ allow(stat).to receive(:gid).and_return(502)
+ allow(stat).to receive(:mode).and_return(0644)
+
+ allow(provider.file_class).to receive(:symlink?).with(
+ "#{CHEF_SPEC_DATA}/fofile-link").and_return(false)
+
+ allow(File).to receive(:exists?).with(
+ "#{CHEF_SPEC_DATA}/fofile-link").and_return(true)
+ allow(File).to receive(:exists?).with(
+ "#{CHEF_SPEC_DATA}/fofile").and_return(true)
+
+ allow(provider.file_class).to receive(:stat).with(
+ "#{CHEF_SPEC_DATA}/fofile").and_return(stat)
+ end
+ end
+
+ context 'on Windows platform' do
+ let(:resource_link) do
+ Chef::Resource::Link.new(provider.new_resource.name)
+ end
+
+ before(:each) do
+ allow(Chef::Resource::Link).to receive(:new).with(
+ provider.new_resource.name).and_return(resource_link)
+ allow(resource_link).to receive(:verify_links_supported!)
+ allow(Chef::Platform).to receive(:windows?).and_return(true)
+ end
+
+ context 'soft links' do
+ include_context 'soft links prerequisites'
+
+ context 'to directories' do
+ include_context 'delete link to directories on Windows'
+ end
+
+ context 'to files' do
+ include_context 'delete link to files'
+ end
+ end
+
+ context 'hard links' do
+ include_context 'hard links prerequisites'
+
+ context 'to directories' do
+ include_context 'delete link to directories on Windows'
+ end
+
+ context 'to files' do
+ include_context 'delete link to files'
+ end
+ end
+ end
+
+ context 'on Linux platform' do
+ before(:each) do
+ allow(Chef::Platform).to receive(:windows?).and_return(false)
+ end
+
+ context 'soft links' do
+ include_context 'soft links prerequisites'
+
+ context 'to directories' do
+ include_context 'delete link to directories on Linux'
+ end
+
+ context 'to files' do
+ include_context 'delete link to files'
+ end
+ end
+
+ context 'hard links' do
+ include_context 'hard links prerequisites'
+
+ context 'to directories' do
+ include_context 'delete link to directories on Linux'
+ end
+
+ context 'to files' do
+ include_context 'delete link to files'
+ end
+ end
+ end
+ end
end