diff options
| author | David Schmitt <david@dasz.at> | 2010-05-17 16:11:20 +0200 |
|---|---|---|
| committer | test branch <puppet-dev@googlegroups.com> | 2010-02-17 06:50:53 -0800 |
| commit | f054d5b6abe2de3810203b13c8f263d9a23f0d50 (patch) | |
| tree | 19a76a255946261c40a2d9b64b9096d73dd83d9c | |
| parent | 54c453853ddb1648af14b42dca6f827c5cb8e007 (diff) | |
| download | puppet-f054d5b6abe2de3810203b13c8f263d9a23f0d50.tar.gz puppet-f054d5b6abe2de3810203b13c8f263d9a23f0d50.tar.xz puppet-f054d5b6abe2de3810203b13c8f263d9a23f0d50.zip | |
Make specs work on win32
lib/:
* Fix Puppet::Parser::Files
* Fix Puppet::Util::Settings
spec/:
* unit/application/kick.rb: only run on posix
* unit/application.rb
* unit/parser/compiler.rb
* unit/parser/files.rb
* unit/resource.rb
* unit/resource/catalog.rb
* unit/resource/type_collection.rb
* unit/transaction.rb
* unit/type/tidy.rb
* unit/util/settings.rb
* unit/util/settings/file_setting.rb
* unit/application.rb
| -rw-r--r-- | lib/puppet/parser/files.rb | 6 | ||||
| -rw-r--r-- | lib/puppet/util/settings.rb | 2 | ||||
| -rwxr-xr-x | spec/unit/application.rb | 27 | ||||
| -rwxr-xr-x | spec/unit/application/kick.rb | 3 | ||||
| -rwxr-xr-x | spec/unit/parser/compiler.rb | 5 | ||||
| -rw-r--r-- | spec/unit/parser/files.rb | 19 | ||||
| -rwxr-xr-x | spec/unit/resource.rb | 23 | ||||
| -rwxr-xr-x | spec/unit/resource/catalog.rb | 33 | ||||
| -rw-r--r-- | spec/unit/resource/type_collection.rb | 2 | ||||
| -rwxr-xr-x | spec/unit/transaction.rb | 7 | ||||
| -rwxr-xr-x | spec/unit/type/tidy.rb | 115 | ||||
| -rwxr-xr-x | spec/unit/util/settings.rb | 32 | ||||
| -rwxr-xr-x | spec/unit/util/settings/file_setting.rb | 22 |
13 files changed, 171 insertions, 125 deletions
diff --git a/lib/puppet/parser/files.rb b/lib/puppet/parser/files.rb index 3442e11a6..1ff5552a0 100644 --- a/lib/puppet/parser/files.rb +++ b/lib/puppet/parser/files.rb @@ -38,7 +38,7 @@ module Puppet::Parser::Files # In all cases, an absolute path is returned, which does not # necessarily refer to an existing file def find_template(template, environment = nil) - if template =~ /^#{File::SEPARATOR}/ + if template == File.expand_path(template) return template end @@ -76,7 +76,7 @@ module Puppet::Parser::Files # Return an array of paths by splitting the +templatedir+ config # parameter. def templatepath(environment = nil) - dirs = Puppet.settings.value(:templatedir, environment).split(":") + dirs = Puppet.settings.value(:templatedir, environment).split(File::PATH_SEPARATOR) dirs.select do |p| File::directory?(p) end @@ -86,7 +86,7 @@ module Puppet::Parser::Files # nil if the path is empty or absolute (starts with a /). # This method can return nil & anyone calling it needs to handle that. def split_file_path(path) - path.split(File::SEPARATOR, 2) unless path =~ /^(#{File::SEPARATOR}|$)/ + path.split(File::SEPARATOR, 2) unless path == "" or path == File.expand_path(path) end end diff --git a/lib/puppet/util/settings.rb b/lib/puppet/util/settings.rb index 82d2d4533..b2d1f4a1f 100644 --- a/lib/puppet/util/settings.rb +++ b/lib/puppet/util/settings.rb @@ -387,7 +387,7 @@ class Puppet::Util::Settings case hash[:default] when true, false, "true", "false" klass = BooleanSetting - when /^\$\w+\//, /^\// + when /^\$\w+\//, /^\//, /^\w:\// klass = FileSetting when String, Integer, Float # nothing klass = Setting diff --git a/spec/unit/application.rb b/spec/unit/application.rb index daaed0c9a..9dc655d14 100755 --- a/spec/unit/application.rb +++ b/spec/unit/application.rb @@ -10,6 +10,9 @@ describe Puppet::Application do before do @app = Class.new(Puppet::Application).new + + # avoid actually trying to parse any settings + Puppet.settings.stubs(:parse) end it "should have a run entry-point" do @@ -145,17 +148,21 @@ describe Puppet::Application do end end - it 'should signal process with HUP after block if restart requested during block execution' do - Puppet::Application.run_status = nil - target = mock 'target' - target.expects(:some_method).once - old_handler = trap('HUP') { target.some_method } - begin - Puppet::Application.controlled_run do - Puppet::Application.run_status = :restart_requested + describe 'on POSIX systems' do + confine "HUP works only on POSIX systems" => Puppet.features.posix? + + it 'should signal process with HUP after block if restart requested during block execution' do + Puppet::Application.run_status = nil + target = mock 'target' + target.expects(:some_method).once + old_handler = trap('HUP') { target.some_method } + begin + Puppet::Application.controlled_run do + Puppet::Application.run_status = :restart_requested + end + ensure + trap('HUP', old_handler) end - ensure - trap('HUP', old_handler) end end diff --git a/spec/unit/application/kick.rb b/spec/unit/application/kick.rb index c1b780651..58e71b2a4 100755 --- a/spec/unit/application/kick.rb +++ b/spec/unit/application/kick.rb @@ -6,6 +6,9 @@ require 'puppet/util/ldap/connection' require 'puppet/application/kick' describe Puppet::Application::Kick do + + confine "Kick's eventloops can only start on POSIX" => Puppet.features.posix? + before :each do Puppet::Util::Ldap::Connection.stubs(:new).returns(stub_everything) @kick = Puppet::Application[:kick] diff --git a/spec/unit/parser/compiler.rb b/spec/unit/parser/compiler.rb index fb210bc02..fa65479b3 100755 --- a/spec/unit/parser/compiler.rb +++ b/spec/unit/parser/compiler.rb @@ -388,8 +388,9 @@ describe Puppet::Parser::Compiler do end it "should fail to add resources that conflict with existing resources" do - file1 = Puppet::Type.type(:file).new :path => "/foo" - file2 = Puppet::Type.type(:file).new :path => "/foo" + path = Puppet.features.posix? ? "/foo" : "C:/foo" + file1 = Puppet::Type.type(:file).new :path => path + file2 = Puppet::Type.type(:file).new :path => path @compiler.add_resource(@scope, file1) lambda { @compiler.add_resource(@scope, file2) }.should raise_error(Puppet::Resource::Catalog::DuplicateResourceError) diff --git a/spec/unit/parser/files.rb b/spec/unit/parser/files.rb index 42953b771..4c6e5b736 100644 --- a/spec/unit/parser/files.rb +++ b/spec/unit/parser/files.rb @@ -5,6 +5,11 @@ require File.dirname(__FILE__) + '/../../spec_helper' require 'puppet/parser/files' describe Puppet::Parser::Files do + + before do + @basepath = Puppet.features.posix? ? "/somepath" : "C:/somepath" + end + it "should have a method for finding a template" do Puppet::Parser::Files.should respond_to(:find_template) end @@ -16,7 +21,7 @@ describe Puppet::Parser::Files do describe "when searching for templates" do it "should return fully-qualified templates directly" do Puppet::Parser::Files.expects(:modulepath).never - Puppet::Parser::Files.find_template("/my/template").should == "/my/template" + Puppet::Parser::Files.find_template(@basepath + "/my/template").should == @basepath + "/my/template" end it "should return the template from the first found module" do @@ -136,19 +141,19 @@ describe Puppet::Parser::Files do it "should not look for modules when paths are fully qualified" do Puppet.expects(:value).with(:modulepath).never - file = "/fully/qualified/file.pp" + file = @basepath + "/fully/qualified/file.pp" Dir.stubs(:glob).with(file).returns([file]) Puppet::Parser::Files.find_manifests(file) end it "should directly return fully qualified files" do - file = "/fully/qualified/file.pp" + file = @basepath + "/fully/qualified/file.pp" Dir.stubs(:glob).with(file).returns([file]) Puppet::Parser::Files.find_manifests(file).should == [file] end it "should match against provided fully qualified patterns" do - pattern = "/fully/qualified/pattern/*" + pattern = @basepath + "/fully/qualified/pattern/*" Dir.expects(:glob).with(pattern).returns(%w{my file list}) Puppet::Parser::Files.find_manifests(pattern).should == %w{my file list} end @@ -160,9 +165,9 @@ describe Puppet::Parser::Files do end it "should only return files, not directories" do - pattern = "/fully/qualified/pattern/*" - file = "/my/file" - dir = "/my/directory" + pattern = @basepath + "/fully/qualified/pattern/*" + file = @basepath + "/my/file" + dir = @basepath + "/my/directory" Dir.expects(:glob).with(pattern).returns([file, dir]) FileTest.expects(:directory?).with(file).returns(false) FileTest.expects(:directory?).with(dir).returns(true) diff --git a/spec/unit/resource.rb b/spec/unit/resource.rb index 0e34c3cbc..d8620ee9a 100755 --- a/spec/unit/resource.rb +++ b/spec/unit/resource.rb @@ -4,6 +4,11 @@ require File.dirname(__FILE__) + '/../spec_helper' require 'puppet/resource' describe Puppet::Resource do + + before do + @basepath = Puppet.features.posix? ? "/somepath" : "C:/somepath" + end + [:catalog, :file, :line].each do |attr| it "should have an #{attr} attribute" do resource = Puppet::Resource.new("file", "/my/file") @@ -13,7 +18,7 @@ describe Puppet::Resource do end it "should have a :title attribute" do - Puppet::Resource.new(:file, "foo").title.should == "foo" + Puppet::Resource.new(:user, "foo").title.should == "foo" end it "should require the type and title" do @@ -21,7 +26,7 @@ describe Puppet::Resource do end it "should canonize types to capitalized strings" do - Puppet::Resource.new(:file, "foo").type.should == "File" + Puppet::Resource.new(:user, "foo").type.should == "User" end it "should canonize qualified types so all strings are capitalized" do @@ -33,7 +38,7 @@ describe Puppet::Resource do end it "should tag itself with its title if the title is a valid tag" do - Puppet::Resource.new("file", "bar").should be_tagged("bar") + Puppet::Resource.new("user", "bar").should be_tagged("bar") end it "should not tag itself with its title if the title is a not valid tag" do @@ -82,10 +87,10 @@ describe Puppet::Resource do end it "should be able to extract its information from a Puppet::Type instance" do - ral = Puppet::Type.type(:file).new :path => "/foo" + ral = Puppet::Type.type(:file).new :path => @basepath+"/foo" ref = Puppet::Resource.new(ral) ref.type.should == "File" - ref.title.should == "/foo" + ref.title.should == @basepath+"/foo" end @@ -479,10 +484,10 @@ describe Puppet::Resource do describe "when converting to a RAL resource" do it "should use the resource type's :new method to create the resource if the resource is of a builtin type" do - resource = Puppet::Resource.new("file", "/my/file") + resource = Puppet::Resource.new("file", @basepath+"/my/file") result = resource.to_ral result.should be_instance_of(Puppet::Type.type(:file)) - result[:path].should == "/my/file" + result[:path].should == @basepath+"/my/file" end it "should convert to a component instance if the resource type is not of a builtin type" do @@ -691,7 +696,7 @@ describe Puppet::Resource do before do @data = { 'type' => "file", - 'title' => "yay", + 'title' => @basepath+"/yay", } end @@ -700,7 +705,7 @@ describe Puppet::Resource do end it "should set its title to the provided title" do - Puppet::Resource.from_pson(@data).title.should == "yay" + Puppet::Resource.from_pson(@data).title.should == @basepath+"/yay" end it "should tag the resource with any provided tags" do diff --git a/spec/unit/resource/catalog.rb b/spec/unit/resource/catalog.rb index 26f69aedf..bd241fd17 100755 --- a/spec/unit/resource/catalog.rb +++ b/spec/unit/resource/catalog.rb @@ -3,6 +3,11 @@ require File.dirname(__FILE__) + '/../../spec_helper' describe Puppet::Resource::Catalog, "when compiling" do + + before do + @basepath = Puppet.features.posix? ? "/somepath" : "C:/somepath" + end + it "should be an Expirer" do Puppet::Resource::Catalog.ancestors.should be_include(Puppet::Util::Cacher::Expirer) end @@ -254,11 +259,11 @@ describe Puppet::Resource::Catalog, "when compiling" do @original.add_class *%w{four five six} @top = Puppet::Resource.new :class, 'top' - @topobject = Puppet::Resource.new :file, '/topobject' + @topobject = Puppet::Resource.new :file, @basepath+'/topobject' @middle = Puppet::Resource.new :class, 'middle' - @middleobject = Puppet::Resource.new :file, '/middleobject' + @middleobject = Puppet::Resource.new :file, @basepath+'/middleobject' @bottom = Puppet::Resource.new :class, 'bottom' - @bottomobject = Puppet::Resource.new :file, '/bottomobject' + @bottomobject = Puppet::Resource.new :file, @basepath+'/bottomobject' @resources = [@top, @topobject, @middle, @middleobject, @bottom, @bottomobject] @@ -501,11 +506,11 @@ describe Puppet::Resource::Catalog, "when compiling" do end it "should create aliases for resources isomorphic resources whose names do not match their titles" do - resource = Puppet::Type::File.new(:title => "testing", :path => "/something") + resource = Puppet::Type::File.new(:title => "testing", :path => @basepath+"/something") @catalog.add_resource(resource) - @catalog.resource(:file, "/something").should equal(resource) + @catalog.resource(:file, @basepath+"/something").should equal(resource) end it "should not create aliases for resources non-isomorphic resources whose names do not match their titles" do @@ -559,15 +564,15 @@ describe Puppet::Resource::Catalog, "when compiling" do end it "should add an alias for the namevar when the title and name differ on isomorphic resource types" do - resource = Puppet::Type.type(:file).new :path => "/something", :title => "other", :content => "blah" + resource = Puppet::Type.type(:file).new :path => @basepath+"/something", :title => "other", :content => "blah" resource.expects(:isomorphic?).returns(true) @catalog.add_resource(resource) @catalog.resource(:file, "other").should equal(resource) - @catalog.resource(:file, "/something").ref.should == resource.ref + @catalog.resource(:file, @basepath+"/something").ref.should == resource.ref end it "should not add an alias for the namevar when the title and name differ on non-isomorphic resource types" do - resource = Puppet::Type.type(:file).new :path => "/something", :title => "other", :content => "blah" + resource = Puppet::Type.type(:file).new :path => @basepath+"/something", :title => "other", :content => "blah" resource.expects(:isomorphic?).returns(false) @catalog.add_resource(resource) @catalog.resource(:file, resource.title).should equal(resource) @@ -696,15 +701,15 @@ describe Puppet::Resource::Catalog, "when compiling" do @compone = Puppet::Type::Component.new :name => "one" @comptwo = Puppet::Type::Component.new :name => "two", :require => "Class[one]" @file = Puppet::Type.type(:file) - @one = @file.new :path => "/one" - @two = @file.new :path => "/two" - @sub = @file.new :path => "/two/subdir" + @one = @file.new :path => @basepath+"/one" + @two = @file.new :path => @basepath+"/two" + @sub = @file.new :path => @basepath+"/two/subdir" @catalog.add_edge @compone, @one @catalog.add_edge @comptwo, @two - @three = @file.new :path => "/three" - @four = @file.new :path => "/four", :require => "File[/three]" - @five = @file.new :path => "/five" + @three = @file.new :path => @basepath+"/three" + @four = @file.new :path => @basepath+"/four", :require => "File[#{@basepath}/three]" + @five = @file.new :path => @basepath+"/five" @catalog.add_resource @compone, @comptwo, @one, @two, @three, @four, @five, @sub @relationships = @catalog.relationship_graph diff --git a/spec/unit/resource/type_collection.rb b/spec/unit/resource/type_collection.rb index 638a0281e..c0711bb87 100644 --- a/spec/unit/resource/type_collection.rb +++ b/spec/unit/resource/type_collection.rb @@ -378,6 +378,7 @@ describe Puppet::Resource::TypeCollection do end it "should set the parser's file to the 'manifest' setting and parse if no code is available and the manifest is available" do + File.stubs(:expand_path).with("/my/file").returns "/my/file" File.expects(:exist?).with("/my/file").returns true Puppet.settings[:manifest] = "/my/file" @parser.expects(:file=).with "/my/file" @@ -386,6 +387,7 @@ describe Puppet::Resource::TypeCollection do end it "should not attempt to load a manifest if none is present" do + File.stubs(:expand_path).with("/my/file").returns "/my/file" File.expects(:exist?).with("/my/file").returns false Puppet.settings[:manifest] = "/my/file" @parser.expects(:file=).never diff --git a/spec/unit/transaction.rb b/spec/unit/transaction.rb index a55d6e59b..b315eb124 100755 --- a/spec/unit/transaction.rb +++ b/spec/unit/transaction.rb @@ -13,6 +13,7 @@ end describe Puppet::Transaction do before do + @basepath = Puppet.features.posix? ? "/what/ever" : "C:/tmp" @transaction = Puppet::Transaction.new(Puppet::Resource::Catalog.new) end @@ -121,7 +122,7 @@ describe Puppet::Transaction do @transaction.stubs(:eval_children_and_apply_resource) @transaction.stubs(:skip?).returns false - @resource = Puppet::Type.type(:file).new :path => "/my/file" + @resource = Puppet::Type.type(:file).new :path => @basepath end it "should check whether the resource should be skipped" do @@ -156,7 +157,7 @@ describe Puppet::Transaction do describe "when applying a resource" do before do - @resource = Puppet::Type.type(:file).new :path => "/my/file" + @resource = Puppet::Type.type(:file).new :path => @basepath @status = Puppet::Resource::Status.new(@resource) @transaction = Puppet::Transaction.new(Puppet::Resource::Catalog.new) @@ -296,7 +297,7 @@ describe Puppet::Transaction do @transaction = Puppet::Transaction.new(@catalog) names = [] 2.times do |i| - name = "/my/file#{i}" + name = File.join(@basepath, "file#{i}") resource = Puppet::Type.type(:file).new :path => name names << resource.to_s @catalog.add_resource resource diff --git a/spec/unit/type/tidy.rb b/spec/unit/type/tidy.rb index 81c46cfe5..7e511899f 100755 --- a/spec/unit/type/tidy.rb +++ b/spec/unit/type/tidy.rb @@ -7,6 +7,7 @@ tidy = Puppet::Type.type(:tidy) describe tidy do before do + @basepath = Puppet.features.posix? ? "/what/ever" : "C:/tmp" Puppet.settings.stubs(:use) # for an unknown reason some of these specs fails when run individually @@ -97,7 +98,7 @@ describe tidy do convertors.each do |unit, multiple| it "should consider a %s to be %s seconds" % [unit, multiple] do - tidy = Puppet::Type.type(:tidy).new :path => "/what/ever", :age => "5%s" % unit.to_s[0..0] + tidy = Puppet::Type.type(:tidy).new :path => @basepath, :age => "5%s" % unit.to_s[0..0] tidy[:age].should == 5 * multiple end @@ -114,7 +115,7 @@ describe tidy do convertors.each do |unit, multiple| it "should consider a %s to be 1024^%s bytes" % [unit, multiple] do - tidy = Puppet::Type.type(:tidy).new :path => "/what/ever", :size => "5%s" % unit + tidy = Puppet::Type.type(:tidy).new :path => @basepath, :size => "5%s" % unit total = 5 multiple.times { total *= 1024 } @@ -125,9 +126,9 @@ describe tidy do describe "when tidying" do before do - @tidy = Puppet::Type.type(:tidy).new :path => "/what/ever" + @tidy = Puppet::Type.type(:tidy).new :path => @basepath @stat = stub 'stat', :ftype => "directory" - File.stubs(:lstat).with("/what/ever").returns @stat + File.stubs(:lstat).with(@basepath).returns @stat end describe "and generating files" do @@ -135,29 +136,29 @@ describe tidy do @tidy[:backup] = "whatever" Puppet::Type.type(:file).expects(:new).with { |args| args[:backup] == "whatever" } - @tidy.mkfile("/what/ever") + @tidy.mkfile(@basepath) end it "should set the file's path to the tidy's path" do - Puppet::Type.type(:file).expects(:new).with { |args| args[:path] == "/what/ever" } + Puppet::Type.type(:file).expects(:new).with { |args| args[:path] == @basepath } - @tidy.mkfile("/what/ever") + @tidy.mkfile(@basepath) end it "should configure the file for deletion" do Puppet::Type.type(:file).expects(:new).with { |args| args[:ensure] == :absent } - @tidy.mkfile("/what/ever") + @tidy.mkfile(@basepath) end it "should force deletion on the file" do Puppet::Type.type(:file).expects(:new).with { |args| args[:force] == true } - @tidy.mkfile("/what/ever") + @tidy.mkfile(@basepath) end it "should do nothing if the targeted file does not exist" do - File.expects(:lstat).with("/what/ever").raises Errno::ENOENT + File.expects(:lstat).with(@basepath).raises Errno::ENOENT @tidy.generate.should == [] end @@ -165,15 +166,15 @@ describe tidy do describe "and recursion is not used" do it "should generate a file resource if the file should be tidied" do - @tidy.expects(:tidy?).with("/what/ever").returns true - file = Puppet::Type.type(:file).new(:path => "/eh") - @tidy.expects(:mkfile).with("/what/ever").returns file + @tidy.expects(:tidy?).with(@basepath).returns true + file = Puppet::Type.type(:file).new(:path => @basepath+"/eh") + @tidy.expects(:mkfile).with(@basepath).returns file @tidy.generate.should == [file] end it "should do nothing if the file should not be tidied" do - @tidy.expects(:tidy?).with("/what/ever").returns false + @tidy.expects(:tidy?).with(@basepath).returns false @tidy.expects(:mkfile).never @tidy.generate.should == [] @@ -184,12 +185,12 @@ describe tidy do before do @tidy[:recurse] = true Puppet::FileServing::Fileset.any_instance.stubs(:stat).returns mock("stat") - @fileset = Puppet::FileServing::Fileset.new("/what/ever") + @fileset = Puppet::FileServing::Fileset.new(@basepath) Puppet::FileServing::Fileset.stubs(:new).returns @fileset end it "should use a Fileset for infinite recursion" do - Puppet::FileServing::Fileset.expects(:new).with("/what/ever", :recurse => true).returns @fileset + Puppet::FileServing::Fileset.expects(:new).with(@basepath, :recurse => true).returns @fileset @fileset.expects(:files).returns %w{. one two} @tidy.stubs(:tidy?).returns false @@ -198,7 +199,7 @@ describe tidy do it "should use a Fileset for limited recursion" do @tidy[:recurse] = 42 - Puppet::FileServing::Fileset.expects(:new).with("/what/ever", :recurse => true, :recurselimit => 42).returns @fileset + Puppet::FileServing::Fileset.expects(:new).with(@basepath, :recurse => true, :recurselimit => 42).returns @fileset @fileset.expects(:files).returns %w{. one two} @tidy.stubs(:tidy?).returns false @@ -208,13 +209,13 @@ describe tidy do it "should generate a file resource for every file that should be tidied but not for files that should not be tidied" do @fileset.expects(:files).returns %w{. one two} - @tidy.expects(:tidy?).with("/what/ever").returns true - @tidy.expects(:tidy?).with("/what/ever/one").returns true - @tidy.expects(:tidy?).with("/what/ever/two").returns false + @tidy.expects(:tidy?).with(@basepath).returns true + @tidy.expects(:tidy?).with(@basepath+"/one").returns true + @tidy.expects(:tidy?).with(@basepath+"/two").returns false - file = Puppet::Type.type(:file).new(:path => "/eh") - @tidy.expects(:mkfile).with("/what/ever").returns file - @tidy.expects(:mkfile).with("/what/ever/one").returns file + file = Puppet::Type.type(:file).new(:path => @basepath+"/eh") + @tidy.expects(:mkfile).with(@basepath).returns file + @tidy.expects(:mkfile).with(@basepath+"/one").returns file @tidy.generate end @@ -222,7 +223,7 @@ describe tidy do describe "and determining whether a file matches provided glob patterns" do before do - @tidy = Puppet::Type.type(:tidy).new :path => "/what/ever", :recurse => 1 + @tidy = Puppet::Type.type(:tidy).new :path => @basepath, :recurse => 1 @tidy[:matches] = %w{*foo* *bar*} @stat = mock 'stat' @@ -248,7 +249,7 @@ describe tidy do describe "and determining whether a file is too old" do before do - @tidy = Puppet::Type.type(:tidy).new :path => "/what/ever" + @tidy = Puppet::Type.type(:tidy).new :path => @basepath @stat = stub 'stat' @tidy[:age] = "1s" @@ -260,25 +261,25 @@ describe tidy do @tidy[:type] = :ctime @stat.expects(:ctime).returns(Time.now) - @ager.tidy?("/what/ever", @stat) + @ager.tidy?(@basepath, @stat) end it "should return false if the file is more recent than the specified age" do @stat.expects(:mtime).returns(Time.now) - @ager.should_not be_tidy("/what/ever", @stat) + @ager.should_not be_tidy(@basepath, @stat) end it "should return true if the file is older than the specified age" do @stat.expects(:mtime).returns(Time.now - 10) - @ager.must be_tidy("/what/ever", @stat) + @ager.must be_tidy(@basepath, @stat) end end describe "and determining whether a file is too large" do before do - @tidy = Puppet::Type.type(:tidy).new :path => "/what/ever" + @tidy = Puppet::Type.type(:tidy).new :path => @basepath @stat = stub 'stat', :ftype => "file" @tidy[:size] = "1kb" @@ -288,54 +289,54 @@ describe tidy do it "should return false if the file is smaller than the specified size" do @stat.expects(:size).returns(4) # smaller than a kilobyte - @sizer.should_not be_tidy("/what/ever", @stat) + @sizer.should_not be_tidy(@basepath, @stat) end it "should return true if the file is larger than the specified size" do @stat.expects(:size).returns(1500) # larger than a kilobyte - @sizer.must be_tidy("/what/ever", @stat) + @sizer.must be_tidy(@basepath, @stat) end it "should return true if the file is equal to the specified size" do @stat.expects(:size).returns(1024) - @sizer.must be_tidy("/what/ever", @stat) + @sizer.must be_tidy(@basepath, @stat) end end describe "and determining whether a file should be tidied" do before do - @tidy = Puppet::Type.type(:tidy).new :path => "/what/ever" + @tidy = Puppet::Type.type(:tidy).new :path => @basepath @stat = stub 'stat', :ftype => "file" - File.stubs(:lstat).with("/what/ever").returns @stat + File.stubs(:lstat).with(@basepath).returns @stat end it "should not try to recurse if the file does not exist" do @tidy[:recurse] = true - File.stubs(:lstat).with("/what/ever").returns nil + File.stubs(:lstat).with(@basepath).returns nil @tidy.generate.should == [] end it "should not be tidied if the file does not exist" do - File.expects(:lstat).with("/what/ever").raises Errno::ENOENT + File.expects(:lstat).with(@basepath).raises Errno::ENOENT - @tidy.should_not be_tidy("/what/ever") + @tidy.should_not be_tidy(@basepath) end it "should not be tidied if the user has no access to the file" do - File.expects(:lstat).with("/what/ever").raises Errno::EACCES + File.expects(:lstat).with(@basepath).raises Errno::EACCES - @tidy.should_not be_tidy("/what/ever") + @tidy.should_not be_tidy(@basepath) end it "should not be tidied if it is a directory and rmdirs is set to false" do stat = mock 'stat', :ftype => "directory" - File.expects(:lstat).with("/what/ever").returns stat + File.expects(:lstat).with(@basepath).returns stat - @tidy.should_not be_tidy("/what/ever") + @tidy.should_not be_tidy(@basepath) end it "should return false if it does not match any provided globs" do @@ -343,24 +344,24 @@ describe tidy do @tidy[:matches] = "globs" matches = @tidy.parameter(:matches) - matches.expects(:tidy?).with("/what/ever", @stat).returns false - @tidy.should_not be_tidy("/what/ever") + matches.expects(:tidy?).with(@basepath, @stat).returns false + @tidy.should_not be_tidy(@basepath) end it "should return false if it does not match aging requirements" do @tidy[:age] = "1d" ager = @tidy.parameter(:age) - ager.expects(:tidy?).with("/what/ever", @stat).returns false - @tidy.should_not be_tidy("/what/ever") + ager.expects(:tidy?).with(@basepath, @stat).returns false + @tidy.should_not be_tidy(@basepath) end it "should return false if it does not match size requirements" do @tidy[:size] = "1b" sizer = @tidy.parameter(:size) - sizer.expects(:tidy?).with("/what/ever", @stat).returns false - @tidy.should_not be_tidy("/what/ever") + sizer.expects(:tidy?).with(@basepath, @stat).returns false + @tidy.should_not be_tidy(@basepath) end it "should tidy a file if age and size are set but only size matches" do @@ -369,7 +370,7 @@ describe tidy do @tidy.parameter(:size).stubs(:tidy?).returns true @tidy.parameter(:age).stubs(:tidy?).returns false - @tidy.should be_tidy("/what/ever") + @tidy.should be_tidy(@basepath) end it "should tidy a file if age and size are set but only age matches" do @@ -378,23 +379,23 @@ describe tidy do @tidy.parameter(:size).stubs(:tidy?).returns false @tidy.parameter(:age).stubs(:tidy?).returns true - @tidy.should be_tidy("/what/ever") + @tidy.should be_tidy(@basepath) end it "should tidy all files if neither age nor size is set" do - @tidy.must be_tidy("/what/ever") + @tidy.must be_tidy(@basepath) end it "should sort the results inversely by path length, so files are added to the catalog before their directories" do @tidy[:recurse] = true @tidy[:rmdirs] = true - fileset = Puppet::FileServing::Fileset.new("/what/ever") + fileset = Puppet::FileServing::Fileset.new(@basepath) Puppet::FileServing::Fileset.expects(:new).returns fileset fileset.expects(:files).returns %w{. one one/two} @tidy.stubs(:tidy?).returns true - @tidy.generate.collect { |r| r[:path] }.should == %w{/what/ever/one/two /what/ever/one /what/ever} + @tidy.generate.collect { |r| r[:path] }.should == [@basepath+"/one/two", @basepath+"/one", @basepath] end end @@ -402,16 +403,16 @@ describe tidy do @tidy[:recurse] = true @tidy[:rmdirs] = true fileset = mock 'fileset' - Puppet::FileServing::Fileset.expects(:new).with("/what/ever", :recurse => true).returns fileset + Puppet::FileServing::Fileset.expects(:new).with(@basepath, :recurse => true).returns fileset fileset.expects(:files).returns %w{. one two one/subone two/subtwo one/subone/ssone} @tidy.stubs(:tidy?).returns true result = @tidy.generate.inject({}) { |hash, res| hash[res[:path]] = res; hash } { - "/what/ever" => %w{/what/ever/one /what/ever/two}, - "/what/ever/one" => ["/what/ever/one/subone"], - "/what/ever/two" => ["/what/ever/two/subtwo"], - "/what/ever/one/subone" => ["/what/ever/one/subone/ssone"] + @basepath => [ @basepath+"/one", @basepath+"/two" ], + @basepath+"/one" => [@basepath+"/one/subone"], + @basepath+"/two" => [@basepath+"/two/subtwo"], + @basepath+"/one/subone" => [@basepath+"/one/subone/ssone"] }.each do |parent, children| children.each do |child| ref = Puppet::Resource.new(:file, child) diff --git a/spec/unit/util/settings.rb b/spec/unit/util/settings.rb index bf0776fc8..e36fd3fd9 100755 --- a/spec/unit/util/settings.rb +++ b/spec/unit/util/settings.rb @@ -359,9 +359,10 @@ describe Puppet::Util::Settings do end it "should use its current ':config' value for the file to parse" do - @settings[:config] = "/my/file" + 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 + @settings[:config] = myfile - File.expects(:read).with("/my/file").returns("[main]") + File.expects(:read).with(myfile).returns "[main]" @settings.parse end @@ -522,6 +523,7 @@ describe Puppet::Util::Settings do filetimeout = -1 " File.expects(:read).with(somefile).returns(text) + File.expects(:expand_path).with(somefile).returns somefile @settings[:config] = somefile end @@ -670,33 +672,39 @@ describe Puppet::Util::Settings do before do @settings = Puppet::Util::Settings.new @settings.stubs(:service_user_available?).returns true + @prefix = Puppet.features.posix? ? "" : "C:" end it "should add all file resources to the catalog if no sections have been specified" do - @settings.setdefaults :main, :maindir => ["/maindir", "a"], :seconddir => ["/seconddir", "a"] - @settings.setdefaults :other, :otherdir => ["/otherdir", "a"] + @settings.setdefaults :main, :maindir => [@prefix+"/maindir", "a"], :seconddir => [@prefix+"/seconddir", "a"] + @settings.setdefaults :other, :otherdir => [@prefix+"/otherdir", "a"] + catalog = @settings.to_catalog - %w{/maindir /seconddir /otherdir}.each do |path| + p "three dirs" + p catalog + + [@prefix+"/maindir", @prefix+"/seconddir", @prefix+"/otherdir"].each do |path| catalog.resource(:file, path).should be_instance_of(Puppet::Resource) end end it "should add only files in the specified sections if section names are provided" do - @settings.setdefaults :main, :maindir => ["/maindir", "a"] - @settings.setdefaults :other, :otherdir => ["/otherdir", "a"] + @settings.setdefaults :main, :maindir => [@prefix+"/maindir", "a"] + @settings.setdefaults :other, :otherdir => [@prefix+"/otherdir", "a"] catalog = @settings.to_catalog(:main) - catalog.resource(:file, "/otherdir").should be_nil - catalog.resource(:file, "/maindir").should be_instance_of(Puppet::Resource) + p catalog + catalog.resource(:file, @prefix+"/otherdir").should be_nil + catalog.resource(:file, @prefix+"/maindir").should be_instance_of(Puppet::Resource) end it "should not try to add the same file twice" do - @settings.setdefaults :main, :maindir => ["/maindir", "a"] - @settings.setdefaults :other, :otherdir => ["/maindir", "a"] + @settings.setdefaults :main, :maindir => [@prefix+"/maindir", "a"] + @settings.setdefaults :other, :otherdir => [@prefix+"/maindir", "a"] lambda { @settings.to_catalog }.should_not raise_error end it "should ignore files whose :to_resource method returns nil" do - @settings.setdefaults :main, :maindir => ["/maindir", "a"] + @settings.setdefaults :main, :maindir => [@prefix+"/maindir", "a"] @settings.setting(:maindir).expects(:to_resource).returns nil Puppet::Resource::Catalog.any_instance.expects(:add_resource).never diff --git a/spec/unit/util/settings/file_setting.rb b/spec/unit/util/settings/file_setting.rb index dfe4d25d0..a6b7f024b 100755 --- a/spec/unit/util/settings/file_setting.rb +++ b/spec/unit/util/settings/file_setting.rb @@ -8,6 +8,10 @@ require 'puppet/util/settings/file_setting' describe Puppet::Util::Settings::FileSetting do FileSetting = Puppet::Util::Settings::FileSetting + before do + @basepath = Puppet.features.posix? ? "/somepath" : "C:/somepath" + end + describe "when determining whether the service user should be used" do before do @settings = mock 'settings' @@ -120,7 +124,7 @@ describe Puppet::Util::Settings::FileSetting do before do @settings = mock 'settings' @file = Puppet::Util::Settings::FileSetting.new(:settings => @settings, :desc => "eh", :name => :mydir, :section => "mysect") - @settings.stubs(:value).with(:mydir).returns "/my/file" + @settings.stubs(:value).with(:mydir).returns @basepath end it "should skip files that cannot determine their types" do @@ -131,20 +135,24 @@ describe Puppet::Util::Settings::FileSetting do it "should skip non-existent files if 'create_files' is not enabled" do @file.expects(:create_files?).returns false @file.expects(:type).returns :file - File.expects(:exist?).with("/my/file").returns false + File.expects(:exist?).with(@basepath).returns false @file.to_resource.should be_nil end it "should manage existent files even if 'create_files' is not enabled" do @file.expects(:create_files?).returns false @file.expects(:type).returns :file - File.expects(:exist?).with("/my/file").returns true + File.expects(:exist?).with(@basepath).returns true @file.to_resource.should be_instance_of(Puppet::Resource) end - it "should skip files in /dev" do - @settings.stubs(:value).with(:mydir).returns "/dev/file" - @file.to_resource.should be_nil + describe "on POSIX systems" do + confine "no /dev on Win32" => Puppet.features.posix? + + it "should skip files in /dev" do + @settings.stubs(:value).with(:mydir).returns "/dev/file" + @file.to_resource.should be_nil + end end it "should skip files whose paths are not strings" do @@ -155,7 +163,7 @@ describe Puppet::Util::Settings::FileSetting do it "should return a file resource with the path set appropriately" do resource = @file.to_resource resource.type.should == "File" - resource.title.should == "/my/file" + resource.title.should == @basepath end it "should fully qualified returned files if necessary (#795)" do |
