From c83ffff9493443845c1545240f75d8136c0ecdff Mon Sep 17 00:00:00 2001 From: Nan Liu Date: Tue, 1 May 2012 16:16:10 -0700 Subject: Add support files for initial release. * Update documentation. * Fix puppet-lint 80 char issues. * Add spec tests. * Add modulefile, changelog, rakefile, and license. --- spec/puppetlabs_spec/files.rb | 57 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 spec/puppetlabs_spec/files.rb (limited to 'spec/puppetlabs_spec/files.rb') 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 -- cgit v1.2.3