summaryrefslogtreecommitdiff
path: root/spec/functional
diff options
context:
space:
mode:
authorsersut <serdar@opscode.com>2013-05-20 11:57:57 -0700
committersersut <serdar@opscode.com>2013-05-20 11:57:57 -0700
commit66b63c96fa3314305c3b488db36558715780b789 (patch)
treea2604656d32f99dbae6fd33d0dfa242e14f2aa81 /spec/functional
parent4a18e1bf98e2a8edabab3b13c674c68150605228 (diff)
downloadchef-66b63c96fa3314305c3b488db36558715780b789.tar.gz
Fix missed link specs and cleanup.
Diffstat (limited to 'spec/functional')
-rw-r--r--spec/functional/resource/link_spec.rb58
1 files changed, 42 insertions, 16 deletions
diff --git a/spec/functional/resource/link_spec.rb b/spec/functional/resource/link_spec.rb
index fb26282bfc..1e6c7d8112 100644
--- a/spec/functional/resource/link_spec.rb
+++ b/spec/functional/resource/link_spec.rb
@@ -27,32 +27,51 @@ describe Chef::Resource::Link, :not_supported_on_win2k3 do
let(:expect_updated?) {true}
- let(:base_dir) do
+ # We create the files in a different directory than tmp to exercise
+ # different file deployment strategies more completely.
+ let(:test_file_dir) do
if windows?
- Chef::ReservedNames::Win32::File.get_long_path_name(Dir.tmpdir.gsub('/', '\\'))
+ File.join(ENV['systemdrive'], "test-dir")
else
- Dir.tmpdir
+ File.join(CHEF_SPEC_DATA, "test-dir")
end
end
+ before do
+ FileUtils::mkdir_p(test_file_dir)
+ end
+
+ after do
+ FileUtils::rm_rf(test_file_dir)
+ end
+
let(:to) do
- File.join(base_dir, make_tmpname("to_spec"))
+ File.join(test_file_dir, make_tmpname("to_spec"))
end
let(:target_file) do
- File.join(base_dir, make_tmpname("from_spec"))
+ File.join(test_file_dir, make_tmpname("from_spec"))
end
after(:each) do
- # TODO Windows fails to clean up some symlinks.
begin
- FileUtils.rm_r(to) if File.exists?(to)
- FileUtils.rm_r(target_file) if File.exists?(target_file)
- FileUtils.rm_r(CHEF_SPEC_BACKUP_PATH) if File.exists?(CHEF_SPEC_BACKUP_PATH)
+ cleanup_link(to) if File.exists?(to)
+ cleanup_link(target_file) if File.exists?(target_file)
+ cleanup_link(CHEF_SPEC_BACKUP_PATH) if File.exists?(CHEF_SPEC_BACKUP_PATH)
rescue
puts "Could not remove a file: #{$!}"
end
end
+ def cleanup_link(path)
+ if windows? && File.directory?(path)
+ # If the link target is a directory rm_rf doesn't work all the
+ # time on windows.
+ system "rmdir '#{path}'"
+ else
+ FileUtils.rm_rf(path)
+ end
+ end
+
def canonicalize(path)
windows? ? path.gsub('/', '\\') : path
end
@@ -270,7 +289,7 @@ describe Chef::Resource::Link, :not_supported_on_win2k3 do
end
context 'pointing somewhere else' do
before(:each) do
- @other_target = File.join(base_dir, make_tmpname('other_spec'))
+ @other_target = File.join(test_file_dir, make_tmpname('other_spec'))
File.open(@other_target, 'w') { |file| file.write('eek') }
symlink(@other_target, target_file)
symlink?(target_file).should be_true
@@ -288,7 +307,7 @@ describe Chef::Resource::Link, :not_supported_on_win2k3 do
end
context 'pointing nowhere' do
before(:each) do
- nonexistent = File.join(base_dir, make_tmpname('nonexistent_spec'))
+ nonexistent = File.join(test_file_dir, make_tmpname('nonexistent_spec'))
symlink(nonexistent, target_file)
symlink?(target_file).should be_true
readlink(target_file).should == nonexistent
@@ -338,6 +357,13 @@ describe Chef::Resource::Link, :not_supported_on_win2k3 do
def denied_acl(sid, expected_perms)
[ ACE.access_denied(sid, expected_perms[:specific]) ]
end
+ def parent_inheritable_acls
+ dummy_file_path = File.join(test_file_dir, "dummy_file")
+ dummy_file = FileUtils.touch(dummy_file_path)
+ dummy_desc = get_security_descriptor(dummy_file_path)
+ FileUtils.rm_rf(dummy_file_path)
+ dummy_desc
+ end
end
end
context 'when the link destination is a directory' do
@@ -354,7 +380,7 @@ describe Chef::Resource::Link, :not_supported_on_win2k3 do
context "when the link destination is a symbolic link" do
context 'to a file that exists' do
before(:each) do
- @other_target = File.join(base_dir, make_tmpname("other_spec"))
+ @other_target = File.join(test_file_dir, make_tmpname("other_spec"))
File.open(@other_target, "w") { |file| file.write("eek") }
symlink(@other_target, to)
symlink?(to).should be_true
@@ -370,7 +396,7 @@ describe Chef::Resource::Link, :not_supported_on_win2k3 do
end
context 'to a file that does not exist' do
before(:each) do
- @other_target = File.join(base_dir, make_tmpname("other_spec"))
+ @other_target = File.join(test_file_dir, make_tmpname("other_spec"))
symlink(@other_target, to)
symlink?(to).should be_true
readlink(to).should == @other_target
@@ -394,7 +420,7 @@ describe Chef::Resource::Link, :not_supported_on_win2k3 do
}.each do |prefix, desc|
context desc do
let(:to) { "#{prefix}#{File.basename(absolute_to)}" }
- let(:absolute_to) { File.join(base_dir, make_tmpname("to_spec")) }
+ let(:absolute_to) { File.join(test_file_dir, make_tmpname("to_spec")) }
before(:each) do
resource.to(to)
end
@@ -513,7 +539,7 @@ describe Chef::Resource::Link, :not_supported_on_win2k3 do
context "when the link destination is a symbolic link" do
context 'to a real file' do
before(:each) do
- @other_target = File.join(base_dir, make_tmpname("other_spec"))
+ @other_target = File.join(test_file_dir, make_tmpname("other_spec"))
File.open(@other_target, "w") { |file| file.write("eek") }
symlink(@other_target, to)
symlink?(to).should be_true
@@ -537,7 +563,7 @@ describe Chef::Resource::Link, :not_supported_on_win2k3 do
end
context 'to a nonexistent file' do
before(:each) do
- @other_target = File.join(base_dir, make_tmpname("other_spec"))
+ @other_target = File.join(test_file_dir, make_tmpname("other_spec"))
symlink(@other_target, to)
symlink?(to).should be_true
readlink(to).should == @other_target