diff options
author | Josh Cooper <josh@puppetlabs.com> | 2011-07-18 23:05:35 -0700 |
---|---|---|
committer | Josh Cooper <josh@puppetlabs.com> | 2011-07-19 14:06:36 -0700 |
commit | 462a95e3d077b1915a919399b846068816c84583 (patch) | |
tree | f2e260c6d923d49f20a3d6094796aae36ec240fe | |
parent | 45ae5b4a9ced26dfcd3e324391f9a26cb02bf93d (diff) | |
download | puppet-462a95e3d077b1915a919399b846068816c84583.tar.gz puppet-462a95e3d077b1915a919399b846068816c84583.tar.xz puppet-462a95e3d077b1915a919399b846068816c84583.zip |
Fix tests with "relative" paths on Windows
Absolute paths on Unix, e.g. /foo/bar, are not absolute on Windows,
which breaks many test cases. This commit adds a method to
PuppetSpec::Files.make_absolute that makes the path absolute in
test cases.
On Unix (Puppet.features.posix?) it is a no-op. On Windows,
(Puppet.features.microsoft_windows?) the drive from the current
working directory is prepended.
Reviewed-by: Jacob Helwig <jacob@puppetlabs.com>
41 files changed, 347 insertions, 233 deletions
diff --git a/spec/integration/indirector/direct_file_server_spec.rb b/spec/integration/indirector/direct_file_server_spec.rb index e53b48d69..0dd9c823f 100755 --- a/spec/integration/indirector/direct_file_server_spec.rb +++ b/spec/integration/indirector/direct_file_server_spec.rb @@ -7,12 +7,14 @@ require 'spec_helper' require 'puppet/indirector/file_content/file' -describe Puppet::Indirector::DirectFileServer, " when interacting with the filesystem and the model" do +describe Puppet::Indirector::DirectFileServer, " when interacting with the filesystem and the model", :fails_on_windows => true do + include PuppetSpec::Files + before do # We just test a subclass, since it's close enough. @terminus = Puppet::Indirector::FileContent::File.new - @filepath = "/path/to/my/file" + @filepath = make_absolute("/path/to/my/file") end it "should return an instance of the model" do diff --git a/spec/integration/transaction_spec.rb b/spec/integration/transaction_spec.rb index 00e9dbb8e..b4214214e 100755 --- a/spec/integration/transaction_spec.rb +++ b/spec/integration/transaction_spec.rb @@ -1,9 +1,7 @@ #!/usr/bin/env rspec require 'spec_helper' -require 'puppet_spec/files' require 'puppet/transaction' -require 'puppet_spec/files' describe Puppet::Transaction do include PuppetSpec::Files @@ -20,10 +18,10 @@ describe Puppet::Transaction do it "should not apply generated resources if the parent resource fails" do catalog = Puppet::Resource::Catalog.new - resource = Puppet::Type.type(:file).new :path => "/foo/bar", :backup => false + resource = Puppet::Type.type(:file).new :path => make_absolute("/foo/bar"), :backup => false catalog.add_resource resource - child_resource = Puppet::Type.type(:file).new :path => "/foo/bar/baz", :backup => false + child_resource = Puppet::Type.type(:file).new :path => make_absolute("/foo/bar/baz"), :backup => false resource.expects(:eval_generate).returns([child_resource]) @@ -39,7 +37,7 @@ describe Puppet::Transaction do it "should not apply virtual resources" do catalog = Puppet::Resource::Catalog.new - resource = Puppet::Type.type(:file).new :path => "/foo/bar", :backup => false + resource = Puppet::Type.type(:file).new :path => make_absolute("/foo/bar"), :backup => false resource.virtual = true catalog.add_resource resource @@ -63,7 +61,7 @@ describe Puppet::Transaction do it "should not apply virtual exported resources" do catalog = Puppet::Resource::Catalog.new - resource = Puppet::Type.type(:file).new :path => "/foo/bar", :backup => false + resource = Puppet::Type.type(:file).new :path => make_absolute("/foo/bar"), :backup => false resource.exported = true resource.virtual = true catalog.add_resource resource @@ -91,7 +89,7 @@ describe Puppet::Transaction do it "should not apply host resources on device" do catalog = Puppet::Resource::Catalog.new - resource = Puppet::Type.type(:file).new :path => "/foo/bar", :backup => false + resource = Puppet::Type.type(:file).new :path => make_absolute("/foo/bar"), :backup => false catalog.add_resource resource transaction = Puppet::Transaction.new(catalog) @@ -133,7 +131,7 @@ describe Puppet::Transaction do # Verify that one component requiring another causes the contained # resources in the requiring component to get refreshed. - it "should propagate events from a contained resource through its container to its dependent container's contained resources" do + it "should propagate events from a contained resource through its container to its dependent container's contained resources", :fails_on_windows => true do transaction = nil file = Puppet::Type.type(:file).new :path => tmpfile("event_propagation"), :ensure => :present execfile = File.join(tmpdir("exec_event"), "exectestingness2") @@ -157,7 +155,7 @@ describe Puppet::Transaction do end # Make sure that multiple subscriptions get triggered. - it "should propagate events to all dependent resources" do + it "should propagate events to all dependent resources", :fails_on_windows => true do path = tmpfile("path") file1 = tmpfile("file1") file2 = tmpfile("file2") @@ -187,7 +185,7 @@ describe Puppet::Transaction do FileTest.should be_exist(file2) end - it "should not let one failed refresh result in other refreshes failing" do + it "should not let one failed refresh result in other refreshes failing", :fails_on_windows => true do path = tmpfile("path") newfile = tmpfile("file") file = Puppet::Type.type(:file).new( @@ -220,7 +218,7 @@ describe Puppet::Transaction do FileTest.should be_exists(newfile) end - it "should still trigger skipped resources", :'fails_on_ruby_1.9.2' => true do + it "should still trigger skipped resources", :'fails_on_ruby_1.9.2' => true, :fails_on_windows => true do catalog = mk_catalog catalog.add_resource(*Puppet::Type.type(:schedule).mkdefaultschedules) @@ -272,7 +270,7 @@ describe Puppet::Transaction do FileTest.should be_exists(fname) end - it "should not attempt to evaluate resources with failed dependencies" do + it "should not attempt to evaluate resources with failed dependencies", :fails_on_windows => true do exec = Puppet::Type.type(:exec).new( :command => "/bin/mkdir /this/path/cannot/possibly/exist", @@ -300,7 +298,7 @@ describe Puppet::Transaction do FileTest.should_not be_exists(file2[:path]) end - it "should not trigger subscribing resources on failure" do + it "should not trigger subscribing resources on failure", :fails_on_windows => true do file1 = tmpfile("file1") file2 = tmpfile("file2") diff --git a/spec/integration/type/file_spec.rb b/spec/integration/type/file_spec.rb index 4bed8c6c1..1a328b0b2 100755 --- a/spec/integration/type/file_spec.rb +++ b/spec/integration/type/file_spec.rb @@ -12,7 +12,7 @@ describe Puppet::Type.type(:file) do end it "should not attempt to manage files that do not exist if no means of creating the file is specified" do - file = Puppet::Type.type(:file).new :path => "/my/file", :mode => "755" + file = Puppet::Type.type(:file).new :path => make_absolute("/my/file"), :mode => "755" catalog = Puppet::Resource::Catalog.new catalog.add_resource file @@ -442,7 +442,7 @@ describe Puppet::Type.type(:file) do file = Puppet::Type.type(:file).new( - :name => dest, + :name => make_absolute(dest), :ensure => :absent, :source => source, :backup => false diff --git a/spec/lib/puppet_spec/files.rb b/spec/lib/puppet_spec/files.rb index 30fb4fc42..9e75d3142 100755 --- a/spec/lib/puppet_spec/files.rb +++ b/spec/lib/puppet_spec/files.rb @@ -31,6 +31,16 @@ module PuppetSpec::Files end end + def make_absolute(path) + return path unless Puppet.features.microsoft_windows? + # REMIND UNC + return path if path =~ /^[A-Za-z]:/ + + pwd = Dir.getwd + return "#{pwd[0,2]}#{path}" if pwd.length > 2 and pwd =~ /^[A-Za-z]:/ + return "C:#{path}" + end + def tmpfile(name) # Generate a temporary file, just for the name... source = Tempfile.new(name) diff --git a/spec/unit/application/device_spec.rb b/spec/unit/application/device_spec.rb index 42a62da22..f88c0c3d9 100755 --- a/spec/unit/application/device_spec.rb +++ b/spec/unit/application/device_spec.rb @@ -7,6 +7,8 @@ require 'ostruct' require 'puppet/configurer' describe Puppet::Application::Device do + include PuppetSpec::Files + before :each do @device = Puppet::Application[:device] @device.preinit @@ -264,8 +266,8 @@ describe Puppet::Application::Device do describe "for each device" do before(:each) do - Puppet[:vardir] = "/dummy" - Puppet[:confdir] = "/dummy" + Puppet[:vardir] = make_absolute("/dummy") + Puppet[:confdir] = make_absolute("/dummy") Puppet[:certname] = "certname" @device_hash = { "device1" => OpenStruct.new(:name => "device1", :url => "url", :provider => "cisco"), @@ -281,12 +283,12 @@ describe Puppet::Application::Device do end it "should set vardir to the device vardir" do - Puppet.settings.expects(:set_value).with(:vardir, "/dummy/devices/device1", :cli) + Puppet.settings.expects(:set_value).with(:vardir, make_absolute("/dummy/devices/device1"), :cli) @device.main end it "should set confdir to the device confdir" do - Puppet.settings.expects(:set_value).with(:confdir, "/dummy/devices/device1", :cli) + Puppet.settings.expects(:set_value).with(:confdir, make_absolute("/dummy/devices/device1"), :cli) @device.main end @@ -319,9 +321,9 @@ describe Puppet::Application::Device do [:vardir, :confdir].each do |setting| it "should cleanup the #{setting} setting after the run" do configurer = states('configurer').starts_as('notrun') - Puppet.settings.expects(:set_value).with(setting, "/dummy/devices/device1", :cli).when(configurer.is('notrun')) + Puppet.settings.expects(:set_value).with(setting, make_absolute("/dummy/devices/device1"), :cli).when(configurer.is('notrun')) @configurer.expects(:run).twice.then(configurer.is('run')) - Puppet.settings.expects(:set_value).with(setting, "/dummy", :cli).when(configurer.is('run')) + Puppet.settings.expects(:set_value).with(setting, make_absolute("/dummy"), :cli).when(configurer.is('run')) @device.main end diff --git a/spec/unit/configurer/downloader_spec.rb b/spec/unit/configurer/downloader_spec.rb index 17b285d53..1ffea9b7a 100755 --- a/spec/unit/configurer/downloader_spec.rb +++ b/spec/unit/configurer/downloader_spec.rb @@ -97,14 +97,15 @@ describe Puppet::Configurer::Downloader do describe "when creating the catalog to do the downloading" do before do - @dler = Puppet::Configurer::Downloader.new("foo", "/download/path", "source") + @path = make_absolute("/download/path") + @dler = Puppet::Configurer::Downloader.new("foo", @path, "source") end it "should create a catalog and add the file to it" do catalog = @dler.catalog catalog.resources.size.should == 1 catalog.resources.first.class.should == Puppet::Type::File - catalog.resources.first.name.should == "/download/path" + catalog.resources.first.name.should == @path end it "should specify that it is not managing a host catalog" do diff --git a/spec/unit/file_bucket/dipper_spec.rb b/spec/unit/file_bucket/dipper_spec.rb index 910b2808d..4b4c08c61 100755 --- a/spec/unit/file_bucket/dipper_spec.rb +++ b/spec/unit/file_bucket/dipper_spec.rb @@ -16,7 +16,7 @@ describe Puppet::FileBucket::Dipper do end it "should fail in an informative way when there are failures checking for the file on the server" do - @dipper = Puppet::FileBucket::Dipper.new(:Path => "/my/bucket") + @dipper = Puppet::FileBucket::Dipper.new(:Path => make_absolute("/my/bucket")) file = make_tmp_file('contents') Puppet::FileBucket::File.indirection.expects(:head).raises ArgumentError @@ -25,7 +25,7 @@ describe Puppet::FileBucket::Dipper do end it "should fail in an informative way when there are failures backing up to the server" do - @dipper = Puppet::FileBucket::Dipper.new(:Path => "/my/bucket") + @dipper = Puppet::FileBucket::Dipper.new(:Path => make_absolute("/my/bucket")) file = make_tmp_file('contents') Puppet::FileBucket::File.indirection.expects(:head).returns false diff --git a/spec/unit/file_serving/configuration_spec.rb b/spec/unit/file_serving/configuration_spec.rb index 6ee1a4f38..d76ac9ca8 100755 --- a/spec/unit/file_serving/configuration_spec.rb +++ b/spec/unit/file_serving/configuration_spec.rb @@ -24,9 +24,10 @@ describe Puppet::FileServing::Configuration do end describe Puppet::FileServing::Configuration do + include PuppetSpec::Files before :each do - @path = "/path/to/configuration/file.conf" + @path = make_absolute("/path/to/configuration/file.conf") Puppet.settings.stubs(:value).with(:trace).returns(false) Puppet.settings.stubs(:value).with(:fileserverconfig).returns(@path) end diff --git a/spec/unit/file_serving/fileset_spec.rb b/spec/unit/file_serving/fileset_spec.rb index 41810650a..aff4c91fa 100755 --- a/spec/unit/file_serving/fileset_spec.rb +++ b/spec/unit/file_serving/fileset_spec.rb @@ -4,6 +4,12 @@ require 'spec_helper' require 'puppet/file_serving/fileset' describe Puppet::FileServing::Fileset, " when initializing" do + include PuppetSpec::Files + + before :each do + @somefile = make_absolute("/some/file") + end + it "should require a path" do proc { Puppet::FileServing::Fileset.new }.should raise_error(ArgumentError) end @@ -13,83 +19,82 @@ describe Puppet::FileServing::Fileset, " when initializing" do end it "should not fail if the path is fully qualified, with a trailing separator" do - path = "/some/path/with/trailing/separator" - path_with_separator = "#{path}#{File::SEPARATOR}" - File.stubs(:lstat).with(path).returns stub('stat') + path_with_separator = "#{@somefile}#{File::SEPARATOR}" + File.stubs(:lstat).with(@somefile).returns stub('stat') fileset = Puppet::FileServing::Fileset.new(path_with_separator) - fileset.path.should == path + fileset.path.should == @somefile end it "should not fail if the path is just the file separator" do - path = File::SEPARATOR + path = make_absolute(File::SEPARATOR) File.stubs(:lstat).with(path).returns stub('stat') fileset = Puppet::FileServing::Fileset.new(path) fileset.path.should == path end it "should fail if its path does not exist" do - File.expects(:lstat).with("/some/file").returns nil - proc { Puppet::FileServing::Fileset.new("/some/file") }.should raise_error(ArgumentError) + File.expects(:lstat).with(@somefile).returns nil + proc { Puppet::FileServing::Fileset.new(@somefile) }.should raise_error(ArgumentError) end it "should accept a 'recurse' option" do - File.expects(:lstat).with("/some/file").returns stub("stat") - set = Puppet::FileServing::Fileset.new("/some/file", :recurse => true) + File.expects(:lstat).with(@somefile).returns stub("stat") + set = Puppet::FileServing::Fileset.new(@somefile, :recurse => true) set.recurse.should be_true end it "should accept a 'recurselimit' option" do - File.expects(:lstat).with("/some/file").returns stub("stat") - set = Puppet::FileServing::Fileset.new("/some/file", :recurselimit => 3) + File.expects(:lstat).with(@somefile).returns stub("stat") + set = Puppet::FileServing::Fileset.new(@somefile, :recurselimit => 3) set.recurselimit.should == 3 end it "should accept an 'ignore' option" do - File.expects(:lstat).with("/some/file").returns stub("stat") - set = Puppet::FileServing::Fileset.new("/some/file", :ignore => ".svn") + File.expects(:lstat).with(@somefile).returns stub("stat") + set = Puppet::FileServing::Fileset.new(@somefile, :ignore => ".svn") set.ignore.should == [".svn"] end it "should accept a 'links' option" do - File.expects(:lstat).with("/some/file").returns stub("stat") - set = Puppet::FileServing::Fileset.new("/some/file", :links => :manage) + File.expects(:lstat).with(@somefile).returns stub("stat") + set = Puppet::FileServing::Fileset.new(@somefile, :links => :manage) set.links.should == :manage end it "should accept a 'checksum_type' option" do - File.expects(:lstat).with("/some/file").returns stub("stat") - set = Puppet::FileServing::Fileset.new("/some/file", :checksum_type => :test) + File.expects(:lstat).with(@somefile).returns stub("stat") + set = Puppet::FileServing::Fileset.new(@somefile, :checksum_type => :test) set.checksum_type.should == :test end it "should fail if 'links' is set to anything other than :manage or :follow" do - proc { Puppet::FileServing::Fileset.new("/some/file", :links => :whatever) }.should raise_error(ArgumentError) + proc { Puppet::FileServing::Fileset.new(@somefile, :links => :whatever) }.should raise_error(ArgumentError) end it "should default to 'false' for recurse" do - File.expects(:lstat).with("/some/file").returns stub("stat") - Puppet::FileServing::Fileset.new("/some/file").recurse.should == false + File.expects(:lstat).with(@somefile).returns stub("stat") + Puppet::FileServing::Fileset.new(@somefile).recurse.should == false end it "should default to :infinite for recurselimit" do - File.expects(:lstat).with("/some/file").returns stub("stat") - Puppet::FileServing::Fileset.new("/some/file").recurselimit.should == :infinite + File.expects(:lstat).with(@somefile).returns stub("stat") + Puppet::FileServing::Fileset.new(@somefile).recurselimit.should == :infinite end it "should default to an empty ignore list" do - File.expects(:lstat).with("/some/file").returns stub("stat") - Puppet::FileServing::Fileset.new("/some/file").ignore.should == [] + File.expects(:lstat).with(@somefile).returns stub("stat") + Puppet::FileServing::Fileset.new(@somefile).ignore.should == [] end it "should default to :manage for links" do - File.expects(:lstat).with("/some/file").returns stub("stat") - Puppet::FileServing::Fileset.new("/some/file").links.should == :manage + File.expects(:lstat).with(@somefile).returns stub("stat") + Puppet::FileServing::Fileset.new(@somefile).links.should == :manage end it "should support using an Indirector Request for its options" do - File.expects(:lstat).with("/some/file").returns stub("stat") + File.expects(:lstat).with(@somefile).returns stub("stat") request = Puppet::Indirector::Request.new(:file_serving, :find, "foo") - lambda { Puppet::FileServing::Fileset.new("/some/file", request) }.should_not raise_error + lambda { Puppet::FileServing::Fileset.new(@somefile, request) }.should_not raise_error end describe "using an indirector request" do @@ -97,40 +102,43 @@ describe Puppet::FileServing::Fileset, " when initializing" do File.stubs(:lstat).returns stub("stat") @values = {:links => :manage, :ignore => %w{a b}, :recurse => true, :recurselimit => 1234} @request = Puppet::Indirector::Request.new(:file_serving, :find, "foo") + @myfile = make_absolute("/my/file") end [:recurse, :recurselimit, :ignore, :links].each do |option| it "should pass :recurse, :recurselimit, :ignore, and :links settings on to the fileset if present" do @request.stubs(:options).returns(option => @values[option]) - Puppet::FileServing::Fileset.new("/my/file", @request).send(option).should == @values[option] + Puppet::FileServing::Fileset.new(@myfile, @request).send(option).should == @values[option] end it "should pass :recurse, :recurselimit, :ignore, and :links settings on to the fileset if present with the keys stored as strings" do @request.stubs(:options).returns(option.to_s => @values[option]) - Puppet::FileServing::Fileset.new("/my/file", @request).send(option).should == @values[option] + Puppet::FileServing::Fileset.new(@myfile, @request).send(option).should == @values[option] end end it "should convert the integer as a string to their integer counterpart when setting options" do @request.stubs(:options).returns(:recurselimit => "1234") - Puppet::FileServing::Fileset.new("/my/file", @request).recurselimit.should == 1234 + Puppet::FileServing::Fileset.new(@myfile, @request).recurselimit.should == 1234 end it "should convert the string 'true' to the boolean true when setting options" do @request.stubs(:options).returns(:recurse => "true") - Puppet::FileServing::Fileset.new("/my/file", @request).recurse.should == true + Puppet::FileServing::Fileset.new(@myfile, @request).recurse.should == true end it "should convert the string 'false' to the boolean false when setting options" do @request.stubs(:options).returns(:recurse => "false") - Puppet::FileServing::Fileset.new("/my/file", @request).recurse.should == false + Puppet::FileServing::Fileset.new(@myfile, @request).recurse.should == false end end end describe Puppet::FileServing::Fileset, " when determining whether to recurse" do + include PuppetSpec::Files + before do - @path = "/my/path" + @path = make_absolute("/my/path") File.expects(:lstat).with(@path).returns stub("stat") @fileset = Puppet::FileServing::Fileset.new(@path) end @@ -166,8 +174,10 @@ describe Puppet::FileServing::Fileset, " when determining whether to recurse" do end describe Puppet::FileServing::Fileset, " when recursing" do + include PuppetSpec::Files + before do - @path = "/my/path" + @path = make_absolute("/my/path") File.expects(:lstat).with(@path).returns stub("stat", :directory? => true) @fileset = Puppet::FileServing::Fileset.new(@path) @@ -257,7 +267,7 @@ describe Puppet::FileServing::Fileset, " when recursing" do end it "should succeed when paths have regexp significant characters" do - @path = "/my/path/rV1x2DafFr0R6tGG+1bbk++++TM" + @path = make_absolute("/my/path/rV1x2DafFr0R6tGG+1bbk++++TM") File.expects(:lstat).with(@path).returns stub("stat", :directory? => true) @fileset = Puppet::FileServing::Fileset.new(@path) mock_dir_structure(@path) @@ -267,8 +277,10 @@ describe Puppet::FileServing::Fileset, " when recursing" do end describe Puppet::FileServing::Fileset, " when following links that point to missing files" do + include PuppetSpec::Files + before do - @path = "/my/path" + @path = make_absolute("/my/path") File.expects(:lstat).with(@path).returns stub("stat", :directory? => true) @fileset = Puppet::FileServing::Fileset.new(@path) @fileset.links = :follow @@ -291,8 +303,10 @@ describe Puppet::FileServing::Fileset, " when following links that point to miss end describe Puppet::FileServing::Fileset, " when ignoring" do + include PuppetSpec::Files + before do - @path = "/my/path" + @path = make_absolute("/my/path") File.expects(:lstat).with(@path).returns stub("stat", :directory? => true) @fileset = Puppet::FileServing::Fileset.new(@path) end @@ -318,8 +332,10 @@ describe Puppet::FileServing::Fileset, " when ignoring" do end describe Puppet::FileServing::Fileset, "when merging other filesets" do + include PuppetSpec::Files + before do - @paths = %w{/first/path /second/path /third/path} + @paths = [make_absolute("/first/path"), make_absolute("/second/path"), make_absolute("/third/path")] File.stubs(:lstat).returns stub("stat", :directory? => false) @filesets = @paths.collect do |path| @@ -331,32 +347,32 @@ describe Puppet::FileServing::Fileset, "when merging other filesets" do end it "should return a hash of all files in each fileset with the value being the base path" do - Dir.expects(:entries).with("/first/path").returns(%w{one uno}) - Dir.expects(:entries).with("/second/path").returns(%w{two dos}) - Dir.expects(:entries).with("/third/path").returns(%w{three tres}) + Dir.expects(:entries).with(make_absolute("/first/path")).returns(%w{one uno}) + Dir.expects(:entries).with(make_absolute("/second/path")).returns(%w{two dos}) + Dir.expects(:entries).with(make_absolute("/third/path")).returns(%w{three tres}) Puppet::FileServing::Fileset.merge(*@filesets).should == { - "." => "/first/path", - "one" => "/first/path", - "uno" => "/first/path", - "two" => "/second/path", - "dos" => "/second/path", - "three" => "/third/path", - "tres" => "/third/path", + "." => make_absolute("/first/path"), + "one" => make_absolute("/first/path"), + "uno" => make_absolute("/first/path"), + "two" => make_absolute("/second/path"), + "dos" => make_absolute("/second/path"), + "three" => make_absolute("/third/path"), + "tres" => make_absolute("/third/path"), } end it "should include the base directory from the first fileset" do - Dir.expects(:entries).with("/first/path").returns(%w{one}) - Dir.expects(:entries).with("/second/path").returns(%w{two}) + Dir.expects(:entries).with(make_absolute("/first/path")).returns(%w{one}) + Dir.expects(:entries).with(make_absolute("/second/path")).returns(%w{two}) - Puppet::FileServing::Fileset.merge(*@filesets)["."].should == "/first/path" + Puppet::FileServing::Fileset.merge(*@filesets)["."].should == make_absolute("/first/path") end it "should use the base path of the first found file when relative file paths conflict" do - Dir.expects(:entries).with("/first/path").returns(%w{one}) - Dir.expects(:entries).with("/second/path").returns(%w{one}) + Dir.expects(:entries).with(make_absolute("/first/path")).returns(%w{one}) + Dir.expects(:entries).with(make_absolute("/second/path")).returns(%w{one}) - Puppet::FileServing::Fileset.merge(*@filesets)["one"].should == "/first/path" + Puppet::FileServing::Fileset.merge(*@filesets)["one"].should == make_absolute("/first/path") end end diff --git a/spec/unit/indirector/file_bucket_file/file_spec.rb b/spec/unit/indirector/file_bucket_file/file_spec.rb index e0612cb21..eb86eee85 100755 --- a/spec/unit/indirector/file_bucket_file/file_spec.rb +++ b/spec/unit/indirector/file_bucket_file/file_spec.rb @@ -243,11 +243,11 @@ HERE describe "when verifying identical files" do before do # this is the default from spec_helper, but it keeps getting reset at odd times - Puppet[:bucketdir] = "/dev/null/bucket" + Puppet[:bucketdir] = make_absolute("/dev/null/bucket") @digest = "4a8ec4fa5f01b4ab1a0ab8cbccb709f0" @checksum = "{md5}4a8ec4fa5f01b4ab1a0ab8cbccb709f0" - @dir = '/dev/null/bucket/4/a/8/e/c/4/f/a/4a8ec4fa5f01b4ab1a0ab8cbccb709f0' + @dir = make_absolute('/dev/null/bucket/4/a/8/e/c/4/f/a/4a8ec4fa5f01b4ab1a0ab8cbccb709f0') @contents = "file contents" diff --git a/spec/unit/indirector/ssl_file_spec.rb b/spec/unit/indirector/ssl_file_spec.rb index 5d0859598..1a837f646 100755 --- a/spec/unit/indirector/ssl_file_spec.rb +++ b/spec/unit/indirector/ssl_file_spec.rb @@ -8,6 +8,8 @@ require 'spec_helper' require 'puppet/indirector/ssl_file' describe Puppet::Indirector::SslFile do + include PuppetSpec::Files + before :all do @indirection = stub 'indirection', :name => :testing, :model => @model Puppet::Indirector::Indirection.expects(:instance).with(:testing).returns(@indirection) @@ -21,7 +23,7 @@ describe Puppet::Indirector::SslFile do @setting = :certdir @file_class.store_in @setting - @path = "/tmp/my_directory" + @path = make_absolute("/tmp/my_directory") Puppet[:noop] = false Puppet[@setting] = @path Puppet[:trace] = false diff --git a/spec/unit/node/environment_spec.rb b/spec/unit/node/environment_spec.rb index d1badfa3a..144e82e0c 100755 --- a/spec/unit/node/environment_spec.rb +++ b/spec/unit/node/environment_spec.rb @@ -144,13 +144,18 @@ describe Puppet::Node::Environment do end describe "when validating modulepath or manifestdir directories" do + before :each do + @path_one = make_absolute('/one') + @path_two = make_absolute('/two') + end + it "should not return non-directories" do env = Puppet::Node::Environment.new("testing") - FileTest.expects(:directory?).with("/one").returns true - FileTest.expects(:directory?).with("/two").returns false + FileTest.expects(:directory?).with(@path_one).returns true + FileTest.expects(:directory?).with(@path_two).returns false - env.validate_dirs(%w{/one /two}).should == %w{/one} + env.validate_dirs([@path_one, @path_two]).should == [@path_one] end it "should use the current working directory to fully-qualify unqualified paths" do @@ -158,7 +163,7 @@ describe Puppet::Node::Environment do env = Puppet::Node::Environment.new("testing") two = File.join(Dir.getwd, "two") - env.validate_dirs(%w{/one two}).should == ["/one", two] + env.validate_dirs([@path_one, 'two']).should == [@path_one, two] end end diff --git a/spec/unit/other/selinux_spec.rb b/spec/unit/other/selinux_spec.rb index 216feaf1f..f20951868 100755 --- a/spec/unit/other/selinux_spec.rb +++ b/spec/unit/other/selinux_spec.rb @@ -5,11 +5,13 @@ require 'puppet/type/selboolean' require 'puppet/type/selmodule' describe Puppet::Type.type(:file), " when manipulating file contexts" do + include PuppetSpec::Files + before :each do @file = Puppet::Type::File.new( - :name => "/tmp/foo", + :name => make_absolute("/tmp/foo"), :ensure => "file", :seluser => "user_u", :selrole => "role_r", diff --git a/spec/unit/parser/compiler_spec.rb b/spec/unit/parser/compiler_spec.rb index e6f481114..411d1b862 100755 --- a/spec/unit/parser/compiler_spec.rb +++ b/spec/unit/parser/compiler_spec.rb @@ -43,6 +43,8 @@ class CompilerTestResource end describe Puppet::Parser::Compiler do + include PuppetSpec::Files + def resource(type, title) Puppet::Parser::Resource.new(type, title, :scope => @scope) end @@ -413,7 +415,7 @@ describe Puppet::Parser::Compiler do end it "should fail to add resources that conflict with existing resources" do - path = Puppet.features.posix? ? "/foo" : "C:/foo" + path = make_absolute("/foo") file1 = Puppet::Type.type(:file).new :path => path file2 = Puppet::Type.type(:file).new :path => path diff --git a/spec/unit/parser/files_spec.rb b/spec/unit/parser/files_spec.rb index 04777f0ec..1bf75e623 100755 --- a/spec/unit/parser/files_spec.rb +++ b/spec/unit/parser/files_spec.rb @@ -4,9 +4,10 @@ require 'spec_helper' require 'puppet/parser/files' describe Puppet::Parser::Files do + include PuppetSpec::Files before do - @basepath = Puppet.features.posix? ? "/somepath" : "C:/somepath" + @basepath = make_absolute("/somepath") end it "should have a method for finding a template" do @@ -77,8 +78,9 @@ describe Puppet::Parser::Files do it "should accept relative templatedirs" do FileTest.stubs(:exist?).returns true Puppet[:templatedir] = "my/templates" - File.expects(:directory?).with(File.join(Dir.getwd,"my/templates")).returns(true) - Puppet::Parser::Files.find_template("mytemplate").should == File.join(Dir.getwd,"my/templates/mytemplate") + # We expand_path to normalize backslashes and slashes on Windows + File.expects(:directory?).with(File.expand_path(File.join(Dir.getwd,"my/templates"))).returns(true) + Puppet::Parser::Files.find_template("mytemplate").should == File.expand_path(File.join(Dir.getwd,"my/templates/mytemplate")) end it "should use the environment templatedir if no module is found and an environment is specified" do @@ -158,7 +160,8 @@ describe Puppet::Parser::Files do end it "should look for files relative to the current directory" do - cwd = Dir.getwd + # We expand_path to normalize backslashes and slashes on Windows + cwd = File.expand_path(Dir.getwd) Dir.expects(:glob).with("#{cwd}/foobar/init.pp").returns(["#{cwd}/foobar/init.pp"]) Puppet::Parser::Files.find_manifests("foobar/init.pp")[1].should == ["#{cwd}/foobar/init.pp"] end diff --git a/spec/unit/parser/functions/extlookup_spec.rb b/spec/unit/parser/functions/extlookup_spec.rb index 30962e137..59ecf39c0 100755 --- a/spec/unit/parser/functions/extlookup_spec.rb +++ b/spec/unit/parser/functions/extlookup_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' require 'tempfile' describe "the extlookup function" do + include PuppetSpec::Files + before :all do Puppet::Parser::Functions.autoloader.loadall end @@ -64,9 +66,10 @@ describe "the extlookup function" do describe "should look in $extlookup_datadir for data files listed by $extlookup_precedence" do before do - @scope.stubs(:[]).with('::extlookup_datadir').returns("/tmp") - File.open("/tmp/one.csv","w"){|one| one.puts "key,value1" } - File.open("/tmp/two.csv","w") do |two| + dir = tmpdir('extlookup_datadir') + @scope.stubs(:[]).with('::extlookup_datadir').returns(dir) + File.open(File.join(dir, "one.csv"),"w"){|one| one.puts "key,value1" } + File.open(File.join(dir, "two.csv"),"w") do |two| two.puts "key,value2" two.puts "key2,value_two" end diff --git a/spec/unit/parser/type_loader_spec.rb b/spec/unit/parser/type_loader_spec.rb index 58caeda05..fd991ffc4 100755 --- a/spec/unit/parser/type_loader_spec.rb +++ b/spec/unit/parser/type_loader_spec.rb @@ -56,8 +56,8 @@ describe Puppet::Parser::TypeLoader do end it "should use the directory of the current file if one is set" do - Puppet::Parser::Files.expects(:find_manifests).with { |pat, opts| opts[:cwd] == "/current" }.returns ["modname", %w{one}] - @loader.import("myfile", "/current/file") + Puppet::Parser::Files.expects(:find_manifests).with { |pat, opts| opts[:cwd] == make_absolute("/current") }.returns ["modname", %w{one}] + @loader.import("myfile", make_absolute("/current/file")) end it "should pass the environment when looking for files" do @@ -71,15 +71,15 @@ describe Puppet::Parser::TypeLoader do end it "should parse each found file" do - Puppet::Parser::Files.expects(:find_manifests).returns ["modname", %w{/one}] - @loader.expects(:parse_file).with("/one").returns(Puppet::Parser::AST::Hostclass.new('')) + Puppet::Parser::Files.expects(:find_manifests).returns ["modname", make_absolute("/one")] + @loader.expects(:parse_file).with(make_absolute("/one")).returns(Puppet::Parser::AST::Hostclass.new('')) @loader.import("myfile") end it "should make each file qualified before attempting to parse it" do Puppet::Parser::Files.expects(:find_manifests).returns ["modname", %w{one}] - @loader.expects(:parse_file).with("/current/one").returns(Puppet::Parser::AST::Hostclass.new('')) - @loader.import("myfile", "/current/file") + @loader.expects(:parse_file).with(make_absolute("/current/one")).returns(Puppet::Parser::AST::Hostclass.new('')) + @loader.import("myfile", make_absolute("/current/file")) end it "should not attempt to import files that have already been imported" do diff --git a/spec/unit/resource/catalog_spec.rb b/spec/unit/resource/catalog_spec.rb index 8f4910af6..35b2fea4b 100755 --- a/spec/unit/resource/catalog_spec.rb +++ b/spec/unit/resource/catalog_spec.rb @@ -2,9 +2,10 @@ require 'spec_helper' describe Puppet::Resource::Catalog, "when compiling" do + include PuppetSpec::Files before do - @basepath = Puppet.features.posix? ? "/somepath" : "C:/somepath" + @basepath = make_absolute("/somepath") # stub this to not try to create state.yaml Puppet::Util::Storage.stubs(:store) end diff --git a/spec/unit/resource/status_spec.rb b/spec/unit/resource/status_spec.rb index e5a9291db..18e3359df 100755 --- a/spec/unit/resource/status_spec.rb +++ b/spec/unit/resource/status_spec.rb @@ -4,14 +4,16 @@ require 'spec_helper' require 'puppet/resource/status' describe Puppet::Resource::Status do + include PuppetSpec::Files + before do - @resource = Puppet::Type.type(:file).new :path => "/my/file" + @resource = Puppet::Type.type(:file).new :path => make_absolute("/my/file") @status = Puppet::Resource::Status.new(@resource) end it "should compute type and title correctly" do @status.resource_type.should == "File" - @status.title.should == "/my/file" + @status.title.should == make_absolute("/my/file") end [:node, :file, :line, :current_values, :status, :evaluation_time].each do |attr| diff --git a/spec/unit/resource_spec.rb b/spec/unit/resource_spec.rb index 0485bc7aa..093532119 100755 --- a/spec/unit/resource_spec.rb +++ b/spec/unit/resource_spec.rb @@ -3,9 +3,10 @@ require 'spec_helper' require 'puppet/resource' describe Puppet::Resource do + include PuppetSpec::Files before do - @basepath = Puppet.features.posix? ? "/somepath" : "C:/somepath" + @basepath = make_absolute("/somepath") end [:catalog, :file, :line].each do |attr| diff --git a/spec/unit/transaction/event_manager_spec.rb b/spec/unit/transaction/event_manager_spec.rb index d127d0391..37775997d 100755 --- a/spec/unit/transaction/event_manager_spec.rb +++ b/spec/unit/transaction/event_manager_spec.rb @@ -4,6 +4,8 @@ require 'spec_helper' require 'puppet/transaction/event_manager' describe Puppet::Transaction::EventManager do + include PuppetSpec::Files + describe "at initialization" do it "should require a transaction" do Puppet::Transaction::EventManager.new("trans").transaction.should == "trans" @@ -23,7 +25,7 @@ describe Puppet::Transaction::EventManager do before do @manager = Puppet::Transaction::EventManager.new(@transaction) - @resource = Puppet::Type.type(:file).new :path => "/my/file" + @resource = Puppet::Type.type(:file).new :path => make_absolute("/my/file") @graph = stub 'graph', :matching_edges => [], :resource => @resource @manager.stubs(:relationship_graph).returns @graph @@ -139,7 +141,7 @@ describe Puppet::Transaction::EventManager do @manager = Puppet::Transaction::EventManager.new(@transaction) @manager.stubs(:queue_events) - @resource = Puppet::Type.type(:file).new :path => "/my/file" + @resource = Puppet::Type.type(:file).new :path => make_absolute("/my/file") @event = Puppet::Transaction::Event.new(:name => :event, :resource => @resource) end diff --git a/spec/unit/transaction/event_spec.rb b/spec/unit/transaction/event_spec.rb index 0093baeb9..5f7f367b4 100755 --- a/spec/unit/transaction/event_spec.rb +++ b/spec/unit/transaction/event_spec.rb @@ -4,6 +4,8 @@ require 'spec_helper' require 'puppet/transaction/event' describe Puppet::Transaction::Event do + include PuppetSpec::Files + [:previous_value, :desired_value, :property, :resource, :name, :message, :file, :line, :tags, :audited].each do |attr| it "should support #{attr}", :'fails_on_ruby_1.9.2' => true do event = Puppet::Transaction::Event.new @@ -113,7 +115,7 @@ describe Puppet::Transaction::Event do describe "When converting to YAML" do it "should include only documented attributes" do - resource = Puppet::Type.type(:file).new(:title => "/tmp/foo") + resource = Puppet::Type.type(:file).new(:title => make_absolute("/tmp/foo")) event = Puppet::Transaction::Event.new(:source_description => "/my/param", :resource => resource, :file => "/foo.rb", :line => 27, :tags => %w{one two}, :desired_value => 7, :historical_value => 'Brazil', diff --git a/spec/unit/transaction/report_spec.rb b/spec/unit/transaction/report_spec.rb index 4b04cc157..08b892f21 100755 --- a/spec/unit/transaction/report_spec.rb +++ b/spec/unit/transaction/report_spec.rb @@ -154,7 +154,7 @@ describe Puppet::Transaction::Report do def add_statuses(count, type = :file) count.times do |i| - status = Puppet::Resource::Status.new(Puppet::Type.type(type).new(:title => "/my/path#{i}")) + status = Puppet::Resource::Status.new(Puppet::Type.type(type).new(:title => make_absolute("/my/path#{i}"))) yield status if block_given? @report.add_resource_status status end diff --git a/spec/unit/transaction/resource_harness_spec.rb b/spec/unit/transaction/resource_harness_spec.rb index a594d3669..cadc31a0f 100755 --- a/spec/unit/transaction/resource_harness_spec.rb +++ b/spec/unit/transaction/resource_harness_spec.rb @@ -9,7 +9,7 @@ describe Puppet::Transaction::ResourceHarness do before do @mode_750 = Puppet.features.microsoft_windows? ? '644' : '750' @mode_755 = Puppet.features.microsoft_windows? ? '644' : '755' - path = Puppet.features.microsoft_windows? ? "c:/my/file" : "/my/file" + path = make_absolute("/my/file") @transaction = Puppet::Transaction.new(Puppet::Resource::Catalog.new) @resource = Puppet::Type.type(:file).new :path => path diff --git a/spec/unit/transaction_spec.rb b/spec/unit/transaction_spec.rb index 3829cfaf5..3f34f65bd 100755 --- a/spec/unit/transaction_spec.rb +++ b/spec/unit/transaction_spec.rb @@ -11,8 +11,10 @@ def without_warnings end describe Puppet::Transaction do + include PuppetSpec::Files + before do - @basepath = Puppet.features.posix? ? "/what/ever" : "C:/tmp" + @basepath = make_absolute("/what/ever") @transaction = Puppet::Transaction.new(Puppet::Resource::Catalog.new) end diff --git a/spec/unit/type/exec_spec.rb b/spec/unit/type/exec_spec.rb index 47d1b8523..175e307f9 100755 --- a/spec/unit/type/exec_spec.rb +++ b/spec/unit/type/exec_spec.rb @@ -2,6 +2,8 @@ require 'spec_helper' describe Puppet::Type.type(:exec) do + include PuppetSpec::Files + def exec_tester(command, exitstatus = 0, rest = {}) @user_name = 'some_user_name' @group_name = 'some_group_name' @@ -30,12 +32,13 @@ describe Puppet::Type.type(:exec) do end before do - @command = Puppet.features.posix? ? '/bin/true whatever' : '"C:/Program Files/something.exe" whatever' + @command = make_absolute('/bin/true whatever') + @executable = make_absolute('/bin/true') + @bogus_cmd = make_absolute('/bogus/cmd') end - describe "when not stubbing the provider" do + describe "when not stubbing the provider", :fails_on_windows => true do before do - @executable = Puppet.features.posix? ? '/bin/true' : 'C:/Program Files/something.exe' File.stubs(:exists?).returns false File.stubs(:exists?).with(@executable).returns true File.stubs(:exists?).with('/bin/false').returns true @@ -139,17 +142,18 @@ describe Puppet::Type.type(:exec) do end end - it "should be able to autorequire files mentioned in the command" do + it "should be able to autorequire files mentioned in the command", :fails_on_windows => true do + foo = make_absolute('/bin/foo') catalog = Puppet::Resource::Catalog.new - tmp = Puppet::Type.type(:file).new(:name => "/bin/foo") + tmp = Puppet::Type.type(:file).new(:name => foo) catalog.add_resource tmp - execer = Puppet::Type.type(:exec).new(:name => "/bin/foo") + execer = Puppet::Type.type(:exec).new(:name => foo) catalog.add_resource execer catalog.relationship_graph.dependencies(execer).should == [tmp] end - describe "when handling the path parameter" do + describe "when handling the path parameter", :fails_on_windows => true do expect = %w{one two three four} { "an array" => expect, "a colon separated list" => "one:two:three:four", @@ -205,7 +209,7 @@ describe Puppet::Type.type(:exec) do describe "when setting cwd" do it_should_behave_like "all path parameters", :cwd, :array => false do def instance(path) - Puppet::Type.type(:exec).new(:name => '/bin/true', :cwd => path) + Puppet::Type.type(:exec).new(:name => @executable, :cwd => path) end end end @@ -221,7 +225,7 @@ describe Puppet::Type.type(:exec) do if @param == :name then instance = Puppet::Type.type(:exec).new() else - instance = Puppet::Type.type(:exec).new(:name => "/bin/true") + instance = Puppet::Type.type(:exec).new(:name => @executable) end if valid then instance.provider.expects(:validatecmd).returns(true) @@ -246,7 +250,7 @@ describe Puppet::Type.type(:exec) do shared_examples_for "all exec command parameters that take arrays" do |param| describe "when given an array of inputs" do before :each do - @test = Puppet::Type.type(:exec).new(:name => "/bin/true") + @test = Puppet::Type.type(:exec).new(:name => @executable) end it "should accept the array when all commands return valid" do @@ -281,7 +285,7 @@ describe Puppet::Type.type(:exec) do describe "for simple parameters" do before :each do - @exec = Puppet::Type.type(:exec).new(:name => '/bin/true') + @exec = Puppet::Type.type(:exec).new(:name => @executable) end describe "when setting environment" do @@ -338,13 +342,15 @@ describe Puppet::Type.type(:exec) do end it "should convert timeout to a float" do - resource = Puppet::Type.type(:exec).new :command => "/bin/false", :timeout => "12" + command = make_absolute('/bin/false') + resource = Puppet::Type.type(:exec).new :command => command, :timeout => "12" resource[:timeout].should be_a(Float) resource[:timeout].should == 12.0 end it "should munge negative timeouts to 0.0" do - resource = Puppet::Type.type(:exec).new :command => "/bin/false", :timeout => "-12.0" + command = make_absolute('/bin/false') + resource = Puppet::Type.type(:exec).new :command => command, :timeout => "-12.0" resource.parameter(:timeout).value.should be_a(Float) resource.parameter(:timeout).value.should == 0.0 end @@ -442,7 +448,7 @@ describe Puppet::Type.type(:exec) do describe "when setting creates" do it_should_behave_like "all path parameters", :creates, :array => true do def instance(path) - Puppet::Type.type(:exec).new(:name => '/bin/true', :creates => path) + Puppet::Type.type(:exec).new(:name => @executable, :creates => path) end end end @@ -460,7 +466,7 @@ describe Puppet::Type.type(:exec) do describe "#check" do before :each do - @test = Puppet::Type.type(:exec).new(:name => "/bin/true") + @test = Puppet::Type.type(:exec).new(:name => @executable) end describe ":refreshonly" do @@ -525,8 +531,8 @@ describe Puppet::Type.type(:exec) do }.each do |param, sense| describe ":#{param}" do before :each do - @pass = "/magic/pass" - @fail = "/magic/fail" + @pass = make_absolute("/magic/pass") + @fail = make_absolute("/magic/fail") @pass_status = stub('status', :exitstatus => sense[:pass] ? 0 : 1) @fail_status = stub('status', :exitstatus => sense[:fail] ? 0 : 1) @@ -584,9 +590,9 @@ describe Puppet::Type.type(:exec) do end end - describe "#retrieve" do + describe "#retrieve", :fails_on_windows => true do before :each do - @exec_resource = Puppet::Type.type(:exec).new(:name => "/bogus/cmd") + @exec_resource = Puppet::Type.type(:exec).new(:name => @bogus_cmd) end it "should return :notrun when check_all_attributes returns true" do @@ -608,7 +614,7 @@ describe Puppet::Type.type(:exec) do describe "#output" do before :each do - @exec_resource = Puppet::Type.type(:exec).new(:name => "/bogus/cmd") + @exec_resource = Puppet::Type.type(:exec).new(:name => @bogus_cmd) end it "should return the provider's run output" do @@ -625,14 +631,15 @@ describe Puppet::Type.type(:exec) do describe "#refresh" do before :each do - @exec_resource = Puppet::Type.type(:exec).new(:name => "/bogus/cmd") + @exec_resource = Puppet::Type.type(:exec).new(:name => @bogus_cmd) end it "should call provider run with the refresh parameter if it is set" do + myother_bogus_cmd = make_absolute('/myother/bogus/cmd') provider = stub 'provider' @exec_resource.stubs(:provider).returns(provider) - @exec_resource.stubs(:[]).with(:refresh).returns('/myother/bogus/cmd') - provider.expects(:run).with('/myother/bogus/cmd') + @exec_resource.stubs(:[]).with(:refresh).returns(myother_bogus_cmd) + provider.expects(:run).with(myother_bogus_cmd) @exec_resource.refresh end @@ -641,7 +648,7 @@ describe Puppet::Type.type(:exec) do provider = stub 'provider' status = stubs "process_status" status.stubs(:exitstatus).returns("0") - provider.expects(:run).with('/bogus/cmd').returns(["silly output", status]) + provider.expects(:run).with(@bogus_cmd).returns(["silly output", status]) @exec_resource.stubs(:provider).returns(provider) @exec_resource.refresh diff --git a/spec/unit/type/file/checksum_spec.rb b/spec/unit/type/file/checksum_spec.rb index b47f617cc..30c4aba6d 100755 --- a/spec/unit/type/file/checksum_spec.rb +++ b/spec/unit/type/file/checksum_spec.rb @@ -4,7 +4,8 @@ require 'spec_helper' checksum = Puppet::Type.type(:file).attrclass(:checksum) describe checksum do before do - @resource = Puppet::Type.type(:file).new :path => "/foo/bar" + @path = Puppet.features.microsoft_windows? ? "c:/foo/bar" : "/foo/bar" + @resource = Puppet::Type.type(:file).new :path => @path @checksum = @resource.parameter(:checksum) end @@ -35,25 +36,25 @@ describe checksum do it "should use its current value when asked to sum a file's content" do @checksum.value = :md5lite - @checksum.expects(:md5lite_file).with("/foo/bar").returns "yay" - @checksum.sum_file("/foo/bar") + @checksum.expects(:md5lite_file).with(@path).returns "yay" + @checksum.sum_file(@path) end it "should use :md5 to sum a file when no value is set" do - @checksum.expects(:md5_file).with("/foo/bar").returns "yay" - @checksum.sum_file("/foo/bar") + @checksum.expects(:md5_file).with(@path).returns "yay" + @checksum.sum_file(@path) end it "should convert all sums to strings when summing files" do @checksum.value = :mtime - @checksum.expects(:mtime_file).with("/foo/bar").returns Time.now - lambda { @checksum.sum_file("/foo/bar") }.should_not raise_error + @checksum.expects(:mtime_file).with(@path).returns Time.now + lambda { @checksum.sum_file(@path) }.should_not raise_error end it "should return the summed contents of a file with a checksum label" do @resource[:checksum] = :md5 @checksum.expects(:md5_file).returns "mysum" - @checksum.sum_file("/foo/bar").should == "{md5}mysum" + @checksum.sum_file(@path).should == "{md5}mysum" end it "should return the summed contents of a stream with a checksum label" do diff --git a/spec/unit/type/file/selinux_spec.rb b/spec/unit/type/file/selinux_spec.rb index 2622948d0..f6e7451c7 100755 --- a/spec/unit/type/file/selinux_spec.rb +++ b/spec/unit/type/file/selinux_spec.rb @@ -1,12 +1,14 @@ #!/usr/bin/env rspec require 'spec_helper' - [:seluser, :selrole, :seltype, :selrange].each do |param| property = Puppet::Type.type(:file).attrclass(param) describe property do + include PuppetSpec::Files + before do - @resource = Puppet::Type.type(:file).new :path => "/my/file" + @path = make_absolute("/my/file") + @resource = Puppet::Type.type(:file).new :path => @path @sel = property.new :resource => @resource end @@ -18,14 +20,14 @@ require 'spec_helper' it "should retrieve nil for #{param} if there is no SELinux support" do stat = stub 'stat', :ftype => "foo" @resource.expects(:stat).returns stat - @sel.expects(:get_selinux_current_context).with("/my/file").returns nil + @sel.expects(:get_selinux_current_context).with(@path).returns nil @sel.retrieve.should be_nil end it "should retrieve #{param} if a SELinux context is found with a range" do stat = stub 'stat', :ftype => "foo" @resource.expects(:stat).returns stat - @sel.expects(:get_selinux_current_context).with("/my/file").returns "user_u:role_r:type_t:s0" + @sel.expects(:get_selinux_current_context).with(@path).returns "user_u:role_r:type_t:s0" expectedresult = case param when :seluser; "user_u" when :selrole; "role_r" @@ -38,7 +40,7 @@ require 'spec_helper' it "should retrieve #{param} if a SELinux context is found without a range" do stat = stub 'stat', :ftype => "foo" @resource.expects(:stat).returns stat - @sel.expects(:get_selinux_current_context).with("/my/file").returns "user_u:role_r:type_t" + @sel.expects(:get_selinux_current_context).with(@path).returns "user_u:role_r:type_t" expectedresult = case param when :seluser; "user_u" when :selrole; "role_r" @@ -49,13 +51,13 @@ require 'spec_helper' end it "should handle no default gracefully" do - @sel.expects(:get_selinux_default_context).with("/my/file").returns nil + @sel.expects(:get_selinux_default_context).with(@path).returns nil @sel.default.must be_nil end it "should be able to detect matchpathcon defaults" do @sel.stubs(:debug) - @sel.expects(:get_selinux_default_context).with("/my/file").returns "user_u:role_r:type_t:s0" + @sel.expects(:get_selinux_default_context).with(@path).returns "user_u:role_r:type_t:s0" expectedresult = case param when :seluser; "user_u" when :selrole; "role_r" @@ -73,7 +75,7 @@ require 'spec_helper' it "should be able to set a new context" do stat = stub 'stat', :ftype => "foo" @sel.should = %w{newone} - @sel.expects(:set_selinux_context).with("/my/file", ["newone"], param) + @sel.expects(:set_selinux_context).with(@path, ["newone"], param) @sel.sync end diff --git a/spec/unit/type/file/source_spec.rb b/spec/unit/type/file/source_spec.rb index 5665d323d..efa7c13e6 100755 --- a/spec/unit/type/file/source_spec.rb +++ b/spec/unit/type/file/source_spec.rb @@ -3,9 +3,13 @@ require 'spec_helper' source = Puppet::Type.type(:file).attrclass(:source) describe Puppet::Type.type(:file).attrclass(:source) do + include PuppetSpec::Files + before do # Wow that's a messy interface to the resource. @resource = stub 'resource', :[]= => nil, :property => nil, :catalog => stub("catalog", :dependent_data_expired? => false), :line => 0, :file => '' + @foobar = make_absolute("/foo/bar") + @feebooz = make_absolute("/fee/booz") end it "should be a subclass of Parameter" do @@ -52,39 +56,39 @@ describe Puppet::Type.type(:file).attrclass(:source) do end it "should collect its metadata using the Metadata class if it is not already set" do - @source = source.new(:resource => @resource, :value => "/foo/bar") - Puppet::FileServing::Metadata.indirection.expects(:find).with("/foo/bar").returns @metadata + @source = source.new(:resource => @resource, :value => @foobar) + Puppet::FileServing::Metadata.indirection.expects(:find).with(@foobar).returns @metadata @source.metadata end it "should use the metadata from the first found source" do metadata = stub 'metadata', :source= => nil - @source = source.new(:resource => @resource, :value => ["/foo/bar", "/fee/booz"]) - Puppet::FileServing::Metadata.indirection.expects(:find).with("/foo/bar").returns nil - Puppet::FileServing::Metadata.indirection.expects(:find).with("/fee/booz").returns metadata + @source = source.new(:resource => @resource, :value => [@foobar, @feebooz]) + Puppet::FileServing::Metadata.indirection.expects(:find).with(@foobar).returns nil + Puppet::FileServing::Metadata.indirection.expects(:find).with(@feebooz).returns metadata @source.metadata.should equal(metadata) end it "should store the found source as the metadata's source" do metadata = mock 'metadata' - @source = source.new(:resource => @resource, :value => "/foo/bar") - Puppet::FileServing::Metadata.indirection.expects(:find).with("/foo/bar").returns metadata + @source = source.new(:resource => @resource, :value => @foobar) + Puppet::FileServing::Metadata.indirection.expects(:find).with(@foobar).returns metadata - metadata.expects(:source=).with("/foo/bar") + metadata.expects(:source=).with(@foobar) @source.metadata end it "should fail intelligently if an exception is encountered while querying for metadata" do - @source = source.new(:resource => @resource, :value => "/foo/bar") - Puppet::FileServing::Metadata.indirection.expects(:find).with("/foo/bar").raises RuntimeError + @source = source.new(:resource => @resource, :value => @foobar) + Puppet::FileServing::Metadata.indirection.expects(:find).with(@foobar).raises RuntimeError @source.expects(:fail).raises ArgumentError lambda { @source.metadata }.should raise_error(ArgumentError) end it "should fail if no specified sources can be found" do - @source = source.new(:resource => @resource, :value => "/foo/bar") - Puppet::FileServing::Metadata.indirection.expects(:find).with("/foo/bar").returns nil + @source = source.new(:resource => @resource, :value => @foobar) + Puppet::FileServing::Metadata.indirection.expects(:find).with(@foobar).returns nil @source.expects(:fail).raises RuntimeError @@ -95,9 +99,9 @@ describe Puppet::Type.type(:file).attrclass(:source) do expirer = stub 'expired', :dependent_data_expired? => true metadata = stub 'metadata', :source= => nil - Puppet::FileServing::Metadata.indirection.expects(:find).with("/fee/booz").returns metadata + Puppet::FileServing::Metadata.indirection.expects(:find).with(@feebooz).returns metadata - @source = source.new(:resource => @resource, :value => ["/fee/booz"]) + @source = source.new(:resource => @resource, :value => [@feebooz]) @source.metadata = "foo" @source.stubs(:expirer).returns expirer @@ -113,7 +117,7 @@ describe Puppet::Type.type(:file).attrclass(:source) do describe "when copying the source values" do before do - @resource = Puppet::Type.type(:file).new :path => "/foo/bar" + @resource = Puppet::Type.type(:file).new :path => @foobar @source = source.new(:resource => @resource) @metadata = stub 'metadata', :owner => 100, :group => 200, :mode => 123, :checksum => "{md5}asdfasdf", :ftype => "file" diff --git a/spec/unit/type/noop_metaparam_spec.rb b/spec/unit/type/noop_metaparam_spec.rb index f4241d417..7083dd037 100755 --- a/spec/unit/type/noop_metaparam_spec.rb +++ b/spec/unit/type/noop_metaparam_spec.rb @@ -4,9 +4,11 @@ require 'spec_helper' require 'puppet/type' describe Puppet::Type.type(:file).attrclass(:noop) do + include PuppetSpec::Files + before do Puppet.settings.stubs(:use) - @file = Puppet::Type.newfile :path => "/what/ever" + @file = Puppet::Type.newfile :path => make_absolute("/what/ever") end it "should accept true as a value" do diff --git a/spec/unit/type/ssh_authorized_key_spec.rb b/spec/unit/type/ssh_authorized_key_spec.rb index 71b8a9ab0..9b3760b71 100755 --- a/spec/unit/type/ssh_authorized_key_spec.rb +++ b/spec/unit/type/ssh_authorized_key_spec.rb @@ -4,6 +4,8 @@ require 'spec_helper' ssh_authorized_key = Puppet::Type.type(:ssh_authorized_key) describe ssh_authorized_key do + include PuppetSpec::Files + before do @class = Puppet::Type.type(:ssh_authorized_key) @@ -11,7 +13,7 @@ describe ssh_authorized_key do @class.stubs(:defaultprovider).returns(@provider_class) @class.stubs(:provider).returns(@provider_class) - @provider = stub 'provider', :class => @provider_class, :file_path => "/tmp/whatever", :clear => nil + @provider = stub 'provider', :class => @provider_class, :file_path => make_absolute("/tmp/whatever"), :clear => nil @provider_class.stubs(:new).returns(@provider) @catalog = Puppet::Resource::Catalog.new end @@ -180,7 +182,7 @@ describe ssh_authorized_key do proc { @class.new(:name => "whev", :type => :rsa, :target => "/tmp/here") }.should_not raise_error end - it "should use the user's path if not explicitly specified" do + it "should use the user's path if not explicitly specified", :fails_on_windows => true do @class.new(:name => "whev", :user => 'root').should(:target).should == File.expand_path("~root/.ssh/authorized_keys") end @@ -226,7 +228,7 @@ describe ssh_authorized_key do end - describe "when user is specified" do + describe "when user is specified", :fails_on_windows => true do it "should determine target" do resource = @class.create( diff --git a/spec/unit/type/tidy_spec.rb b/spec/unit/type/tidy_spec.rb index cb030634b..bf892e836 100755 --- a/spec/unit/type/tidy_spec.rb +++ b/spec/unit/type/tidy_spec.rb @@ -5,8 +5,10 @@ require 'puppet/file_bucket/dipper' tidy = Puppet::Type.type(:tidy) describe tidy do + include PuppetSpec::Files + before do - @basepath = Puppet.features.posix? ? "/what/ever" : "C:/tmp" + @basepath = make_absolute("/what/ever") Puppet.settings.stubs(:use) # for an unknown reason some of these specs fails when run individually diff --git a/spec/unit/type_spec.rb b/spec/unit/type_spec.rb index bbdaec3bc..73150af48 100755 --- a/spec/unit/type_spec.rb +++ b/spec/unit/type_spec.rb @@ -1,7 +1,9 @@ #!/usr/bin/env rspec require 'spec_helper' -describe Puppet::Type do +describe Puppet::Type, :'fails_on_windows' => true do + include PuppetSpec::Files + it "should include the Cacher module" do Puppet::Type.ancestors.should be_include(Puppet::Util::Cacher) end @@ -309,7 +311,8 @@ describe Puppet::Type do end it "should use the Resource Type's namevar to determine how to find the name in the hash" do - Puppet::Type.type(:file).new(:path => "/yay").title.should == "/yay" + yay = make_absolute('/yay') + Puppet::Type.type(:file).new(:path => yay).title.should == yay end [:catalog].each do |param| @@ -387,7 +390,7 @@ describe Puppet::Type do end it "should delete the name via the namevar from the originally provided parameters" do - Puppet::Type.type(:file).new(:name => "/foo").original_parameters[:path].should be_nil + Puppet::Type.type(:file).new(:name => make_absolute('/foo')).original_parameters[:path].should be_nil end end @@ -471,7 +474,7 @@ describe Puppet::Type do end it "should provide a value for 'ensure' even if no desired value is provided" do - @resource = Puppet::Type.type(:file).new(:path => "/my/file/that/can't/exist") + @resource = Puppet::Type.type(:file).new(:path => make_absolute("/my/file/that/can't/exist")) end it "should not call retrieve on non-ensure properties if the resource is absent and should consider the property absent" do @@ -513,8 +516,8 @@ describe Puppet::Type do before do @catalog = Puppet::Resource::Catalog.new @container = Puppet::Type.type(:component).new(:name => "container") - @one = Puppet::Type.type(:file).new(:path => "/file/one") - @two = Puppet::Type.type(:file).new(:path => "/file/two") + @one = Puppet::Type.type(:file).new(:path => make_absolute("/file/one")) + @two = Puppet::Type.type(:file).new(:path => make_absolute("/file/two")) @catalog.add_resource @container @catalog.add_resource @one @@ -541,7 +544,9 @@ describe Puppet::Type do end end -describe Puppet::Type::RelationshipMetaparam do +describe Puppet::Type::RelationshipMetaparam, :fails_on_windows => true do + include PuppetSpec::Files + it "should be a subclass of Puppet::Parameter" do Puppet::Type::RelationshipMetaparam.superclass.should equal(Puppet::Parameter) end @@ -550,14 +555,15 @@ describe Puppet::Type::RelationshipMetaparam do Puppet::Type::RelationshipMetaparam.should respond_to(:subclasses) end - describe "when munging relationships" do + describe "when munging relationships", :'fails_on_windows' => true do before do - @resource = Puppet::Type.type(:mount).new :name => "/foo" + @path = make_absolute('/foo') + @resource = Puppet::Type.type(:mount).new :name => @path @metaparam = Puppet::Type.metaparamclass(:require).new :resource => @resource end it "should accept Puppet::Resource instances" do - ref = Puppet::Resource.new(:file, "/foo") + ref = Puppet::Resource.new(:file, @path) @metaparam.munge(ref)[0].should equal(ref) end @@ -585,18 +591,22 @@ describe Puppet::Type::RelationshipMetaparam do end end -describe Puppet::Type.metaparamclass(:check) do +describe Puppet::Type.metaparamclass(:check), :fails_on_windows => true do + include PuppetSpec::Files + it "should warn and create an instance of ':audit'" do - file = Puppet::Type.type(:file).new :path => "/foo" + file = Puppet::Type.type(:file).new :path => make_absolute('/foo') file.expects(:warning) file[:check] = :mode file[:audit].should == [:mode] end end -describe Puppet::Type.metaparamclass(:audit) do +describe Puppet::Type.metaparamclass(:audit), :fails_on_windows => true do + include PuppetSpec::Files + before do - @resource = Puppet::Type.type(:file).new :path => "/foo" + @resource = Puppet::Type.type(:file).new :path => make_absolute('/foo') end it "should default to being nil" do @@ -642,8 +652,9 @@ describe Puppet::Type.metaparamclass(:audit) do Puppet::Type.type(:file).stubs(:title_patterns).returns( [ [ /(.*)/, [ [:path, lambda{|x| x} ] ] ] ] ) - res = Puppet::Type.type(:file).new( :title => '/my/file', :path => '/my/file', :owner => 'root', :content => 'hello' ) - res.uniqueness_key.should == [ nil, 'root', '/my/file'] + myfile = make_absolute('/my/file') + res = Puppet::Type.type(:file).new( :title => myfile, :path => myfile, :owner => 'root', :content => 'hello' ) + res.uniqueness_key.should == [ nil, 'root', myfile] end end end diff --git a/spec/unit/util/autoload_spec.rb b/spec/unit/util/autoload_spec.rb index d61b7689e..100975f27 100755 --- a/spec/unit/util/autoload_spec.rb +++ b/spec/unit/util/autoload_spec.rb @@ -4,6 +4,8 @@ require 'spec_helper' require 'puppet/util/autoload' describe Puppet::Util::Autoload do + include PuppetSpec::Files + before do @autoload = Puppet::Util::Autoload.new("foo", "tmp") @@ -15,32 +17,38 @@ describe Puppet::Util::Autoload do end describe "when building the search path" do + before :each do + @dira = make_absolute('/a') + @dirb = make_absolute('/b') + @dirc = make_absolute('/c') + end + it "should collect all of the plugins and lib directories that exist in the current environment's module path" do Puppet.settings.expects(:value).with(:environment).returns "foo" - Puppet.settings.expects(:value).with(:modulepath, :foo).returns "/a:/b:/c" - Dir.expects(:entries).with("/a").returns %w{one two} - Dir.expects(:entries).with("/b").returns %w{one two} + Puppet.settings.expects(:value).with(:modulepath, :foo).returns "#{@dira}#{File::PATH_SEPARATOR}#{@dirb}#{File::PATH_SEPARATOR}#{@dirc}" + Dir.expects(:entries).with(@dira).returns %w{one two} + Dir.expects(:entries).with(@dirb).returns %w{one two} FileTest.stubs(:directory?).returns false - FileTest.expects(:directory?).with("/a").returns true - FileTest.expects(:directory?).with("/b").returns true - %w{/a/one/plugins /a/two/lib /b/one/plugins /b/two/lib}.each do |d| + FileTest.expects(:directory?).with(@dira).returns true + FileTest.expects(:directory?).with(@dirb).returns true + ["#{@dira}/one/plugins", "#{@dira}/two/lib", "#{@dirb}/one/plugins", "#{@dirb}/two/lib"].each do |d| FileTest.expects(:directory?).with(d).returns true end - @autoload.module_directories.should == %w{/a/one/plugins /a/two/lib /b/one/plugins /b/two/lib} + @autoload.module_directories.should == ["#{@dira}/one/plugins", "#{@dira}/two/lib", "#{@dirb}/one/plugins", "#{@dirb}/two/lib"] end it "should not look for lib directories in directories starting with '.'" do Puppet.settings.expects(:value).with(:environment).returns "foo" - Puppet.settings.expects(:value).with(:modulepath, :foo).returns "/a" - Dir.expects(:entries).with("/a").returns %w{. ..} - - FileTest.expects(:directory?).with("/a").returns true - FileTest.expects(:directory?).with("/a/./lib").never - FileTest.expects(:directory?).with("/a/./plugins").never - FileTest.expects(:directory?).with("/a/../lib").never - FileTest.expects(:directory?).with("/a/../plugins").never + Puppet.settings.expects(:value).with(:modulepath, :foo).returns @dira + Dir.expects(:entries).with(@dira).returns %w{. ..} + + FileTest.expects(:directory?).with(@dira).returns true + FileTest.expects(:directory?).with("#{@dira}/./lib").never + FileTest.expects(:directory?).with("#{@dira}/./plugins").never + FileTest.expects(:directory?).with("#{@dira}/../lib").never + FileTest.expects(:directory?).with("#{@dira}/../plugins").never @autoload.module_directories end diff --git a/spec/unit/util/backups_spec.rb b/spec/unit/util/backups_spec.rb index 611c19304..d2f36a6e6 100755 --- a/spec/unit/util/backups_spec.rb +++ b/spec/unit/util/backups_spec.rb @@ -4,28 +4,31 @@ require 'spec_helper' require 'puppet/util/backups' describe Puppet::Util::Backups do + include PuppetSpec::Files + before do FileTest.stubs(:exists?).returns true + @nosuchfile = make_absolute('/no/such/file') end describe "when backing up a file" do it "should noop if the file does not exist" do FileTest.expects(:exists?).returns false - file = Puppet::Type.type(:file).new(:name => '/no/such/file') + file = Puppet::Type.type(:file).new(:name => @nosuchfile) file.expects(:bucket).never file.perform_backup end it "should succeed silently if self[:backup] is false" do - file = Puppet::Type.type(:file).new(:name => '/no/such/file', :backup => false) + file = Puppet::Type.type(:file).new(:name => @nosuchfile, :backup => false) file.expects(:bucket).never FileTest.expects(:exists?).never file.perform_backup end it "a bucket should be used when provided" do - path = '/my/file' + path = make_absolute('/my/file') File.stubs(:stat).with(path).returns(mock('stat', :ftype => 'file')) @@ -39,7 +42,7 @@ describe Puppet::Util::Backups do end it "should propagate any exceptions encountered when backing up to a filebucket" do - path = '/my/file' + path = make_absolute('/my/file') File.stubs(:stat).with(path).returns(mock('stat', :ftype => 'file')) @@ -54,7 +57,7 @@ describe Puppet::Util::Backups do describe "and no filebucket is configured" do it "should remove any local backup if one exists" do - path = '/my/file' + path = make_absolute('/my/file') FileTest.stubs(:exists?).returns true backup = path + ".foo" @@ -69,7 +72,7 @@ describe Puppet::Util::Backups do end it "should fail when the old backup can't be removed" do - path = '/my/file' + path = make_absolute('/my/file') FileTest.stubs(:exists?).returns true backup = path + ".foo" @@ -84,7 +87,7 @@ describe Puppet::Util::Backups do end it "should not try to remove backups that don't exist" do - path = '/my/file' + path = make_absolute('/my/file') FileTest.stubs(:exists?).returns true backup = path + ".foo" @@ -99,7 +102,7 @@ describe Puppet::Util::Backups do end it "a copy should be created in the local directory" do - path = '/my/file' + path = make_absolute('/my/file') FileTest.stubs(:exists?).with(path).returns true FileUtils.expects(:cp_r).with(path, path + ".foo", :preserve => true) @@ -109,7 +112,7 @@ describe Puppet::Util::Backups do end it "should propagate exceptions if no backup can be created" do - path = '/my/file' + path = make_absolute('/my/file') FileTest.stubs(:exists?).with(path).returns true FileUtils.expects(:cp_r).raises ArgumentError @@ -122,13 +125,13 @@ describe Puppet::Util::Backups do describe "when backing up a directory" do it "a bucket should work when provided" do - path = '/my/dir' + path = make_absolute('/my/dir') File.stubs(:file?).returns true - Find.expects(:find).with(path).yields("/my/dir/file") + Find.expects(:find).with(path).yields(make_absolute("/my/dir/file")) bucket = stub('bucket', :name => "eh") - bucket.expects(:backup).with("/my/dir/file").returns true + bucket.expects(:backup).with(make_absolute("/my/dir/file")).returns true file = Puppet::Type.type(:file).new(:name => path, :backup => 'foo') file.stubs(:bucket).returns bucket @@ -139,7 +142,7 @@ describe Puppet::Util::Backups do end it "should do nothing when recursing" do - path = '/my/dir' + path = make_absolute('/my/dir') bucket = stub('bucket', :name => "eh") bucket.expects(:backup).never diff --git a/spec/unit/util/log_spec.rb b/spec/unit/util/log_spec.rb index 1baa0d5af..39da4b010 100755 --- a/spec/unit/util/log_spec.rb +++ b/spec/unit/util/log_spec.rb @@ -4,6 +4,8 @@ require 'spec_helper' require 'puppet/util/log' describe Puppet::Util::Log do + include PuppetSpec::Files + it "should write a given message to the specified destination" do arraydest = [] Puppet::Util::Log.newdestination(Puppet::Test::LogCollector.new(arraydest)) @@ -167,7 +169,7 @@ describe Puppet::Util::Log do describe "when setting the source as a RAL object" do it "should tag itself with any tags the source has" do - source = Puppet::Type.type(:file).new :path => "/foo/bar" + source = Puppet::Type.type(:file).new :path => make_absolute("/foo/bar") log = Puppet::Util::Log.new(:level => "notice", :message => :foo, :source => source) source.tags.each do |tag| log.tags.should be_include(tag) @@ -188,7 +190,7 @@ describe Puppet::Util::Log do end it "should copy over any file and line information" do - source = Puppet::Type.type(:file).new :path => "/foo/bar" + source = Puppet::Type.type(:file).new :path => make_absolute("/foo/bar") source.file = "/my/file" source.line = 50 log = Puppet::Util::Log.new(:level => "notice", :message => :foo, :source => source) diff --git a/spec/unit/util/network_device/config_spec.rb b/spec/unit/util/network_device/config_spec.rb index d69358a92..d9bd3d979 100755 --- a/spec/unit/util/network_device/config_spec.rb +++ b/spec/unit/util/network_device/config_spec.rb @@ -4,9 +4,11 @@ require 'spec_helper' require 'puppet/util/network_device/config' describe Puppet::Util::NetworkDevice::Config do + include PuppetSpec::Files + before(:each) do - Puppet[:deviceconfig] = "/dummy" - FileTest.stubs(:exists?).with("/dummy").returns(true) + Puppet[:deviceconfig] = make_absolute("/dummy") + FileTest.stubs(:exists?).with(make_absolute("/dummy")).returns(true) end describe "when initializing" do @@ -15,7 +17,7 @@ describe Puppet::Util::NetworkDevice::Config do end it "should use the deviceconfig setting as pathname" do - Puppet.expects(:[]).with(:deviceconfig).returns("/dummy") + Puppet.expects(:[]).with(:deviceconfig).returns(make_absolute("/dummy")) Puppet::Util::NetworkDevice::Config.new end diff --git a/spec/unit/util/rdoc/parser_spec.rb b/spec/unit/util/rdoc/parser_spec.rb index 92b50e09b..4c2c79e88 100755 --- a/spec/unit/util/rdoc/parser_spec.rb +++ b/spec/unit/util/rdoc/parser_spec.rb @@ -8,6 +8,8 @@ require 'rdoc/options' require 'rdoc/rdoc' describe RDoc::Parser, :'fails_on_ruby_1.9.2' => true do + include PuppetSpec::Files + before :each do File.stubs(:stat).with("init.pp") @top_level = stub_everything 'toplevel', :file_relative_name => "init.pp" @@ -21,7 +23,7 @@ describe RDoc::Parser, :'fails_on_ruby_1.9.2' => true do Puppet::Parser::Parser.stubs(:new).returns(parser) parser.expects(:parse).returns(Puppet::Parser::AST::Hostclass.new('')).at_least_once parser.expects(:file=).with("module/manifests/init.pp") - parser.expects(:file=).with("/dev/null/manifests/site.pp") + parser.expects(:file=).with(make_absolute("/dev/null/manifests/site.pp")) @parser.scan end diff --git a/spec/unit/util/settings/file_setting_spec.rb b/spec/unit/util/settings/file_setting_spec.rb index 489628a78..01d891f08 100755 --- a/spec/unit/util/settings/file_setting_spec.rb +++ b/spec/unit/util/settings/file_setting_spec.rb @@ -7,8 +7,10 @@ require 'puppet/util/settings/file_setting' describe Puppet::Util::Settings::FileSetting do FileSetting = Puppet::Util::Settings::FileSetting + include PuppetSpec::Files + before do - @basepath = Puppet.features.posix? ? "/somepath" : "C:/somepath" + @basepath = make_absolute("/somepath") end describe "when determining whether the service user should be used" do @@ -165,7 +167,10 @@ describe Puppet::Util::Settings::FileSetting do it "should fully qualified returned files if necessary (#795)" do @settings.stubs(:value).with(:mydir).returns "myfile" - @file.to_resource.title.should == File.join(Dir.getwd, "myfile") + path = File.join(Dir.getwd, "myfile") + # Dir.getwd can return windows paths with backslashes, so we normalize them using expand_path + path = File.expand_path(path) if Puppet.features.microsoft_windows? + @file.to_resource.title.should == path end it "should set the mode on the file if a mode is provided" do diff --git a/spec/unit/util/settings_spec.rb b/spec/unit/util/settings_spec.rb index aa50c8f3a..efe2be443 100755 --- a/spec/unit/util/settings_spec.rb +++ b/spec/unit/util/settings_spec.rb @@ -2,6 +2,8 @@ require 'spec_helper' describe Puppet::Util::Settings do + include PuppetSpec::Files + describe "when specifying defaults" do before do @settings = Puppet::Util::Settings.new @@ -377,7 +379,7 @@ describe Puppet::Util::Settings do end it "should use its current ':config' value for the file to parse" do - myfile = Puppet.features.posix? ? "/my/file" : "C:/myfile" # do not stub expand_path here, as this leads to a stack overflow, when mocha tries to use it + myfile = make_absolute("/my/file") # do not stub expand_path here, as this leads to a stack overflow, when mocha tries to use it @settings[:config] = myfile File.expects(:read).with(myfile).returns "[main]" @@ -444,25 +446,27 @@ describe Puppet::Util::Settings do it "should support specifying all metadata (owner, group, mode) in the configuration file" do @settings.setdefaults :section, :myfile => ["/myfile", "a"] + otherfile = make_absolute("/other/file") text = "[main] - myfile = /other/file {owner = service, group = service, mode = 644} + myfile = #{otherfile} {owner = service, group = service, mode = 644} " @settings.expects(:read_file).returns(text) @settings.parse - @settings[:myfile].should == "/other/file" + @settings[:myfile].should == otherfile @settings.metadata(:myfile).should == {:owner => "suser", :group => "sgroup", :mode => "644"} end it "should support specifying a single piece of metadata (owner, group, or mode) in the configuration file" do @settings.setdefaults :section, :myfile => ["/myfile", "a"] + otherfile = make_absolute("/other/file") text = "[main] - myfile = /other/file {owner = service} + myfile = #{otherfile} {owner = service} " file = "/some/file" @settings.expects(:read_file).returns(text) @settings.parse - @settings[:myfile].should == "/other/file" + @settings[:myfile].should == otherfile @settings.metadata(:myfile).should == {:owner => "suser"} end diff --git a/spec/unit/util/storage_spec.rb b/spec/unit/util/storage_spec.rb index 90c11aa69..575ad1ef3 100755 --- a/spec/unit/util/storage_spec.rb +++ b/spec/unit/util/storage_spec.rb @@ -8,7 +8,7 @@ describe Puppet::Util::Storage do include PuppetSpec::Files before(:all) do - @basepath = Puppet.features.posix? ? "/somepath" : "C:/somepath" + @basepath = make_absolute("/somepath") Puppet[:statedir] = tmpdir("statedir") end |