diff options
author | Nan Liu <nan@puppetlabs.com> | 2012-05-01 16:16:10 -0700 |
---|---|---|
committer | Nan Liu <nan@puppetlabs.com> | 2012-05-01 16:16:10 -0700 |
commit | c83ffff9493443845c1545240f75d8136c0ecdff (patch) | |
tree | 2a4f1450709f3559bf2b6cad95c7efe04011161b /spec/puppetlabs_spec/files.rb | |
parent | df6c470fd39e6e4e92968d414ae9021b4ec67205 (diff) | |
download | puppet-tftp-c83ffff9493443845c1545240f75d8136c0ecdff.tar.gz puppet-tftp-c83ffff9493443845c1545240f75d8136c0ecdff.tar.bz2 |
Add support files for initial release.
* Update documentation.
* Fix puppet-lint 80 char issues.
* Add spec tests.
* Add modulefile, changelog, rakefile, and license.
Diffstat (limited to 'spec/puppetlabs_spec/files.rb')
-rw-r--r-- | spec/puppetlabs_spec/files.rb | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/spec/puppetlabs_spec/files.rb b/spec/puppetlabs_spec/files.rb new file mode 100644 index 0000000..d64cb3f --- /dev/null +++ b/spec/puppetlabs_spec/files.rb @@ -0,0 +1,57 @@ +require 'fileutils' +require 'tempfile' +require 'pathname' + +# A support module for testing files. +module PuppetlabsSpec::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 + def self.in_tmp(path) + tempdir = Dir.tmpdir + + Pathname.new(path).ascend do |dir| + return true if File.identical?(tempdir, dir) + end + + false + end + + def self.cleanup + $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 + end + end + + def make_absolute(path) + path = File.expand_path(path) + path[0] = 'c' if Puppet.features.microsoft_windows? + path + end + + def tmpfilename(name) + # Generate a temporary file, just for the name... + source = Tempfile.new(name) + path = source.path + source.close! + + # ...record it for cleanup, + $global_tempfiles ||= [] + $global_tempfiles << File.expand_path(path) + + # ...and bam. + path + end + + def tmpdir(name) + path = tmpfilename(name) + FileUtils.mkdir_p(path) + path + end +end |