summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordanielsdeleo <dan@opscode.com>2013-01-29 18:48:39 -0800
committerdanielsdeleo <dan@opscode.com>2013-01-29 18:48:39 -0800
commit74d1f3a10a559cd0e72b3d9946faaa9e7c958649 (patch)
tree356bf5c9e171072145f0968d9d5f6e0f87fc7d8e
parentbb103422a98616c3ac72cea355e9799a542cae85 (diff)
parent2ebb6ddd2864cf8ee3c1a3e101a5bf5d61c533ff (diff)
downloadchef-74d1f3a10a559cd0e72b3d9946faaa9e7c958649.tar.gz
Merge branch 'tempfile-finalizer-races'
-rw-r--r--spec/functional/resource/cookbook_file_spec.rb2
-rw-r--r--spec/functional/resource/link_spec.rb18
-rw-r--r--spec/support/chef_helpers.rb2
-rw-r--r--spec/support/shared/functional/directory_resource.rb2
-rw-r--r--spec/support/shared/functional/file_resource.rb2
-rw-r--r--spec/unit/api_client/registration_spec.rb5
6 files changed, 14 insertions, 17 deletions
diff --git a/spec/functional/resource/cookbook_file_spec.rb b/spec/functional/resource/cookbook_file_spec.rb
index e155c4a942..9977cd6c99 100644
--- a/spec/functional/resource/cookbook_file_spec.rb
+++ b/spec/functional/resource/cookbook_file_spec.rb
@@ -67,7 +67,7 @@ describe Chef::Resource::CookbookFile do
# stages files in temp.
context "targets a file outside of the system temp directory" do
let(:windows_non_temp_dir) { File.join(ENV['systemdrive'], make_tmpname(file_base, "non-temp")) }
- let(:path) { File.join(windows_non_temp_dir, make_tmpname(file_base, nil)) }
+ let(:path) { File.join(windows_non_temp_dir, make_tmpname(file_base)) }
before do
FileUtils::mkdir_p(windows_non_temp_dir) if Chef::Platform.windows?
diff --git a/spec/functional/resource/link_spec.rb b/spec/functional/resource/link_spec.rb
index 5566a41587..ca022260cf 100644
--- a/spec/functional/resource/link_spec.rb
+++ b/spec/functional/resource/link_spec.rb
@@ -36,10 +36,10 @@ describe Chef::Resource::Link, :not_supported_on_win2k3 do
end
let(:to) do
- File.join(base_dir, make_tmpname("to_spec", nil))
+ File.join(base_dir, make_tmpname("to_spec"))
end
let(:target_file) do
- File.join(base_dir, make_tmpname("from_spec", nil))
+ File.join(base_dir, make_tmpname("from_spec"))
end
after(:each) do
@@ -270,7 +270,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', nil))
+ @other_target = File.join(base_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 +288,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', nil))
+ nonexistent = File.join(base_dir, make_tmpname('nonexistent_spec'))
symlink(nonexistent, target_file)
symlink?(target_file).should be_true
readlink(target_file).should == nonexistent
@@ -354,7 +354,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", nil))
+ @other_target = File.join(base_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 +370,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", nil))
+ @other_target = File.join(base_dir, make_tmpname("other_spec"))
symlink(@other_target, to)
symlink?(to).should be_true
readlink(to).should == @other_target
@@ -394,7 +394,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", nil)) }
+ let(:absolute_to) { File.join(base_dir, make_tmpname("to_spec")) }
before(:each) do
resource.to(to)
end
@@ -513,7 +513,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", nil))
+ @other_target = File.join(base_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 +537,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", nil))
+ @other_target = File.join(base_dir, make_tmpname("other_spec"))
symlink(@other_target, to)
symlink?(to).should be_true
readlink(to).should == @other_target
diff --git a/spec/support/chef_helpers.rb b/spec/support/chef_helpers.rb
index 74af5f558e..2d7fe609b8 100644
--- a/spec/support/chef_helpers.rb
+++ b/spec/support/chef_helpers.rb
@@ -32,7 +32,7 @@ end
# From Ruby 1.9.2+
# Here for backwards compatibility with Ruby 1.8.7
# http://rubydoc.info/stdlib/tmpdir/1.9.2/Dir/Tmpname
-def make_tmpname(prefix_suffix, n)
+def make_tmpname(prefix_suffix, n = nil)
case prefix_suffix
when String
prefix = prefix_suffix
diff --git a/spec/support/shared/functional/directory_resource.rb b/spec/support/shared/functional/directory_resource.rb
index c4a93c076b..910fb26706 100644
--- a/spec/support/shared/functional/directory_resource.rb
+++ b/spec/support/shared/functional/directory_resource.rb
@@ -138,7 +138,7 @@ end
shared_context Chef::Resource::Directory do
let(:path) do
- File.join(Dir.tmpdir, make_tmpname(directory_base, nil))
+ File.join(Dir.tmpdir, make_tmpname(directory_base))
end
after(:each) do
diff --git a/spec/support/shared/functional/file_resource.rb b/spec/support/shared/functional/file_resource.rb
index 5188805beb..0846511de7 100644
--- a/spec/support/shared/functional/file_resource.rb
+++ b/spec/support/shared/functional/file_resource.rb
@@ -308,7 +308,7 @@ end
shared_context Chef::Resource::File do
let(:path) do
- File.join(Dir.tmpdir, make_tmpname(file_base, nil))
+ File.join(Dir.tmpdir, make_tmpname(file_base))
end
after(:each) do
diff --git a/spec/unit/api_client/registration_spec.rb b/spec/unit/api_client/registration_spec.rb
index 892b22e1b8..3efbe9914b 100644
--- a/spec/unit/api_client/registration_spec.rb
+++ b/spec/unit/api_client/registration_spec.rb
@@ -23,10 +23,7 @@ require 'chef/api_client/registration'
describe Chef::ApiClient::Registration do
let(:key_location) do
- path = nil
- Tempfile.open("client-registration-key") {|f| path = f.path }
- File.unlink(path)
- path
+ make_tmpname("client-registration-key")
end
let(:registration) { Chef::ApiClient::Registration.new("silent-bob", key_location) }