diff --git a/spec/lib/puppet_spec/files.rb b/spec/lib/puppet_spec/files.rb index 5608454b9..3f1d7111e 100755 --- a/spec/lib/puppet_spec/files.rb +++ b/spec/lib/puppet_spec/files.rb @@ -1,59 +1,60 @@ require 'fileutils' require 'tempfile' require 'pathname' # 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 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) + def make_absolute(path) PuppetSpec::Files.make_absolute(path) end + def self.make_absolute(path) path = File.expand_path(path) path[0] = 'c' if Puppet.features.microsoft_windows? path end def tmpfile(name) PuppetSpec::Files.tmpfile(name) end def self.tmpfile(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) PuppetSpec::Files.tmpdir(name) end def self.tmpdir(name) path = tmpfile(name) FileUtils.mkdir_p(path) path end end diff --git a/spec/shared_behaviours/file_serving_model.rb b/spec/shared_behaviours/file_serving_model.rb index 4ed6c1977..9c35e2e77 100644 --- a/spec/shared_behaviours/file_serving_model.rb +++ b/spec/shared_behaviours/file_serving_model.rb @@ -1,73 +1,76 @@ #!/usr/bin/env rspec shared_examples_for "a file_serving model" do include PuppetSpec::Files describe "#indirection" do + localpath = PuppetSpec::Files.make_absolute("/etc/sudoers") + localurl = "file://" + localpath + before :each do # Never connect to the network, no matter what described_class.indirection.terminus(:rest).class.any_instance.stubs(:find) end describe "when running the master application" do before :each do Puppet::Application[:master].setup_terminuses end { - "/etc/sudoers" => :file_server, - "file:///etc/sudoers" => :file_server, + localpath => :file_server, + localurl => :file_server, "puppet:///modules/foo/bar" => :file_server, "puppet://server/modules/foo/bar" => :file_server, }.each do |key, terminus| it "should use the #{terminus} terminus when requesting #{key.inspect}" do described_class.indirection.terminus(terminus).class.any_instance.expects(:find) described_class.indirection.find(key) end end end describe "when running the apply application" do before :each do # Stub this so we can set the 'name' setting Puppet::Util::Settings::ReadOnly.stubs(:include?) Puppet[:name] = 'apply' end { - "/etc/sudoers" => :file, - "file:///etc/sudoers" => :file, + localpath => :file, + localurl => :file, "puppet:///modules/foo/bar" => :file_server, "puppet://server/modules/foo/bar" => :rest, }.each do |key, terminus| it "should use the #{terminus} terminus when requesting #{key.inspect}" do described_class.indirection.terminus(terminus).class.any_instance.expects(:find) described_class.indirection.find(key) end end end describe "when running another application" do before :each do # Stub this so we can set the 'name' setting Puppet::Util::Settings::ReadOnly.stubs(:include?) Puppet[:name] = 'agent' end { - "/etc/sudoers" => :file, - "file:///etc/sudoers" => :file, + localpath => :file, + localurl => :file, "puppet:///modules/foo/bar" => :rest, "puppet://server/modules/foo/bar" => :rest, }.each do |key, terminus| it "should use the #{terminus} terminus when requesting #{key.inspect}" do described_class.indirection.terminus(terminus).class.any_instance.expects(:find) described_class.indirection.find(key) end end end end end