summaryrefslogtreecommitdiff
path: root/spec/support
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2014-04-17 13:46:39 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2014-04-17 13:46:39 -0700
commit055376d9e278418de2426e39fcb3d874eb7e1beb (patch)
tree133684cb302c2b5ace0608a5840b15bba07f9726 /spec/support
parent8934bad60dbe8836e13f9076171a0df8a219f6d9 (diff)
downloadchef-055376d9e278418de2426e39fcb3d874eb7e1beb.tar.gz
add func tests for CHEF-5015
Diffstat (limited to 'spec/support')
-rw-r--r--spec/support/shared/functional/file_resource.rb52
1 files changed, 52 insertions, 0 deletions
diff --git a/spec/support/shared/functional/file_resource.rb b/spec/support/shared/functional/file_resource.rb
index ccb224ab71..02e430d1e7 100644
--- a/spec/support/shared/functional/file_resource.rb
+++ b/spec/support/shared/functional/file_resource.rb
@@ -645,6 +645,58 @@ shared_examples_for "a configured file resource" do
end
end
+ context "when the target file does not exist" do
+ before(:each) do
+ FileUtils.rm_rf(path)
+ end
+
+ after(:each) do
+ FileUtils.rm_rf(path)
+ end
+
+ def symlink?(file_path)
+ if windows?
+ Chef::ReservedNames::Win32::File.symlink?(file_path)
+ else
+ File.symlink?(file_path)
+ end
+ end
+
+ def real_file?(file_path)
+ !symlink?(file_path) && File.file?(file_path)
+ end
+
+ describe "when force_unlink is set to true" do
+ it ":create updates the target" do
+ resource.force_unlink(true)
+ resource.run_action(:create)
+ real_file?(path).should be_true
+ binread(path).should == expected_content
+ resource.should be_updated_by_last_action
+ end
+ end
+
+ describe "when force_unlink is set to false" do
+ it ":create updates the target" do
+ resource.force_unlink(true)
+ resource.run_action(:create)
+ real_file?(path).should be_true
+ binread(path).should == expected_content
+ resource.should be_updated_by_last_action
+ end
+ end
+
+ describe "when force_unlink is not set (default)" do
+ it ":create updates the target" do
+ resource.force_unlink(true)
+ resource.run_action(:create)
+ real_file?(path).should be_true
+ binread(path).should == expected_content
+ resource.should be_updated_by_last_action
+ end
+ end
+ end
+
context "when the target file is a directory" do
before(:each) do
FileUtils.mkdir_p(path)