Skip to content

Commit 7475001

Browse files
committed
Updating Link provider delete action specs, for chef-208
1 parent 42b9dfc commit 7475001

3 files changed

Lines changed: 17 additions & 15 deletions

File tree

chef/lib/chef/exceptions.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@ class UnsupportedAction < RuntimeError; end
2929
class MissingLibrary < RuntimeError; end
3030
class User < RuntimeError; end
3131
class Group < RuntimeError; end
32+
class Link < RuntimeError; end
3233
end
3334
end

chef/lib/chef/provider/link.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,21 @@ def action_create
6969

7070
def action_delete
7171
if ::File.exists?(@new_resource.target_file)
72-
if @new_resource.link_type == :symbolic
73-
if ::File.symlink?(@new_resource.target_file)
72+
if @new_resource.link_type == :symbolic
73+
if ::File.symlink?(@new_resource.target_file)
7474
Chef::Log.info("Deleting #{@new_resource} at #{@new_resource.target_file}")
7575
::File.delete(@new_resource.target_file)
7676
@new_resource.updated = true
7777
else
78-
raise "Cannot delete #{@new_resource} at #{@new_resource.target_file}! Not a symbolic link."
78+
raise Chef::Exceptions::Link, "Cannot delete #{@new_resource} at #{@new_resource.target_file}! Not a symbolic link."
7979
end
8080
elsif @new_resource.link_type == :hard
8181
if ::File.exists?(@new_resource.to) && ::File.stat(@current_resource.target_file).ino == ::File.stat(@new_resource.to).ino
8282
Chef::Log.info("Deleting #{@new_resource} at #{@new_resource.target_file}")
8383
::File.delete(@new_resource.target_file)
8484
@new_resource.updated = true
8585
else
86-
raise "Cannot delete #{@new_resource} at #{@new_resource.target_file}! Not a hard link."
86+
raise Chef::Exceptions::Link, "Cannot delete #{@new_resource} at #{@new_resource.target_file}! Not a hard link."
8787
end
8888
end
8989
end

chef/spec/unit/provider/link_spec.rb

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -277,14 +277,14 @@
277277
Chef::Resource::Link.stub!(:new).and_return(@current_resource)
278278
@provider.current_resource = @current_resource
279279
@new_resource.stub!(:to_s).and_return("link[/tmp/fofile]")
280+
File.stub!(:symlink?).and_return(true)
280281
File.stub!(:exists?).and_return(true)
281282
File.stub!(:delete).and_return(true)
282283
end
283284

284-
describe "when the file exists and is writeable" do
285+
describe "when the file exists" do
285286
before do
286287
File.should_receive(:exists?).with("/tmp/fofile-link").and_return(true)
287-
File.should_receive(:writable?).with("/tmp/fofile-link").and_return(true)
288288
end
289289

290290
it "should log an appropriate error message" do
@@ -303,23 +303,24 @@
303303
end
304304
end
305305

306-
describe "when the file does not exist" do
307-
before do
308-
File.should_receive(:exists?).with("/tmp/fofile-link").and_return(false)
306+
describe "when the file exists but is not a symbolic link" do
307+
before(:each) do
308+
File.should_receive(:symlink?).with("/tmp/fofile-link").and_return(false)
309309
end
310310

311-
it "should raise a runtime error" do
312-
lambda { @provider.action_delete }.should raise_error(RuntimeError)
311+
it "should raise a Link error" do
312+
lambda { @provider.action_delete }.should raise_error(Chef::Exceptions::Link)
313313
end
314314
end
315315

316-
describe "when the file isn't writable" do
316+
describe "when the file does not exist" do
317317
before do
318-
File.should_receive(:writable?).with("/tmp/fofile-link").and_return(false)
318+
File.should_receive(:exists?).with("/tmp/fofile-link").and_return(false)
319319
end
320320

321-
it "should raise a runtime error" do
322-
lambda { @provider.action_delete }.should raise_error(RuntimeError)
321+
it "should not raise a Link error" do
322+
lambda { @provider.action_delete }.should_not raise_error(Chef::Exceptions::Link)
323323
end
324324
end
325+
325326
end

0 commit comments

Comments
 (0)