diff options
Diffstat (limited to 'spec')
24 files changed, 355 insertions, 57 deletions
diff --git a/spec/integration/checksum.rb b/spec/integration/checksum.rb index c94f3e47e..49ae8d2b7 100755 --- a/spec/integration/checksum.rb +++ b/spec/integration/checksum.rb @@ -9,6 +9,7 @@ require 'puppet/checksum' describe Puppet::Checksum, " when using the file terminus" do before do + Puppet.settings.stubs(:use) Puppet::Checksum.terminus_class = :file @content = "this is some content" @sum = Puppet::Checksum.new(@content) diff --git a/spec/integration/defaults.rb b/spec/integration/defaults.rb index b3f3a7066..46b5fd64e 100755 --- a/spec/integration/defaults.rb +++ b/spec/integration/defaults.rb @@ -5,6 +5,7 @@ require File.dirname(__FILE__) + '/../spec_helper' require 'puppet/defaults' describe "Puppet defaults" do + include Puppet::Util::Execution after { Puppet.settings.clear } describe "when setting the :factpath" do @@ -83,4 +84,12 @@ describe "Puppet defaults" do Puppet.settings.element(setting).should be_instance_of(Puppet::Util::Settings::CElement) end end + + it "should add /usr/sbin and /sbin to the path if they're not there" do + withenv("PATH" => "/usr/bin:/usr/local/bin") do + Puppet.settings[:path] = "none" # this causes it to ignore the setting + ENV["PATH"].split(File::PATH_SEPARATOR).should be_include("/usr/sbin") + ENV["PATH"].split(File::PATH_SEPARATOR).should be_include("/sbin") + end + end end diff --git a/spec/integration/reports.rb b/spec/integration/reports.rb index 7351c3da1..cc4ae8f4c 100755 --- a/spec/integration/reports.rb +++ b/spec/integration/reports.rb @@ -8,6 +8,10 @@ require File.dirname(__FILE__) + '/../spec_helper' require 'puppet/reports' describe Puppet::Reports, " when using report types" do + before do + Puppet.settings.stubs(:use) + end + it "should load report types as modules" do Puppet::Reports.report(:store).should be_instance_of(Module) end diff --git a/spec/integration/transaction/report.rb b/spec/integration/transaction/report.rb index 68533b503..b704e56b8 100755 --- a/spec/integration/transaction/report.rb +++ b/spec/integration/transaction/report.rb @@ -7,7 +7,10 @@ require File.dirname(__FILE__) + '/../../spec_helper' describe Puppet::Transaction::Report do describe "when using the indirector" do - after { Puppet::Util::Cacher.expire } + after do + Puppet::Util::Cacher.expire + Puppet.settings.stubs(:use) + end it "should be able to delegate to the :processor terminus" do Puppet::Transaction::Report.indirection.stubs(:terminus_class).returns :processor diff --git a/spec/integration/type/package.rb b/spec/integration/type/package.rb index def44ad97..a3d8eb278 100755 --- a/spec/integration/type/package.rb +++ b/spec/integration/type/package.rb @@ -9,7 +9,7 @@ describe Puppet::Type.type(:package), "when choosing a default package provider" end def provider_name(os) - {"Debian" => :apt, "Darwin" => :apple, "RedHat" => :up2date, "Fedora" => :yum, "FreeBSD" => :ports, "OpenBSD" => :openbsd, "Solaris" => :sun}[os] + {"Ubuntu" => :apt, "Debian" => :apt, "Darwin" => :apple, "RedHat" => :up2date, "Fedora" => :yum, "FreeBSD" => :ports, "OpenBSD" => :openbsd, "Solaris" => :sun}[os] end it "should have a default provider" do @@ -17,6 +17,9 @@ describe Puppet::Type.type(:package), "when choosing a default package provider" end it "should choose the correct provider each platform" do - Puppet::Type.type(:package).defaultprovider.name.should == provider_name(Facter.value(:operatingsystem)) + unless default_provider = provider_name(Facter.value(:operatingsystem)) + pending("No default provider specified in this test for %s" % Facter.value(:operatingsystem)) + end + Puppet::Type.type(:package).defaultprovider.name.should == default_provider end end diff --git a/spec/unit/file_collection.rb b/spec/unit/file_collection.rb new file mode 100755 index 000000000..81bcc2d2d --- /dev/null +++ b/spec/unit/file_collection.rb @@ -0,0 +1,53 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../spec_helper' + +require 'puppet/file_collection' + +describe Puppet::FileCollection do + before do + @collection = Puppet::FileCollection.new + end + + it "should be able to convert a file name into an index" do + @collection.index("/my/file").should be_instance_of(Fixnum) + end + + it "should be able to convert an index into a file name" do + index = @collection.index("/path/to/file") + @collection.path(index).should == "/path/to/file" + end + + it "should always give the same file name for a given index" do + index = @collection.index("/path/to/file") + @collection.path(index).should == @collection.path(index) + end + + it "should always give the same index for a given file name" do + @collection.index("/my/file").should == @collection.index("/my/file") + end + + it "should always correctly relate a file name and its index even when multiple files are in the collection" do + indexes = %w{a b c d e f}.inject({}) do |hash, letter| + hash[letter] = @collection.index("/path/to/file/%s" % letter) + hash + end + + indexes.each do |letter, index| + @collection.index("/path/to/file/%s" % letter).should == indexes[letter] + @collection.path(index).should == @collection.path(index) + end + end + + it "should return nil as the file name when an unknown index is provided" do + @collection.path(50).should be_nil + end + + it "should provide a global collection" do + Puppet::FileCollection.collection.should be_instance_of(Puppet::FileCollection) + end + + it "should reuse the global collection" do + Puppet::FileCollection.collection.should equal(Puppet::FileCollection.collection) + end +end diff --git a/spec/unit/file_collection/lookup.rb b/spec/unit/file_collection/lookup.rb new file mode 100755 index 000000000..81cc61872 --- /dev/null +++ b/spec/unit/file_collection/lookup.rb @@ -0,0 +1,46 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../spec_helper' +require 'puppet/file_collection/lookup' + +class LookupTester + include Puppet::FileCollection::Lookup +end + +describe Puppet::FileCollection::Lookup do + before do + @tester = LookupTester.new + + @file_collection = mock 'file_collection' + Puppet::FileCollection.stubs(:collection).returns @file_collection + end + + it "should use the file collection to determine the index of the file name" do + @file_collection.expects(:index).with("/my/file").returns 50 + + @tester.file = "/my/file" + @tester.file_index.should == 50 + end + + it "should return nil as the file name if no index is set" do + @tester.file.should be_nil + end + + it "should use the file collection to convert the index to a file name" do + @file_collection.expects(:path).with(25).returns "/path/to/file" + + @tester.file_index = 25 + + @tester.file.should == "/path/to/file" + end + + it "should support a line attribute" do + @tester.line = 50 + @tester.line.should == 50 + end + + it "should default to the global file collection" do + Puppet::FileCollection.expects(:collection).returns "collection" + @tester.file_collection.should == "collection" + end +end diff --git a/spec/unit/indirector/node/ldap.rb b/spec/unit/indirector/node/ldap.rb index ed8809e73..d407796c6 100755 --- a/spec/unit/indirector/node/ldap.rb +++ b/spec/unit/indirector/node/ldap.rb @@ -91,6 +91,26 @@ describe Puppet::Node::Ldap do @searcher.entry2hash(@entry)[:parameters]["foo"].should == "one" end + it "should convert 'true' values to the boolean 'true'" do + @entry.stubs(:to_hash).returns({"one" => ["true"]}) + @searcher.entry2hash(@entry)[:parameters]["one"].should == true + end + + it "should convert 'false' values to the boolean 'false'" do + @entry.stubs(:to_hash).returns({"one" => ["false"]}) + @searcher.entry2hash(@entry)[:parameters]["one"].should == false + end + + it "should convert 'true' values to the boolean 'true' inside an array" do + @entry.stubs(:to_hash).returns({"one" => ["true", "other"]}) + @searcher.entry2hash(@entry)[:parameters]["one"].should == [true, "other"] + end + + it "should convert 'false' values to the boolean 'false' inside an array" do + @entry.stubs(:to_hash).returns({"one" => ["false", "other"]}) + @searcher.entry2hash(@entry)[:parameters]["one"].should == [false, "other"] + end + it "should add the parent's name if present" do @entry.stubs(:vals).with("parentnode").returns(%w{foo}) @searcher.entry2hash(@entry)[:parent].should == "foo" diff --git a/spec/unit/other/transbucket.rb b/spec/unit/other/transbucket.rb index 63de962e5..63b5137b5 100755 --- a/spec/unit/other/transbucket.rb +++ b/spec/unit/other/transbucket.rb @@ -70,20 +70,20 @@ describe Puppet::TransBucket, " when generating a catalog" do @bottom = Puppet::TransBucket.new @bottom.type = "fake" @bottom.name = "bottom" - @bottomobj = Puppet::TransObject.new("bottom", "user") + @bottomobj = Puppet::TransObject.new("bottom", "notify") @bottom.push @bottomobj @middle = Puppet::TransBucket.new @middle.type = "fake" @middle.name = "middle" - @middleobj = Puppet::TransObject.new("middle", "user") + @middleobj = Puppet::TransObject.new("middle", "notify") @middle.push(@middleobj) @middle.push(@bottom) @top = Puppet::TransBucket.new @top.type = "fake" @top.name = "top" - @topobj = Puppet::TransObject.new("top", "user") + @topobj = Puppet::TransObject.new("top", "notify") @top.push(@topobj) @top.push(@middle) @@ -94,7 +94,7 @@ describe Puppet::TransBucket, " when generating a catalog" do it "should convert all transportable objects to RAL resources" do @catalog = @top.to_catalog @users.each do |name| - @catalog.vertices.find { |r| r.class.name == :user and r.title == name }.should be_instance_of(Puppet::Type.type(:user)) + @catalog.vertices.find { |r| r.class.name == :notify and r.title == name }.should be_instance_of(Puppet::Type.type(:notify)) end end diff --git a/spec/unit/parser/ast.rb b/spec/unit/parser/ast.rb index 513943725..35e2b1eff 100644 --- a/spec/unit/parser/ast.rb +++ b/spec/unit/parser/ast.rb @@ -5,6 +5,10 @@ require File.dirname(__FILE__) + '/../../spec_helper' require 'puppet/parser/ast' describe Puppet::Parser::AST do + + it "should use the file lookup module" do + Puppet::Parser::AST.ancestors.should be_include(Puppet::FileCollection::Lookup) + end it "should have a doc accessor" do ast = Puppet::Parser::AST.new({}) @@ -34,4 +38,4 @@ describe Puppet::Parser::AST do end end -end
\ No newline at end of file +end diff --git a/spec/unit/parser/resource.rb b/spec/unit/parser/resource.rb index 92699e040..a042b4e72 100755 --- a/spec/unit/parser/resource.rb +++ b/spec/unit/parser/resource.rb @@ -44,6 +44,10 @@ describe Puppet::Parser::Resource do end end + it "should use the file lookup module" do + Puppet::Parser::Resource.ancestors.should be_include(Puppet::FileCollection::Lookup) + end + it "should be isomorphic if it is builtin and models an isomorphic type" do Puppet::Type.type(:file).expects(:isomorphic?).returns(true) @resource = Puppet::Parser::Resource.new(:type => "file", :title => "whatever", :scope => @scope, :source => @source).isomorphic?.should be_true diff --git a/spec/unit/parser/resource/reference.rb b/spec/unit/parser/resource/reference.rb index bb1452692..6284e67cc 100755 --- a/spec/unit/parser/resource/reference.rb +++ b/spec/unit/parser/resource/reference.rb @@ -7,6 +7,10 @@ describe Puppet::Parser::Resource::Reference do @type = Puppet::Parser::Resource::Reference end + it "should use the file lookup module" do + Puppet::Parser::Resource::Reference.ancestors.should be_include(Puppet::FileCollection::Lookup) + end + it "should require a type" do proc { @type.new(:title => "yay") }.should raise_error(Puppet::DevError) end diff --git a/spec/unit/property/list.rb b/spec/unit/property/list.rb index 2fab868db..854ab4874 100644 --- a/spec/unit/property/list.rb +++ b/spec/unit/property/list.rb @@ -36,6 +36,10 @@ describe list_class do @property.is_to_s(["foo","bar"]).should == "foo,bar" end + it "should be able to correctly convert ':absent' to a string" do + @property.is_to_s(:absent).should == "absent" + end + describe "when adding should to current" do it "should add the arrays when current is an array" do @property.add_should_with_current(["foo"], ["bar"]).should == ["foo", "bar"] diff --git a/spec/unit/provider/augeas/augeas.rb b/spec/unit/provider/augeas/augeas.rb index affc66676..284145657 100644 --- a/spec/unit/provider/augeas/augeas.rb +++ b/spec/unit/provider/augeas/augeas.rb @@ -133,14 +133,14 @@ describe provider_class do tokens[0][0].should == "set" tokens[0][1].should == 'Jar Jar' tokens[0][2].should == "Binks is my copilot" - end + end end describe "get filters" do before do augeas_stub = stub("augeas", :get => "value") @provider = provider_class.new() - @provider.stubs(:open_augeas).returns(augeas_stub) + @provider.aug= augeas_stub end it "should return false for a = nonmatch" do @@ -168,7 +168,7 @@ describe provider_class do before do augeas_stub = stub("augeas", :match => ["set", "of", "values"]) @provider = provider_class.new() - @provider.stubs(:open_augeas).returns(augeas_stub) + @provider.aug= augeas_stub end it "should return true for size match" do @@ -202,53 +202,82 @@ describe provider_class do end end - describe "need_to_run" do + describe "need to run" do it "should handle no filters" do - resource = stub("resource", :[] => "") + resource = stub("resource") + resource.stubs(:[]).returns(false).then.returns("") + augeas_stub = stub("augeas", :match => ["set", "of", "values"]) + augeas_stub.stubs("close") provider = provider_class.new(resource) + provider.stubs(:get_augeas_version).returns("0.3.5") provider.need_to_run?.should == true end it "should return true when a get filter matches" do - resource = stub("resource", :[] => "get path == value") + resource = stub("resource") + resource.stubs(:[]).returns(false).then.returns("get path == value") provider = provider_class.new(resource) augeas_stub = stub("augeas", :get => "value") - provider.stubs(:open_augeas).returns(augeas_stub) + augeas_stub.stubs("close") + provider.aug= augeas_stub + provider.stubs(:get_augeas_version).returns("0.3.5") provider.need_to_run?.should == true end it "should return false when a get filter does not match" do - resource = stub("resource", :[] => "get path == another value") + resource = stub("resource") + resource.stubs(:[]).returns(false).then.returns("get path == another value") provider = provider_class.new(resource) augeas_stub = stub("augeas", :get => "value") - provider.stubs(:open_augeas).returns(augeas_stub) + augeas_stub.stubs("close") + provider.aug= augeas_stub + provider.stubs(:get_augeas_version).returns("0.3.5") provider.need_to_run?.should == false end it "should return true when a match filter matches" do - resource = stub("resource", :[] => "match path size == 3") + resource = stub("resource") + resource.stubs(:[]).returns(false).then.returns("match path size == 3") provider = provider_class.new(resource) augeas_stub = stub("augeas", :match => ["set", "of", "values"]) - provider.stubs(:open_augeas).returns(augeas_stub) + augeas_stub.stubs("close") + provider.aug= augeas_stub + provider.stubs(:get_augeas_version).returns("0.3.5") provider.need_to_run?.should == true end it "should return false when a match filter does not match" do - resource = stub("resource", :[] => "match path size == 2") + resource = stub("resource") + resource.stubs(:[]).returns(false).then.returns("match path size == 2") + provider = provider_class.new(resource) + augeas_stub = stub("augeas", :match => ["set", "of", "values"]) + augeas_stub.stubs("close") + provider.aug= augeas_stub + provider.stubs(:get_augeas_version).returns("0.3.5") + provider.need_to_run?.should == false + end + + #This is a copy of the last one, with setting the force to true + it "setting force should not change the above logic" do + resource = stub("resource") + resource.stubs(:[]).returns(true).then.returns("match path size == 2") provider = provider_class.new(resource) augeas_stub = stub("augeas", :match => ["set", "of", "values"]) - provider.stubs(:open_augeas).returns(augeas_stub) + augeas_stub.stubs("close") + provider.aug= augeas_stub + provider.stubs(:get_augeas_version).returns("0.3.5") provider.need_to_run?.should == false end end - describe "augeas integration" do + describe "augeas execution integration" do before do @resource = stub("resource") @provider = provider_class.new(@resource) @augeas = stub("augeas") - @provider.stubs(:open_augeas).returns(@augeas) + @provider.aug= @augeas + @provider.stubs(:get_augeas_version).returns("0.3.5") end it "should handle set commands" do @@ -257,6 +286,7 @@ describe provider_class do @resource.expects(:[]).times(2).returns(command).then.returns(context) @augeas.expects(:set).with("/some/path/Jar/Jar", "Binks") @augeas.expects(:save).returns(true) + @augeas.expects(:close) @provider.execute_changes.should == :executed end @@ -266,6 +296,7 @@ describe provider_class do @resource.expects(:[]).times(2).returns(command).then.returns(context) @augeas.expects(:rm).with("/Jar/Jar") @augeas.expects(:save).returns(true) + @augeas.expects(:close) @provider.execute_changes.should == :executed end @@ -275,6 +306,7 @@ describe provider_class do @resource.expects(:[]).times(2).returns(command).then.returns(context) @augeas.expects(:rm).with("/Jar/Jar") @augeas.expects(:save).returns(true) + @augeas.expects(:close) @provider.execute_changes.should == :executed end @@ -284,9 +316,10 @@ describe provider_class do @resource.expects(:[]).times(2).returns(command).then.returns(context) @augeas.expects(:clear).with("/foo/Jar/Jar") @augeas.expects(:save).returns(true) + @augeas.expects(:close) @provider.execute_changes.should == :executed - end - + end + it "should handle ins commands with before" do command = [["ins", "Binks", "before /Jar/Jar"]] @@ -294,6 +327,7 @@ describe provider_class do @resource.expects(:[]).times(2).returns(command).then.returns(context) @augeas.expects(:insert).with("/foo/Jar/Jar", "Binks", true) @augeas.expects(:save).returns(true) + @augeas.expects(:close) @provider.execute_changes.should == :executed end @@ -303,6 +337,7 @@ describe provider_class do @resource.expects(:[]).times(2).returns(command).then.returns(context) @augeas.expects(:insert).with("/foo/Jar/Jar", "Binks", false) @augeas.expects(:save).returns(true) + @augeas.expects(:close) @provider.execute_changes.should == :executed end @@ -312,16 +347,18 @@ describe provider_class do @resource.expects(:[]).times(2).returns(command).then.returns(context) @augeas.expects(:insert).with("/Jar/Jar", "Binks", false) @augeas.expects(:save).returns(true) + @augeas.expects(:close) @provider.execute_changes.should == :executed - end - + end + it "should handle multiple commands" do command = [["ins", "Binks", "after /Jar/Jar"], ["clear", "/Jar/Jar"]] context = "/foo" @resource.expects(:[]).times(2).returns(command).then.returns(context) @augeas.expects(:insert).with("/foo/Jar/Jar", "Binks", false) - @augeas.expects(:clear).with("/foo/Jar/Jar") + @augeas.expects(:clear).with("/foo/Jar/Jar") @augeas.expects(:save).returns(true) + @augeas.expects(:close) @provider.execute_changes.should == :executed end end diff --git a/spec/unit/provider/mount/parsed.rb b/spec/unit/provider/mount/parsed.rb index d2c992f33..364e145be 100755 --- a/spec/unit/provider/mount/parsed.rb +++ b/spec/unit/provider/mount/parsed.rb @@ -130,6 +130,7 @@ describe provider_class do describe provider_class, " when modifying the filesystem tab" do include ParsedMountTesting before do + Puppet.settings.stubs(:use) # Never write to disk, only to RAM. @provider_class.stubs(:filetype).returns(Puppet::Util::FileType.filetype(:ram)) diff --git a/spec/unit/provider/ssh_authorized_key/parsed.rb b/spec/unit/provider/ssh_authorized_key/parsed.rb index ec8f2b96a..18f3be126 100755 --- a/spec/unit/provider/ssh_authorized_key/parsed.rb +++ b/spec/unit/provider/ssh_authorized_key/parsed.rb @@ -72,32 +72,76 @@ describe provider_class do genkey(key).should == "from=\"192.168.1.1\",no-pty,no-X11-forwarding ssh-rsa AAAAfsfddsjldjgksdflgkjsfdlgkj root@localhost\n" end - it "should prefetch ~user/.ssh/authorized_keys when user is given" do - key = Puppet::Type.type(:ssh_authorized_key).create( - :name => "Test", - :key => "AA", - :type => "rsa", - :ensure => :present, - :user => "root") - prov = @provider.new key + it "'s parse_options method should be able to parse options containing commas" do + options = %w{from="host1.reductlivelabs.com,host.reductivelabs.com" command="/usr/local/bin/run" ssh-pty} + optionstr = options.join(", ") - prov.prefetch - prov.target.should == File.expand_path("~root/.ssh/authorized_keys") + @provider.parse_options(optionstr).should == options end +end - it "should create destination dir" do - # No idea how to test the flush method +describe provider_class do + before :each do + @resource = stub("resource", :name => "foo") + @resource.stubs(:[]).returns "foo" + @provider = provider_class.new(@resource) end - it "should set correct default permissions" do - # No idea how to test the flush method - end + describe "when flushing" do + before :each do + # Stub file and directory operations + Dir.stubs(:mkdir) + File.stubs(:chmod) + File.stubs(:chown) + end - it "'s parse_options method should be able to parse options containing commas" do - options = %w{from="host1.reductlivelabs.com,host.reductivelabs.com" command="/usr/local/bin/run" ssh-pty} - optionstr = options.join(", ") + describe "and a user has been specified" do + before :each do + @resource.stubs(:should).with(:user).returns "nobody" + target = File.expand_path("~nobody/.ssh/authorized_keys") + @resource.stubs(:should).with(:target).returns target + end + + it "should create the directory" do + Dir.expects(:mkdir).with(File.expand_path("~nobody/.ssh"), 0700) + @provider.flush + end + + it "should chown the directory to the user" do + uid = Puppet::Util.uid("nobody") + File.expects(:chown).with(uid, nil, File.expand_path("~nobody/.ssh")) + @provider.flush + end + + it "should chown the key file to the user" do + uid = Puppet::Util.uid("nobody") + File.expects(:chown).with(uid, nil, File.expand_path("~nobody/.ssh/authorized_keys")) + @provider.flush + end + + it "should chmod the key file to 0600" do + File.chmod(0600, File.expand_path("~nobody/.ssh/authorized_keys")) + @provider.flush + end + end + + describe "and a target has been specified" do + before :each do + @resource.stubs(:should).with(:user).returns nil + @resource.stubs(:should).with(:target).returns "/tmp/.ssh/authorized_keys" + end + + it "should make the directory" do + Dir.expects(:mkdir).with("/tmp/.ssh", 0755) + @provider.flush + end + + it "should chmod the key file to 0644" do + File.expects(:chmod).with(0644, "/tmp/.ssh/authorized_keys") + @provider.flush + end + end - @provider.parse_options(optionstr).should == options end end diff --git a/spec/unit/rails.rb b/spec/unit/rails.rb index f0ba2b942..48e0ab321 100755 --- a/spec/unit/rails.rb +++ b/spec/unit/rails.rb @@ -7,7 +7,8 @@ describe Puppet::Rails, "when initializing any connection" do confine "Cannot test without ActiveRecord" => Puppet.features.rails? before do - @logger = stub 'logger', :level= => nil + Puppet.settings.stubs(:use) + @logger = mock 'logger' @logger.stub_everything Logger.stubs(:new).returns(@logger) diff --git a/spec/unit/transaction.rb b/spec/unit/transaction.rb index 554d20ce9..efd071231 100755 --- a/spec/unit/transaction.rb +++ b/spec/unit/transaction.rb @@ -4,6 +4,21 @@ require File.dirname(__FILE__) + '/../spec_helper' require 'puppet/transaction' +describe Puppet::Transaction do + it "should match resources by name, not title, when prefetching" do + @catalog = Puppet::Node::Catalog.new + @transaction = Puppet::Transaction.new(@catalog) + + # Have both a title and name + resource = Puppet::Type.type(:sshkey).create :title => "foo", :name => "bar", :type => :dsa, :key => "eh" + @catalog.add_resource resource + + resource.provider.class.expects(:prefetch).with("bar" => resource) + + @transaction.prefetch + end +end + describe Puppet::Transaction, " when determining tags" do before do @config = Puppet::Resource::Catalog.new diff --git a/spec/unit/type/file.rb b/spec/unit/type/file.rb index 0187cc41d..094596966 100755 --- a/spec/unit/type/file.rb +++ b/spec/unit/type/file.rb @@ -4,6 +4,8 @@ require File.dirname(__FILE__) + '/../../spec_helper' describe Puppet::Type.type(:file) do before do + Puppet.settings.stubs(:use) + @path = Tempfile.new("puppetspec") pathname = @path.path @path.close!() diff --git a/spec/unit/type/group.rb b/spec/unit/type/group.rb index c9a7fc904..fad7a0c48 100755 --- a/spec/unit/type/group.rb +++ b/spec/unit/type/group.rb @@ -4,6 +4,9 @@ require File.dirname(__FILE__) + '/../../spec_helper' describe Puppet::Type.type(:group) do before do + unless ENV["PATH"].split(File::PATH_SEPARATOR).include?("/usr/sbin") + ENV["PATH"] += File::PATH_SEPARATOR + "/usr/sbin" + end @class = Puppet::Type.type(:group) end diff --git a/spec/unit/type/noop_metaparam.rb b/spec/unit/type/noop_metaparam.rb index 98cb0409e..2c4b6dc49 100755 --- a/spec/unit/type/noop_metaparam.rb +++ b/spec/unit/type/noop_metaparam.rb @@ -6,6 +6,7 @@ require 'puppet/type' describe Puppet::Type.type(:file).attrclass(:noop) do before do + Puppet.settings.stubs(:use) @file = Puppet::Type.newfile :path => "/what/ever" end diff --git a/spec/unit/type/ssh_authorized_key.rb b/spec/unit/type/ssh_authorized_key.rb index 9a2389eef..db389864e 100755 --- a/spec/unit/type/ssh_authorized_key.rb +++ b/spec/unit/type/ssh_authorized_key.rb @@ -89,13 +89,36 @@ describe ssh_authorized_key do @class.attrtype(:target).should == :property end - it "should raise an error when neither user nor target is given" do - proc do - @class.new( - :name => "Test", - :key => "AAA", - :type => "ssh-rsa", - :ensure => :present) - end.should raise_error(Puppet::Error) + describe "when neither user nor target is specified" do + it "should raise an error" do + proc do + @class.create( + :name => "Test", + :key => "AAA", + :type => "ssh-rsa", + :ensure => :present) + end.should raise_error(Puppet::Error) + end + end + + describe "when both target and user are specified" do + it "should use target" do + resource = @class.create( + :name => "Test", + :user => "root", + :target => "/tmp/blah") + resource.should(:target).should == "/tmp/blah" + end + end + + + describe "when user is specified" do + it "should determine target" do + resource = @class.create( + :name => "Test", + :user => "root") + target = File.expand_path("~root/.ssh/authorized_keys") + resource.should(:target).should == target + end end end diff --git a/spec/unit/type/tidy.rb b/spec/unit/type/tidy.rb index 72f6b0f10..e17f65de4 100755 --- a/spec/unit/type/tidy.rb +++ b/spec/unit/type/tidy.rb @@ -2,13 +2,26 @@ require File.dirname(__FILE__) + '/../../spec_helper' -describe Puppet::Type.type(:tidy) do +tidy = Puppet::Type.type(:tidy) + +describe tidy do + before do + Puppet.settings.stubs(:use) + end + it "should use :lstat when stating a file" do tidy = Puppet::Type.type(:tidy).new :path => "/foo/bar", :age => "1d" stat = mock 'stat' File.expects(:lstat).with("/foo/bar").returns stat tidy.stat("/foo/bar").should == stat end + + it "should be in sync if the targeted file does not exist" do + File.expects(:lstat).with("/tmp/foonesslaters").raises Errno::ENOENT + @tidy = tidy.create :path => "/tmp/foonesslaters", :age => "100d" + + @tidy.property(:ensure).must be_insync({}) + end [:age, :size, :path, :matches, :type, :recurse, :rmdirs].each do |param| it "should have a %s parameter" % param do diff --git a/spec/unit/type/user.rb b/spec/unit/type/user.rb index 57af7f093..bf2af23ab 100755 --- a/spec/unit/type/user.rb +++ b/spec/unit/type/user.rb @@ -6,6 +6,9 @@ user = Puppet::Type.type(:user) describe user do before do + unless ENV["PATH"].split(File::PATH_SEPARATOR).include?("/usr/sbin") + ENV["PATH"] += File::PATH_SEPARATOR + "/usr/sbin" + end @provider = stub 'provider' @resource = stub 'resource', :resource => nil, :provider => @provider, :line => nil, :file => nil end |