From 373d505c381696f880c305a9357a6e50342079b8 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Thu, 12 Feb 2009 23:42:31 -0600 Subject: Adding a FileCollection and a lookup module for it. Signed-off-by: Luke Kanies --- spec/unit/file_collection.rb | 45 +++++++++++++++++++++++++++++++++++++ spec/unit/file_collection/lookup.rb | 41 +++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100755 spec/unit/file_collection.rb create mode 100755 spec/unit/file_collection/lookup.rb (limited to 'spec') diff --git a/spec/unit/file_collection.rb b/spec/unit/file_collection.rb new file mode 100755 index 000000000..e9acc8dd2 --- /dev/null +++ b/spec/unit/file_collection.rb @@ -0,0 +1,45 @@ +#!/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 +end diff --git a/spec/unit/file_collection/lookup.rb b/spec/unit/file_collection/lookup.rb new file mode 100755 index 000000000..9ae7ae582 --- /dev/null +++ b/spec/unit/file_collection/lookup.rb @@ -0,0 +1,41 @@ +#!/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' + @tester.stubs(:file_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 +end -- cgit From fa6494b69ad1b01a9c587c86aa1731f4702f5509 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Fri, 13 Feb 2009 00:29:07 -0600 Subject: Using the FileCollection where appropriate. This commit just replaces the :file and :line accessors with the use of the new FileCollection Lookup module. This should mean that we've normalized all file names in a given process, which *might* have drastic RAM improvements. For initial simplicity, I've gone with a single global collection of file names, but it's built so it's easy to use individual file collections instead. Signed-off-by: Luke Kanies --- spec/unit/file_collection.rb | 8 ++++++++ spec/unit/file_collection/lookup.rb | 7 ++++++- spec/unit/parser/ast.rb | 6 +++++- spec/unit/parser/resource.rb | 4 ++++ spec/unit/parser/resource/reference.rb | 4 ++++ 5 files changed, 27 insertions(+), 2 deletions(-) (limited to 'spec') diff --git a/spec/unit/file_collection.rb b/spec/unit/file_collection.rb index e9acc8dd2..81bcc2d2d 100755 --- a/spec/unit/file_collection.rb +++ b/spec/unit/file_collection.rb @@ -42,4 +42,12 @@ describe Puppet::FileCollection do 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 index 9ae7ae582..81cc61872 100755 --- a/spec/unit/file_collection/lookup.rb +++ b/spec/unit/file_collection/lookup.rb @@ -12,7 +12,7 @@ describe Puppet::FileCollection::Lookup do @tester = LookupTester.new @file_collection = mock 'file_collection' - @tester.stubs(:file_collection).returns @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 @@ -38,4 +38,9 @@ describe Puppet::FileCollection::Lookup 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/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 63cfbc2ed..2666f6461 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 -- cgit From c052ff881e4a0cf6edfe4c1974597cd3abb378cf Mon Sep 17 00:00:00 2001 From: Paul Lathrop Date: Fri, 27 Feb 2009 12:25:28 -0800 Subject: Make puppetd --waitforcert option behave as documented: "You can turn off waiting for certificates by specifying a time of 0." Also add a test to ensure we catch any future regression of this behavior. Signed-off-by: Paul Lathrop --- spec/unit/executables/client/certhandler.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'spec') diff --git a/spec/unit/executables/client/certhandler.rb b/spec/unit/executables/client/certhandler.rb index 4f8f8139c..69d6de92b 100755 --- a/spec/unit/executables/client/certhandler.rb +++ b/spec/unit/executables/client/certhandler.rb @@ -91,6 +91,19 @@ describe cert_handler, "when handling certificates" do end end + describe "when waitforcert is disabled" do + before do + @handler = cert_handler.new(0, false) + @handler.stubs(:read_cert).returns false + end + + it "should exit if the cert request does not return a certificate" do + @caclient.stubs(:request_cert).returns(false) + @handler.expects(:exit).with(1).raises(SystemExit) + lambda { @handler.retrieve_cert }.should raise_error(SystemExit) + end + end + describe "when in one time mode" do before do #true puts us in onetime mode -- cgit From 23066c1b117af4d531efad79ee11ed683ac92e5e Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Sat, 28 Feb 2009 06:40:46 +0000 Subject: Fixing every failing test I can find on the build server. All but one of these tests is fixed by: * Stubbing Puppet.settings.use * Adding /usr/sbin to PATH The only other one was the package integration test, which stupidly assumed a default was specified in the test. The fix here is twofold: Remove that assumption (the test is now 'pending' if no default is available), and add a default for Ubuntu. (The default is in the test, not the default package provider - that is, it's testing the default package provider, thus it can't rely on that information.) Signed-off-by: Luke Kanies --- spec/integration/checksum.rb | 1 + spec/integration/reports.rb | 4 ++++ spec/integration/transaction/report.rb | 8 +++++++- spec/integration/type/package.rb | 7 +++++-- spec/unit/indirector/ssl_rsa/file.rb | 5 +++++ spec/unit/node/catalog.rb | 1 + spec/unit/other/transbucket.rb | 8 ++++---- spec/unit/provider/mount/parsed.rb | 1 + spec/unit/rails.rb | 1 + spec/unit/type/file.rb | 2 ++ spec/unit/type/group.rb | 3 +++ spec/unit/type/noop_metaparam.rb | 1 + spec/unit/type/tidy.rb | 4 ++++ spec/unit/type/user.rb | 3 +++ 14 files changed, 42 insertions(+), 7 deletions(-) (limited to 'spec') 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/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 48e59f203..333deac0e 100755 --- a/spec/integration/transaction/report.rb +++ b/spec/integration/transaction/report.rb @@ -7,7 +7,13 @@ require File.dirname(__FILE__) + '/../../spec_helper' describe Puppet::Transaction::Report do describe "when using the indirector" do - after { Puppet::Transaction::Report.indirection.clear_cache } + before do + Puppet.settings.stubs(:use) + end + + after do + Puppet::Transaction::Report.indirection.clear_cache + 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/indirector/ssl_rsa/file.rb b/spec/unit/indirector/ssl_rsa/file.rb index 76e5e3a94..4800f4a71 100755 --- a/spec/unit/indirector/ssl_rsa/file.rb +++ b/spec/unit/indirector/ssl_rsa/file.rb @@ -22,6 +22,7 @@ end describe Puppet::Indirector::SslRsa::File, " when choosing a path for a ca key" do before do + Puppet.settings.stubs(:use) @file = Puppet::Indirector::SslRsa::File.new @name = :ca end @@ -38,6 +39,7 @@ end describe Puppet::Indirector::SslRsa::File, " when choosing a path for a non-ca key" do before do + Puppet.settings.stubs(:use) @file = Puppet::Indirector::SslRsa::File.new @name = :publickey end @@ -54,6 +56,7 @@ end describe Puppet::Indirector::SslRsa::File, " when saving" do before do + Puppet.settings.stubs(:use) @file = Puppet::Indirector::SslRsa::File.new Puppet.settings.stubs(:value).with(:publickeydir).returns("/dir") @@ -72,6 +75,7 @@ end describe Puppet::Indirector::SslRsa::File, " when finding a key by name" do before do + Puppet.settings.stubs(:use) @file = Puppet::Indirector::SslRsa::File.new Puppet.settings.stubs(:value).with(:publickeydir).returns("/dir") @@ -95,6 +99,7 @@ end describe Puppet::Indirector::SslRsa::File, " when removing a key" do before do + Puppet.settings.stubs(:use) @file = Puppet::Indirector::SslRsa::File.new Puppet.settings.stubs(:value).with(:publickeydir).returns("/dir") diff --git a/spec/unit/node/catalog.rb b/spec/unit/node/catalog.rb index be198b88e..f6ef291a5 100755 --- a/spec/unit/node/catalog.rb +++ b/spec/unit/node/catalog.rb @@ -794,6 +794,7 @@ describe Puppet::Node::Catalog, " when writing dot files" do end it "should write a dot file based on the passed name" do + Puppet.settings.stubs(:use) File.expects(:open).with(@file, "w").yields(stub("file", :puts => nil)) @catalog.expects(:to_dot).with("name" => @name.to_s.capitalize) @catalog.host_config = true diff --git a/spec/unit/other/transbucket.rb b/spec/unit/other/transbucket.rb index 4494f2abb..0240a4473 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) @@ -98,7 +98,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/provider/mount/parsed.rb b/spec/unit/provider/mount/parsed.rb index df0e992f8..66891e6bf 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/rails.rb b/spec/unit/rails.rb index 382f7c0f4..694bb55c7 100755 --- a/spec/unit/rails.rb +++ b/spec/unit/rails.rb @@ -7,6 +7,7 @@ describe Puppet::Rails, "when initializing any connection" do confine "Cannot test without ActiveRecord" => Puppet.features.rails? before do + Puppet.settings.stubs(:use) @logger = mock 'logger' @logger.stub_everything Logger.stubs(:new).returns(@logger) diff --git a/spec/unit/type/file.rb b/spec/unit/type/file.rb index 0b7bfa8fb..da03dd349 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") @path.close!() @path = @path.path diff --git a/spec/unit/type/group.rb b/spec/unit/type/group.rb index d7e06dcd8..66a7daf06 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 8510a1b6b..73fed53c1 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/tidy.rb b/spec/unit/type/tidy.rb index 9bcae86d7..3d0ff172b 100755 --- a/spec/unit/type/tidy.rb +++ b/spec/unit/type/tidy.rb @@ -5,6 +5,10 @@ require File.dirname(__FILE__) + '/../../spec_helper' tidy = Puppet::Type.type(:tidy) describe tidy do + before do + Puppet.settings.stubs(:use) + end + after { tidy.clear } it "should be in sync if the targeted file does not exist" do diff --git a/spec/unit/type/user.rb b/spec/unit/type/user.rb index dadcc65ef..4f4f2c0eb 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 -- cgit From 9577d3af929727ac1e7b5e7e54e4491990d55995 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Tue, 3 Mar 2009 23:20:29 -0600 Subject: Fixing #2013 - prefetching had a mismatch between type and title The ParsedFile types seem to be the main one that suffers from this, but the transactions were using the resource titles, not names, so resources were often not getting prefetched correctly. Signed-off-by: Luke Kanies --- spec/unit/transaction.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'spec') diff --git a/spec/unit/transaction.rb b/spec/unit/transaction.rb index e5ec64054..9122e0eb3 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::Node::Catalog.new -- cgit From 61661b1c46fafeabf1bdbc4778762831d7178d91 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Tue, 3 Mar 2009 21:36:56 -0600 Subject: Fixing #1991 - ldap booleans get converted to booleans Signed-off-by: Luke Kanies --- spec/unit/indirector/node/ldap.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'spec') 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" -- cgit From cf48ec0aba120e6e83e48b3499df9029b5302767 Mon Sep 17 00:00:00 2001 From: Bryan Kearney Date: Wed, 18 Feb 2009 12:34:17 -0500 Subject: First cut at the not running if augeas does not change any of the underlieing files --- spec/unit/provider/augeas/augeas.rb | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'spec') diff --git a/spec/unit/provider/augeas/augeas.rb b/spec/unit/provider/augeas/augeas.rb index 2def0d0c4..3ce64576e 100644 --- a/spec/unit/provider/augeas/augeas.rb +++ b/spec/unit/provider/augeas/augeas.rb @@ -60,7 +60,7 @@ describe provider_class 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 @@ -88,7 +88,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 @@ -122,10 +122,12 @@ describe provider_class do end end - describe "need_to_run" do + describe "legacy need to run" do it "should handle no filters" do resource = stub("resource", :[] => "") + augeas_stub = stub("augeas", :match => ["set", "of", "values"]) provider = provider_class.new(resource) + provider.stubs(:get_augeas_version).returns("0.3.5") provider.need_to_run?.should == true end @@ -133,7 +135,8 @@ describe provider_class do resource = stub("resource", :[] => "get path == value") provider = provider_class.new(resource) augeas_stub = stub("augeas", :get => "value") - provider.stubs(:open_augeas).returns(augeas_stub) + provider.aug= augeas_stub + provider.stubs(:get_augeas_version).returns("0.3.5") provider.need_to_run?.should == true end @@ -141,7 +144,8 @@ describe provider_class do resource = stub("resource", :[] => "get path == another value") provider = provider_class.new(resource) augeas_stub = stub("augeas", :get => "value") - provider.stubs(:open_augeas).returns(augeas_stub) + provider.aug= augeas_stub + provider.stubs(:get_augeas_version).returns("0.3.5") provider.need_to_run?.should == false end @@ -149,7 +153,8 @@ describe provider_class do resource = stub("resource", :[] => "match path size == 3") provider = provider_class.new(resource) augeas_stub = stub("augeas", :match => ["set", "of", "values"]) - provider.stubs(:open_augeas).returns(augeas_stub) + provider.aug= augeas_stub + provider.stubs(:get_augeas_version).returns("0.3.5") provider.need_to_run?.should == true end @@ -157,18 +162,20 @@ describe provider_class do resource = stub("resource", :[] => "match path size == 2") provider = provider_class.new(resource) augeas_stub = stub("augeas", :match => ["set", "of", "values"]) - provider.stubs(:open_augeas).returns(augeas_stub) + 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 "legacy augeas 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 -- cgit From cedeb7982b051e00173822c8d14a794e4fb10ae7 Mon Sep 17 00:00:00 2001 From: Bryan Kearney Date: Wed, 18 Feb 2009 12:46:17 -0500 Subject: Backport the fix for #1835 --- spec/unit/provider/augeas/augeas.rb | 80 +++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) (limited to 'spec') diff --git a/spec/unit/provider/augeas/augeas.rb b/spec/unit/provider/augeas/augeas.rb index 3ce64576e..e05812d78 100644 --- a/spec/unit/provider/augeas/augeas.rb +++ b/spec/unit/provider/augeas/augeas.rb @@ -54,6 +54,86 @@ describe provider_class do tokens[0][1].should == "/Jar/Jar" tokens[0][2].should == "Binks is my copilot" end + + it "should accept spaces and and single ticks" do + provider = provider_class.new() + tokens = provider.parse_commands("set 'Jar Jar' Binks") + tokens.size.should == 1 + tokens[0].size.should == 3 + tokens[0][0].should == "set" + tokens[0][1].should == "Jar Jar" + tokens[0][2].should == "Binks" + end + + it "should accept spaces in the value and and single ticks" do + provider = provider_class.new() + tokens = provider.parse_commands("set 'Jar Jar' 'Binks is my copilot'") + tokens.size.should == 1 + tokens[0].size.should == 3 + tokens[0][0].should == "set" + tokens[0][1].should == "Jar Jar" + tokens[0][2].should == "Binks is my copilot" + end + + it "should accept spaces and and double ticks" do + provider = provider_class.new() + tokens = provider.parse_commands('set "Jar Jar" Binks') + tokens.size.should == 1 + tokens[0].size.should == 3 + tokens[0][0].should == "set" + tokens[0][1].should == 'Jar Jar' + tokens[0][2].should == 'Binks' + end + + it "should accept spaces in the value and and double ticks" do + provider = provider_class.new() + tokens = provider.parse_commands('set "Jar Jar" "Binks is my copilot"') + tokens.size.should == 1 + tokens[0].size.should == 3 + tokens[0][0].should == "set" + tokens[0][1].should == 'Jar Jar' + tokens[0][2].should == 'Binks is my copilot' + end + + it "should accept mixed ticks" do + provider = provider_class.new() + tokens = provider.parse_commands('set "Jar Jar" "Some \'Test\'"') + tokens.size.should == 1 + tokens[0].size.should == 3 + tokens[0][0].should == "set" + tokens[0][1].should == 'Jar Jar' + tokens[0][2].should == "Some \'Test\'" + end + + it "should accept only the last value using ticks" do + provider = provider_class.new() + tokens = provider.parse_commands('set /Jar/Jar "Binks is my copilot"') + tokens.size.should == 1 + tokens[0].size.should == 3 + tokens[0][0].should == "set" + tokens[0][1].should == '/Jar/Jar' + tokens[0][2].should == "Binks is my copilot" + end + + it "should accept only the first value using ticks" do + provider = provider_class.new() + tokens = provider.parse_commands('set "Jar Jar" copilot') + tokens.size.should == 1 + tokens[0].size.should == 3 + tokens[0][0].should == "set" + tokens[0][1].should == 'Jar Jar' + tokens[0][2].should == "copilot" + end + + it "should accept only the first value using ticks and the last values being concatenated" do + provider = provider_class.new() + tokens = provider.parse_commands('set "Jar Jar" Binks is my copilot') + tokens.size.should == 1 + tokens[0].size.should == 3 + tokens[0][0].should == "set" + tokens[0][1].should == 'Jar Jar' + tokens[0][2].should == "Binks is my copilot" + end end describe "get filters" do -- cgit From 01bc88c7e2a3d5a71aec8f0727631cbf41680720 Mon Sep 17 00:00:00 2001 From: Bryan Kearney Date: Mon, 23 Feb 2009 11:21:59 -0500 Subject: Added a force option to ensure the change is always applied, and call augeas twice to reduce the chance that data is lost --- spec/unit/provider/augeas/augeas.rb | 212 ++++++++++++++++++++---------------- 1 file changed, 121 insertions(+), 91 deletions(-) (limited to 'spec') diff --git a/spec/unit/provider/augeas/augeas.rb b/spec/unit/provider/augeas/augeas.rb index e05812d78..284145657 100644 --- a/spec/unit/provider/augeas/augeas.rb +++ b/spec/unit/provider/augeas/augeas.rb @@ -10,49 +10,49 @@ describe provider_class do provider = provider_class.new() tokens = provider.parse_commands("set /Jar/Jar Binks") tokens.size.should == 1 - tokens[0].size.should == 3 + tokens[0].size.should == 3 tokens[0][0].should == "set" tokens[0][1].should == "/Jar/Jar" - tokens[0][2].should == "Binks" + tokens[0][2].should == "Binks" end - + it "should break apart a multiple line into six tokens" do provider = provider_class.new() tokens = provider.parse_commands("set /Jar/Jar Binks\nrm anakin skywalker") tokens.size.should == 2 - tokens[0].size.should == 3 - tokens[1].size.should == 3 + tokens[0].size.should == 3 + tokens[1].size.should == 3 tokens[0][0].should == "set" tokens[0][1].should == "/Jar/Jar" - tokens[0][2].should == "Binks" + tokens[0][2].should == "Binks" tokens[1][0].should == "rm" tokens[1][1].should == "anakin" - tokens[1][2].should == "skywalker" - end - + tokens[1][2].should == "skywalker" + end + it "should handle arrays" do provider = provider_class.new() commands = ["set /Jar/Jar Binks", "rm anakin skywalker"] tokens = provider.parse_commands(commands) tokens.size.should == 2 - tokens[0].size.should == 3 - tokens[1].size.should == 3 + tokens[0].size.should == 3 + tokens[1].size.should == 3 tokens[0][0].should == "set" tokens[0][1].should == "/Jar/Jar" - tokens[0][2].should == "Binks" + tokens[0][2].should == "Binks" tokens[1][0].should == "rm" tokens[1][1].should == "anakin" - tokens[1][2].should == "skywalker" - end - + tokens[1][2].should == "skywalker" + end + it "should concat the last values" do provider = provider_class.new() tokens = provider.parse_commands("set /Jar/Jar Binks is my copilot") tokens.size.should == 1 - tokens[0].size.should == 3 + tokens[0].size.should == 3 tokens[0][0].should == "set" tokens[0][1].should == "/Jar/Jar" - tokens[0][2].should == "Binks is my copilot" + tokens[0][2].should == "Binks is my copilot" end it "should accept spaces and and single ticks" do @@ -64,7 +64,7 @@ describe provider_class do tokens[0][1].should == "Jar Jar" tokens[0][2].should == "Binks" end - + it "should accept spaces in the value and and single ticks" do provider = provider_class.new() tokens = provider.parse_commands("set 'Jar Jar' 'Binks is my copilot'") @@ -74,7 +74,7 @@ describe provider_class do tokens[0][1].should == "Jar Jar" tokens[0][2].should == "Binks is my copilot" end - + it "should accept spaces and and double ticks" do provider = provider_class.new() tokens = provider.parse_commands('set "Jar Jar" Binks') @@ -84,7 +84,7 @@ describe provider_class do tokens[0][1].should == 'Jar Jar' tokens[0][2].should == 'Binks' end - + it "should accept spaces in the value and and double ticks" do provider = provider_class.new() tokens = provider.parse_commands('set "Jar Jar" "Binks is my copilot"') @@ -94,7 +94,7 @@ describe provider_class do tokens[0][1].should == 'Jar Jar' tokens[0][2].should == 'Binks is my copilot' end - + it "should accept mixed ticks" do provider = provider_class.new() tokens = provider.parse_commands('set "Jar Jar" "Some \'Test\'"') @@ -104,7 +104,7 @@ describe provider_class do tokens[0][1].should == 'Jar Jar' tokens[0][2].should == "Some \'Test\'" end - + it "should accept only the last value using ticks" do provider = provider_class.new() tokens = provider.parse_commands('set /Jar/Jar "Binks is my copilot"') @@ -114,7 +114,7 @@ describe provider_class do tokens[0][1].should == '/Jar/Jar' tokens[0][2].should == "Binks is my copilot" end - + it "should accept only the first value using ticks" do provider = provider_class.new() tokens = provider.parse_commands('set "Jar Jar" copilot') @@ -124,7 +124,7 @@ describe provider_class do tokens[0][1].should == 'Jar Jar' tokens[0][2].should == "copilot" end - + it "should accept only the first value using ticks and the last values being concatenated" do provider = provider_class.new() tokens = provider.parse_commands('set "Jar Jar" Binks is my copilot') @@ -133,167 +133,193 @@ 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.aug= augeas_stub + @provider = provider_class.new() + @provider.aug= augeas_stub end - + it "should return false for a = nonmatch" do command = ["get", "fake value", "==", "value"] @provider.process_get(command).should == true end - + it "should return true for a != match" do command = ["get", "fake value", "!=", "value"] @provider.process_get(command).should == false - end - + end + it "should return true for a =~ match" do command = ["get", "fake value", "=~", "val*"] @provider.process_get(command).should == true - end - + end + it "should return false for a == nonmatch" do command = ["get", "fake value", "=~", "num*"] @provider.process_get(command).should == false - end + end end - + describe "match filters" do before do augeas_stub = stub("augeas", :match => ["set", "of", "values"]) - @provider = provider_class.new() - @provider.aug= augeas_stub + @provider = provider_class.new() + @provider.aug= augeas_stub end - + it "should return true for size match" do command = ["match", "fake value", "size", "==", "3"] @provider.process_match(command).should == true end - + it "should return false for a size non match" do command = ["match", "fake value", "size", "<", "3"] @provider.process_match(command).should == false - end - + end + it "should return true for includes match" do command = ["get", "fake value", "include", "values"] @provider.process_match(command).should == true - end - + end + it "should return false for includes non match" do command = ["get", "fake value", "include", "JarJar"] @provider.process_match(command).should == false - end - + end + it "should return true for an array match" do command = ["get", "fake value", "==", "['set', 'of', 'values']"] @provider.process_match(command).should == true - end - + end + it "should return false for an array non match" do command = ["get", "fake value", "==", "['this', 'should', 'not', 'match']"] @provider.process_match(command).should == false - end - end - - describe "legacy need to run" do + end + end + + describe "need to run" do it "should handle no filters" do - resource = stub("resource", :[] => "") - augeas_stub = stub("augeas", :match => ["set", "of", "values"]) + 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 + 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") + augeas_stub.stubs("close") provider.aug= augeas_stub - provider.stubs(:get_augeas_version).returns("0.3.5") - provider.need_to_run?.should == true - end - + 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") + augeas_stub.stubs("close") provider.aug= augeas_stub - provider.stubs(:get_augeas_version).returns("0.3.5") - provider.need_to_run?.should == false - end - + 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"]) + augeas_stub.stubs("close") provider.aug= augeas_stub - provider.stubs(:get_augeas_version).returns("0.3.5") - provider.need_to_run?.should == true - end - + 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"]) + augeas_stub.stubs("close") provider.aug= augeas_stub - provider.stubs(:get_augeas_version).returns("0.3.5") - provider.need_to_run?.should == false - end + provider.stubs(:get_augeas_version).returns("0.3.5") + provider.need_to_run?.should == false + end end - - describe "legacy augeas integration" do - + + describe "augeas execution integration" do + before do @resource = stub("resource") @provider = provider_class.new(@resource) @augeas = stub("augeas") @provider.aug= @augeas - @provider.stubs(:get_augeas_version).returns("0.3.5") + @provider.stubs(:get_augeas_version).returns("0.3.5") end - + it "should handle set commands" do command = [["set", "/Jar/Jar", "Binks"]] context = "/some/path" @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 - + it "should handle rm commands" do command = [["rm", "/Jar/Jar"]] context = "" @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 - + end + it "should handle remove commands" do command = [["remove", "Jar/Jar"]] context = "" @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 - + end + it "should handle clear commands" do command = [["clear", "/Jar/Jar"]] context = "/foo" @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"]] @@ -301,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 @@ -310,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 @@ -319,17 +347,19 @@ 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 end end -- cgit From a3bb201bd4c964ab4f68e00895b692d9d9585407 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Fri, 6 Mar 2009 18:11:33 -0600 Subject: Fixing change printing when list properties are absent They were throwing an exception when the 'is' value was 'absent'. Signed-off-by: Luke Kanies --- spec/unit/property/list.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'spec') 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"] -- cgit From 73a0757b559d7e4fbd1da43bbcf4e60fd9155896 Mon Sep 17 00:00:00 2001 From: Brice Figureau Date: Fri, 19 Dec 2008 15:05:29 +0100 Subject: Fix #1828 - Scope.number? wasn't strict enough and could produce wrong results Some invalid numbers were treated as numbers and conversion to Integer was failing returning 0 (for instance 0.24.7). Signed-off-by: Brice Figureau --- spec/unit/parser/scope.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'spec') diff --git a/spec/unit/parser/scope.rb b/spec/unit/parser/scope.rb index fa76c4ff2..13559528b 100755 --- a/spec/unit/parser/scope.rb +++ b/spec/unit/parser/scope.rb @@ -81,7 +81,21 @@ describe Puppet::Parser::Scope do Puppet::Parser::Scope.number?("0755").should == 0755 end + it "should return nil on malformed integers" do + Puppet::Parser::Scope.number?("0.24.5").should be_nil + end + + it "should convert strings with leading 0 to integer if they are not octal" do + Puppet::Parser::Scope.number?("0788").should == 788 + end + it "should convert strings of negative integers" do + Puppet::Parser::Scope.number?("-0788").should == -788 + end + + it "should return nil on malformed hexadecimal numbers" do + Puppet::Parser::Scope.number?("0x89g").should be_nil + end end end -- cgit From 081021af4dda0d19e7de7debb580196219bb7c36 Mon Sep 17 00:00:00 2001 From: Brice Figureau Date: Fri, 19 Dec 2008 17:38:50 +0100 Subject: Fix #1829 - Add puppet function versioncmp to compare versions Signed-off-by: Brice Figureau --- spec/unit/parser/functions/versioncmp.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100755 spec/unit/parser/functions/versioncmp.rb (limited to 'spec') diff --git a/spec/unit/parser/functions/versioncmp.rb b/spec/unit/parser/functions/versioncmp.rb new file mode 100755 index 000000000..06b125ea0 --- /dev/null +++ b/spec/unit/parser/functions/versioncmp.rb @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../../spec_helper' + +describe "the versioncmp function" do + + before :each do + @scope = Puppet::Parser::Scope.new() + end + + it "should exist" do + Puppet::Parser::Functions.function("versioncmp").should == "function_versioncmp" + end + + it "should raise a ParseError if there is less than 2 arguments" do + lambda { @scope.function_versioncmp(["1.2"]) }.should raise_error(Puppet::ParseError) + end + + it "should raise a ParseError if there is more than 2 arguments" do + lambda { @scope.function_versioncmp(["1.2", "2.4.5", "3.5.6"]) }.should raise_error(Puppet::ParseError) + end + + it "should call Puppet::Util::Package.versioncmp (included in scope)" do + Puppet::Util::Package.expects(:versioncmp).with("1.2", "1.3").returns(-1) + + @scope.function_versioncmp(["1.2", "1.3"]) + end + +end -- cgit From 69a0f7dc8d3ba1c64e5acdf99628f10b41ab8e30 Mon Sep 17 00:00:00 2001 From: Brice Figureau Date: Fri, 19 Dec 2008 17:35:08 +0100 Subject: Fix #1807 - make Puppet::Util::Package.versioncmp a module function Signed-off-by: Brice Figureau --- spec/unit/util/package.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 spec/unit/util/package.rb (limited to 'spec') diff --git a/spec/unit/util/package.rb b/spec/unit/util/package.rb new file mode 100644 index 000000000..7d956efb5 --- /dev/null +++ b/spec/unit/util/package.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../spec_helper' + +require 'puppet/util/package' + +describe Puppet::Util::Package, " versioncmp" do + + it "should be able to be used as a module function" do + Puppet::Util::Package.should respond_to(:versioncmp) + end + + it "should be able to sort a long set of various unordered versions" do + ary = %w{ 1.1.6 2.3 1.1a 3.0 1.5 1 2.4 1.1-4 2.3.1 1.2 2.3.0 1.1-3 2.4b 2.4 2.40.2 2.3a.1 3.1 0002 1.1-5 1.1.a 1.06} + + newary = ary.sort { |a, b| Puppet::Util::Package.versioncmp(a,b) } + + newary.should == ["0002", "1", "1.06", "1.1-3", "1.1-4", "1.1-5", "1.1.6", "1.1.a", "1.1a", "1.2", "1.5", "2.3", "2.3.0", "2.3.1", "2.3a.1", "2.4", "2.4", "2.4b", "2.40.2", "3.0", "3.1"] + end + +end -- cgit From bbcda1d5bcab492dc68d331e6f78fb0473e9f046 Mon Sep 17 00:00:00 2001 From: Francois Deppierraz Date: Fri, 28 Nov 2008 15:12:30 +0100 Subject: Fix Bug #1629 A refactoring of ssh_authorized_key parsed provider was needed and tests were improved. flush method has been split for clarity. --- spec/unit/provider/ssh_authorized_key/parsed.rb | 64 +++++++++++++++++++++++++ 1 file changed, 64 insertions(+) (limited to 'spec') diff --git a/spec/unit/provider/ssh_authorized_key/parsed.rb b/spec/unit/provider/ssh_authorized_key/parsed.rb index 21f30f97e..73d623573 100755 --- a/spec/unit/provider/ssh_authorized_key/parsed.rb +++ b/spec/unit/provider/ssh_authorized_key/parsed.rb @@ -100,3 +100,67 @@ describe provider_class do @provider.parse_options(optionstr).should == options end end + +describe provider_class do + before :each do + @resource = stub("resource", :name => "foo") + @resource.stubs(:[]).returns "foo" + @provider = provider_class.new(@resource) + end + + describe "when flushing" do + before :each do + # Stub file and directory operations + Dir.stubs(:mkdir) + File.stubs(:chmod) + File.stubs(:chown) + end + + describe "and a user has been specified" do + before :each do + @resource.stubs(:should).with(:user).returns "nobody" + @resource.stubs(:should).with(:target).returns nil + 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 + + end +end -- cgit From 39deaf373c46c20d14a04391ad4b7c70ad43e266 Mon Sep 17 00:00:00 2001 From: Francois Deppierraz Date: Sat, 21 Mar 2009 23:32:02 +0100 Subject: Fixed #2004 - ssh_authorized_key fails if no target is defined This commit depends on 7f291afdacf59f762c3b78481f5420ec8919e46d (fixing #1629) which was cherry-picked from master. Signed-off-by: Francois Deppierraz --- spec/unit/provider/ssh_authorized_key/parsed.rb | 24 ++------------- spec/unit/type/ssh_authorized_key.rb | 39 ++++++++++++++++++++----- 2 files changed, 33 insertions(+), 30 deletions(-) (limited to 'spec') diff --git a/spec/unit/provider/ssh_authorized_key/parsed.rb b/spec/unit/provider/ssh_authorized_key/parsed.rb index 73d623573..1e5d6be48 100755 --- a/spec/unit/provider/ssh_authorized_key/parsed.rb +++ b/spec/unit/provider/ssh_authorized_key/parsed.rb @@ -72,27 +72,6 @@ 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 - - prov.prefetch - prov.target.should == File.expand_path("~root/.ssh/authorized_keys") - end - - it "should create destination dir" do - # No idea how to test the flush method - end - - it "should set correct default permissions" do - # No idea how to test the flush method - 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(", ") @@ -119,7 +98,8 @@ describe provider_class do describe "and a user has been specified" do before :each do @resource.stubs(:should).with(:user).returns "nobody" - @resource.stubs(:should).with(:target).returns nil + target = File.expand_path("~nobody/.ssh/authorized_keys") + @resource.stubs(:should).with(:target).returns target end it "should create the directory" do diff --git a/spec/unit/type/ssh_authorized_key.rb b/spec/unit/type/ssh_authorized_key.rb index 2cd5171c9..6d60ac2ef 100755 --- a/spec/unit/type/ssh_authorized_key.rb +++ b/spec/unit/type/ssh_authorized_key.rb @@ -89,14 +89,37 @@ 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.create( - :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 after do -- cgit From aa00bdedefcf4dce9c55968e33123a73b78fb6d6 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Sun, 22 Mar 2009 22:00:41 -0500 Subject: Fixing #1631 - adding /sbin and /usr/sbin to PATH This is a trivial fix but seems to crop up more often than it should. Signed-off-by: Luke Kanies --- spec/integration/defaults.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'spec') diff --git a/spec/integration/defaults.rb b/spec/integration/defaults.rb index 54b673a1a..0b2b756bf 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 @@ -44,4 +45,12 @@ describe "Puppet defaults" do it "should default to yaml as the catalog format" do Puppet.settings[:catalog_format].should == "yaml" 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 -- cgit From a677e26eb1452c08d7724047a18e50f4a654d2cd Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Thu, 2 Apr 2009 19:41:17 -0500 Subject: Fixing all tests that were apparently broken in the 0.24.x merge. Signed-off-by: Luke Kanies --- spec/integration/bin/puppetmasterd.rb | 3 ++- spec/unit/provider/augeas/augeas.rb | 1 + spec/unit/transaction.rb | 2 +- spec/unit/type/tidy.rb | 11 ++--------- spec/unit/util/selinux.rb | 5 ++++- 5 files changed, 10 insertions(+), 12 deletions(-) (limited to 'spec') diff --git a/spec/integration/bin/puppetmasterd.rb b/spec/integration/bin/puppetmasterd.rb index 447344472..b5a3f96da 100755 --- a/spec/integration/bin/puppetmasterd.rb +++ b/spec/integration/bin/puppetmasterd.rb @@ -50,7 +50,8 @@ describe "puppetmasterd" do args = arguments + addl_args - output = %x{puppetmasterd #{args}}.chomp + bin = File.join(File.dirname(__FILE__), "..", "..", "..", "sbin", "puppetmasterd") + output = %x{#{bin} #{args}}.chomp end def stop diff --git a/spec/unit/provider/augeas/augeas.rb b/spec/unit/provider/augeas/augeas.rb index 284145657..43fca723c 100644 --- a/spec/unit/provider/augeas/augeas.rb +++ b/spec/unit/provider/augeas/augeas.rb @@ -209,6 +209,7 @@ describe provider_class do augeas_stub = stub("augeas", :match => ["set", "of", "values"]) augeas_stub.stubs("close") provider = provider_class.new(resource) + provider.aug= augeas_stub provider.stubs(:get_augeas_version).returns("0.3.5") provider.need_to_run?.should == true end diff --git a/spec/unit/transaction.rb b/spec/unit/transaction.rb index efd071231..60705c7fb 100755 --- a/spec/unit/transaction.rb +++ b/spec/unit/transaction.rb @@ -6,7 +6,7 @@ require 'puppet/transaction' describe Puppet::Transaction do it "should match resources by name, not title, when prefetching" do - @catalog = Puppet::Node::Catalog.new + @catalog = Puppet::Resource::Catalog.new @transaction = Puppet::Transaction.new(@catalog) # Have both a title and name diff --git a/spec/unit/type/tidy.rb b/spec/unit/type/tidy.rb index e17f65de4..cf244ca0e 100755 --- a/spec/unit/type/tidy.rb +++ b/spec/unit/type/tidy.rb @@ -10,19 +10,12 @@ describe tidy do end it "should use :lstat when stating a file" do - tidy = Puppet::Type.type(:tidy).new :path => "/foo/bar", :age => "1d" + resource = tidy.new :path => "/foo/bar", :age => "1d" stat = mock 'stat' File.expects(:lstat).with("/foo/bar").returns stat - tidy.stat("/foo/bar").should == stat + resource.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 Puppet::Type.type(:tidy).attrclass(param).ancestors.should be_include(Puppet::Parameter) diff --git a/spec/unit/util/selinux.rb b/spec/unit/util/selinux.rb index dacf9f503..db3ee413a 100644 --- a/spec/unit/util/selinux.rb +++ b/spec/unit/util/selinux.rb @@ -31,7 +31,10 @@ describe Puppet::Util::SELinux do describe "filesystem detection" do before :each do - File.expects(:read).with("/proc/mounts").returns "rootfs / rootfs rw 0 0\n/dev/root / ext3 rw,relatime,errors=continue,user_xattr,acl,data=ordered 0 0\n/dev /dev tmpfs rw,relatime,mode=755 0 0\n/proc /proc proc rw,relatime 0 0\n/sys /sys sysfs rw,relatime 0 0\n192.168.1.1:/var/export /mnt/nfs nfs rw,relatime,vers=3,rsize=32768,wsize=32768,namlen=255,hard,nointr,proto=tcp,timeo=600,retrans=2,sec=sys,mountaddr=192.168.1.1,mountvers=3,mountproto=udp,addr=192.168.1.1 0 0\n" + fh = stub 'fh', :close => nil + File.stubs(:open).with("/proc/mounts", File::NONBLOCK).returns fh + fh.stubs(:read).returns "rootfs / rootfs rw 0 0\n/dev/root / ext3 rw,relatime,errors=continue,user_xattr,acl,data=ordered 0 0\n/dev /dev tmpfs rw,relatime,mode=755 0 0\n/proc /proc proc rw,relatime 0 0\n/sys /sys sysfs rw,relatime 0 0\n192.168.1.1:/var/export /mnt/nfs nfs rw,relatime,vers=3,rsize=32768,wsize=32768,namlen=255,hard,nointr,proto=tcp,timeo=600,retrans=2,sec=sys,mountaddr=192.168.1.1,mountvers=3,mountproto=udp,addr=192.168.1.1 0 0\n" + fh.stubs(:close) end it "should parse the contents of /proc/mounts" do -- cgit