diff options
| author | Daniel Pittman <daniel@puppetlabs.com> | 2011-04-08 15:24:38 -0700 |
|---|---|---|
| committer | Daniel Pittman <daniel@puppetlabs.com> | 2011-04-08 15:24:38 -0700 |
| commit | ab5f1e8ffbe6503687c6f46bcaed9316da0151b9 (patch) | |
| tree | 922bf531dcd3bf5ea3581c44370574f11c875e8e /spec | |
| parent | 87f4e0a1ce60ddb443a5eda459793c5acb7fce1e (diff) | |
| parent | f9271b918833b250da304efa8efdd0fdb64e89ca (diff) | |
| download | puppet-ab5f1e8ffbe6503687c6f46bcaed9316da0151b9.tar.gz puppet-ab5f1e8ffbe6503687c6f46bcaed9316da0151b9.tar.xz puppet-ab5f1e8ffbe6503687c6f46bcaed9316da0151b9.zip | |
Merge branch 'maint/next/improve-test-suite-performance' into next
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/lib/puppet_spec/files.rb | 56 | ||||
| -rw-r--r-- | spec/spec_helper.rb | 4 | ||||
| -rwxr-xr-x | spec/unit/application/faces_base_spec.rb | 7 |
3 files changed, 44 insertions, 23 deletions
diff --git a/spec/lib/puppet_spec/files.rb b/spec/lib/puppet_spec/files.rb index 38c51a572..30fb4fc42 100644 --- a/spec/lib/puppet_spec/files.rb +++ b/spec/lib/puppet_spec/files.rb @@ -3,41 +3,51 @@ require 'tempfile' # A support module for testing files. module PuppetSpec::Files + # This code exists only to support tests that run as root, pretty much. + # Once they have finally been eliminated this can all go... --daniel 2011-04-08 + if Puppet.features.posix? then + def self.in_tmp(path) + path =~ /^\/tmp/ or path =~ /^\/var\/folders/ + end + elsif Puppet.features.microsoft_windows? + def self.in_tmp(path) + tempdir = File.expand_path(File.join(Dir::LOCAL_APPDATA, "Temp")) + path =~ /^#{tempdir}/ + end + else + fail "Help! Can't find in_tmp for this platform" + end + def self.cleanup - if defined?($tmpfiles) - $tmpfiles.each do |file| - file = File.expand_path(file) - if Puppet.features.posix? and file !~ /^\/tmp/ and file !~ /^\/var\/folders/ - puts "Not deleting tmpfile #{file} outside of /tmp or /var/folders" - next - elsif Puppet.features.microsoft_windows? - tempdir = File.expand_path(File.join(Dir::LOCAL_APPDATA, "Temp")) - if file !~ /^#{tempdir}/ - puts "Not deleting tmpfile #{file} outside of #{tempdir}" - next - end - end - if FileTest.exist?(file) - system("chmod -R 755 '#{file}'") - system("rm -rf '#{file}'") - end + $global_tempfiles ||= [] + while path = $global_tempfiles.pop do + fail "Not deleting tmpfile #{path} outside regular tmpdir" unless in_tmp(path) + + begin + FileUtils.rm_r path, :secure => true + rescue Errno::ENOENT + # nothing to do end - $tmpfiles.clear end end def tmpfile(name) + # Generate a temporary file, just for the name... source = Tempfile.new(name) path = source.path source.close! - $tmpfiles ||= [] - $tmpfiles << path + + # ...record it for cleanup, + $global_tempfiles ||= [] + $global_tempfiles << File.expand_path(path) + + # ...and bam. path end def tmpdir(name) - file = tmpfile(name) - FileUtils.mkdir_p(file) - file + path = tmpfile(name) + FileUtils.mkdir_p(path) + path end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index fc63c6d19..e8ab66611 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -38,6 +38,8 @@ RSpec.configure do |config| config.mock_with :mocha config.before :each do + GC.disable + # these globals are set by Application $puppet_application_mode = nil $puppet_application_name = nil @@ -65,6 +67,8 @@ RSpec.configure do |config| @logs.clear Puppet::Util::Log.close_all + + GC.enable end end diff --git a/spec/unit/application/faces_base_spec.rb b/spec/unit/application/faces_base_spec.rb index 6d8815f44..6d8456612 100755 --- a/spec/unit/application/faces_base_spec.rb +++ b/spec/unit/application/faces_base_spec.rb @@ -59,6 +59,13 @@ describe Puppet::Application::FacesBase do describe "parsing the command line" do context "with just an action" do before :all do + # We have to stub Signal.trap to avoid a crazy mess where we take + # over signal handling and make it impossible to cancel the test + # suite run. + # + # It would be nice to fix this elsewhere, but it is actually hard to + # capture this in rspec 2.5 and all. :( --daniel 2011-04-08 + Signal.stubs(:trap) app.command_line.stubs(:args).returns %w{foo} app.preinit end |
