From 15e225b5ef80a92f1d9ec25ca518601519f6ffe9 Mon Sep 17 00:00:00 2001 From: Dominic Cleal Date: Sun, 20 Feb 2011 11:37:55 +0000 Subject: Add spec tests for pkgutil package provider --- spec/unit/provider/package/pkgutil_spec.rb | 132 +++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100755 spec/unit/provider/package/pkgutil_spec.rb (limited to 'spec') diff --git a/spec/unit/provider/package/pkgutil_spec.rb b/spec/unit/provider/package/pkgutil_spec.rb new file mode 100755 index 000000000..10cebfed1 --- /dev/null +++ b/spec/unit/provider/package/pkgutil_spec.rb @@ -0,0 +1,132 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../../spec_helper' + +provider = Puppet::Type.type(:package).provider(:pkgutil) + +describe provider do + before(:each) do + @resource = stub 'resource' + @resource = Puppet::Type.type(:package).new(:name => "TESTpkg", :ensure => :present) + @provider = provider.new(@resource) + end + + it "should have an install method" do + @provider.should respond_to(:install) + end + + it "should have a latest method" do + @provider.should respond_to(:uninstall) + end + + it "should have an update method" do + @provider.should respond_to(:update) + end + + it "should have a latest method" do + @provider.should respond_to(:latest) + end + + describe "when installing" do + it "should use a command without versioned package" do + @resource[:ensure] = :latest + @provider.expects(:pkguti).with('-y', '-i', 'TESTpkg') + @provider.install + end + end + + describe "when updating" do + it "should use a command without versioned package" do + @provider.expects(:pkguti).with('-y', '-i', 'TESTpkg') + @provider.update + end + end + + describe "when uninstalling" do + it "should call the remove operation" do + @provider.expects(:pkguti).with('-y', '-r', 'TESTpkg') + @provider.uninstall + end + end + + describe "when getting latest version" do + it "should return TESTpkg's version string" do + fake_data = " +CSWsvn 1.4.5,REV=2007.11.18 SAME +TESTpkg 1.4.5,REV=2007.11.18 1.4.5,REV=2007.11.20 +CSWemacs notinst 22.1" + provider.expects(:pkguti).with(['-c', '--single', 'TESTpkg']).returns fake_data + @provider.latest.should == "1.4.5,REV=2007.11.20" + end + + it "should handle TESTpkg's 'SAME' version string" do + fake_data = " +CSWsvn 1.4.5,REV=2007.11.18 SAME +TESTpkg 1.4.5,REV=2007.11.18 SAME +CSWemacs notinst 22.1" + provider.expects(:pkguti).with(['-c', '--single', 'TESTpkg']).returns fake_data + @provider.latest.should == "1.4.5,REV=2007.11.18" + end + + it "should handle a non-existent package" do + fake_data = "CSWsvn 1.4.5,REV=2007.11.18 SAME" + provider.expects(:pkguti).with(['-c', '--single', 'TESTpkg']).returns fake_data + @provider.latest.should == nil + end + + it "should warn on unknown pkgutil noise" do + provider.expects(:pkguti).returns("testingnoise") + Puppet.expects(:warning) + provider.expects(:new).never + provider.instances.should == [] + end + + it "should ignore pkgutil noise/headers to find TESTpkg" do + fake_data = "# stuff +=> Fetching new catalog and descriptions (http://mirror.opencsw.org/opencsw/unstable/i386/5.11) if available ... +2011-02-19 23:05:46 URL:http://mirror.opencsw.org/opencsw/unstable/i386/5.11/catalog [534635/534635] -> \"/var/opt/csw/pkgutil/catalog.mirror.opencsw.org_opencsw_unstable_i386_5.11.tmp\" [1] +Checking integrity of /var/opt/csw/pkgutil/catalog.mirror.opencsw.org_opencsw_unstable_i386_5.11 with gpg. +gpg: Signature made February 17, 2011 05:27:53 PM GMT using DSA key ID E12E9D2F +gpg: Good signature from \"Distribution Manager \" +==> 2770 packages loaded from /var/opt/csw/pkgutil/catalog.mirror.opencsw.org_opencsw_unstable_i386_5.11 +package installed catalog +TESTpkg 1.4.5,REV=2007.11.18 1.4.5,REV=2007.11.20 +testingnoise +testing noise again" + provider.expects(:pkguti).returns fake_data + @provider.latest.should == "1.4.5,REV=2007.11.20" + end + end + + describe "when querying current version" do + it "should return TESTpkg's version string" do + fake_data = "TESTpkg 1.4.5,REV=2007.11.18 1.4.5,REV=2007.11.20" + provider.expects(:pkguti).with(['-c', '--single', 'TESTpkg']).returns fake_data + @provider.query[:ensure].should == "1.4.5,REV=2007.11.18" + end + + it "should handle a package that isn't installed" do + fake_data = "TESTpkg notinst 1.4.5,REV=2007.11.20" + provider.expects(:pkguti).with(['-c', '--single', 'TESTpkg']).returns fake_data + @provider.query[:ensure].should == :absent + end + + it "should handle a non-existent package" do + fake_data = "CSWsvn 1.4.5,REV=2007.11.18 SAME" + provider.expects(:pkguti).with(['-c', '--single', 'TESTpkg']).returns fake_data + @provider.query[:ensure].should == :absent + end + end + + describe "when querying current instances" do + it "should return TESTpkg's version string" do + fake_data = "TESTpkg 1.4.5,REV=2007.11.18 1.4.5,REV=2007.11.20" + provider.expects(:pkguti).with(['-c']).returns fake_data + + testpkg = mock 'pkg1' + provider.expects(:new).with(:ensure => "1.4.5,REV=2007.11.18", :name => "TESTpkg", :provider => :pkgutil).returns testpkg + provider.instances.should == [testpkg] + end + end + +end -- cgit From ab5bc35eac89001f1c8c8358f4489efda8315e9c Mon Sep 17 00:00:00 2001 From: Dominic Cleal Date: Fri, 18 Mar 2011 23:18:41 +0000 Subject: (#4258) Update pkgutil spec for recent impl changes Fix test output of pkgutil for commands using --single Fix expected upgrade command to match impl --- spec/unit/provider/package/pkgutil_spec.rb | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'spec') diff --git a/spec/unit/provider/package/pkgutil_spec.rb b/spec/unit/provider/package/pkgutil_spec.rb index 10cebfed1..01142b4e0 100755 --- a/spec/unit/provider/package/pkgutil_spec.rb +++ b/spec/unit/provider/package/pkgutil_spec.rb @@ -37,7 +37,7 @@ describe provider do describe "when updating" do it "should use a command without versioned package" do - @provider.expects(:pkguti).with('-y', '-i', 'TESTpkg') + @provider.expects(:pkguti).with('-y', '-u', 'TESTpkg') @provider.update end end @@ -52,24 +52,22 @@ describe provider do describe "when getting latest version" do it "should return TESTpkg's version string" do fake_data = " -CSWsvn 1.4.5,REV=2007.11.18 SAME -TESTpkg 1.4.5,REV=2007.11.18 1.4.5,REV=2007.11.20 -CSWemacs notinst 22.1" +noisy output here +TESTpkg 1.4.5,REV=2007.11.18 1.4.5,REV=2007.11.20" provider.expects(:pkguti).with(['-c', '--single', 'TESTpkg']).returns fake_data @provider.latest.should == "1.4.5,REV=2007.11.20" end it "should handle TESTpkg's 'SAME' version string" do fake_data = " -CSWsvn 1.4.5,REV=2007.11.18 SAME -TESTpkg 1.4.5,REV=2007.11.18 SAME -CSWemacs notinst 22.1" +noisy output here +TESTpkg 1.4.5,REV=2007.11.18 SAME" provider.expects(:pkguti).with(['-c', '--single', 'TESTpkg']).returns fake_data @provider.latest.should == "1.4.5,REV=2007.11.18" end it "should handle a non-existent package" do - fake_data = "CSWsvn 1.4.5,REV=2007.11.18 SAME" + fake_data = "noisy output here" provider.expects(:pkguti).with(['-c', '--single', 'TESTpkg']).returns fake_data @provider.latest.should == nil end @@ -90,10 +88,8 @@ gpg: Signature made February 17, 2011 05:27:53 PM GMT using DSA key ID E12E9D2F gpg: Good signature from \"Distribution Manager \" ==> 2770 packages loaded from /var/opt/csw/pkgutil/catalog.mirror.opencsw.org_opencsw_unstable_i386_5.11 package installed catalog -TESTpkg 1.4.5,REV=2007.11.18 1.4.5,REV=2007.11.20 -testingnoise -testing noise again" - provider.expects(:pkguti).returns fake_data +TESTpkg 1.4.5,REV=2007.11.18 1.4.5,REV=2007.11.20" + provider.expects(:pkguti).with(['-c', '--single', 'TESTpkg']).returns fake_data @provider.latest.should == "1.4.5,REV=2007.11.20" end end @@ -112,7 +108,7 @@ testing noise again" end it "should handle a non-existent package" do - fake_data = "CSWsvn 1.4.5,REV=2007.11.18 SAME" + fake_data = "noisy output here" provider.expects(:pkguti).with(['-c', '--single', 'TESTpkg']).returns fake_data @provider.query[:ensure].should == :absent end -- cgit From 7c99dd966845fde026178a50b62c52735b2e5a1b Mon Sep 17 00:00:00 2001 From: Dominic Cleal Date: Sat, 19 Mar 2011 00:07:30 +0000 Subject: (#4258) Use pkgutil -a to reliably determine package common names/aliases Populate instances with both the real package name ("CSWsvn") and the alias name ("subversion") from separate "pkgutil -a" call. Fixed cases where pkgutil noise was parsed as aliased package names and also breaking "not in catalog" detection. Updated pkgutil_spec test to show various edge cases. --- spec/unit/provider/package/pkgutil_spec.rb | 60 +++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 6 deletions(-) (limited to 'spec') diff --git a/spec/unit/provider/package/pkgutil_spec.rb b/spec/unit/provider/package/pkgutil_spec.rb index 01142b4e0..4f0e0ccd7 100755 --- a/spec/unit/provider/package/pkgutil_spec.rb +++ b/spec/unit/provider/package/pkgutil_spec.rb @@ -67,16 +67,15 @@ TESTpkg 1.4.5,REV=2007.11.18 SAME" end it "should handle a non-existent package" do - fake_data = "noisy output here" + fake_data = "noisy output here +Not in catalog" provider.expects(:pkguti).with(['-c', '--single', 'TESTpkg']).returns fake_data @provider.latest.should == nil end it "should warn on unknown pkgutil noise" do - provider.expects(:pkguti).returns("testingnoise") - Puppet.expects(:warning) - provider.expects(:new).never - provider.instances.should == [] + provider.expects(:pkguti).with(['-c', '--single', 'TESTpkg']).returns("testingnoise") + @provider.latest.should == nil end it "should ignore pkgutil noise/headers to find TESTpkg" do @@ -92,6 +91,14 @@ TESTpkg 1.4.5,REV=2007.11.18 1.4.5,REV=2007.11.20" provider.expects(:pkguti).with(['-c', '--single', 'TESTpkg']).returns fake_data @provider.latest.should == "1.4.5,REV=2007.11.20" end + + it "should find REALpkg via an alias (TESTpkg)" do + fake_data = " +noisy output here +REALpkg 1.4.5,REV=2007.11.18 1.4.5,REV=2007.11.20" + provider.expects(:pkguti).with(['-c', '--single', 'TESTpkg']).returns fake_data + @provider.query[:name].should == "TESTpkg" + end end describe "when querying current version" do @@ -108,14 +115,26 @@ TESTpkg 1.4.5,REV=2007.11.18 1.4.5,REV=2007.11.20" end it "should handle a non-existent package" do - fake_data = "noisy output here" + fake_data = "noisy output here +Not in catalog" provider.expects(:pkguti).with(['-c', '--single', 'TESTpkg']).returns fake_data @provider.query[:ensure].should == :absent end end describe "when querying current instances" do + it "should warn on unknown pkgutil noise" do + provider.expects(:pkguti).with(['-a']).returns("testingnoise") + provider.expects(:pkguti).with(['-c']).returns("testingnoise") + Puppet.expects(:warning).times(2) + provider.expects(:new).never + provider.instances.should == [] + end + it "should return TESTpkg's version string" do + fake_data = "TESTpkg TESTpkg 1.4.5,REV=2007.11.20" + provider.expects(:pkguti).with(['-a']).returns fake_data + fake_data = "TESTpkg 1.4.5,REV=2007.11.18 1.4.5,REV=2007.11.20" provider.expects(:pkguti).with(['-c']).returns fake_data @@ -123,6 +142,35 @@ TESTpkg 1.4.5,REV=2007.11.18 1.4.5,REV=2007.11.20" provider.expects(:new).with(:ensure => "1.4.5,REV=2007.11.18", :name => "TESTpkg", :provider => :pkgutil).returns testpkg provider.instances.should == [testpkg] end + + it "should also return both TESTpkg and mypkg alias instances" do + fake_data = "mypkg TESTpkg 1.4.5,REV=2007.11.20" + provider.expects(:pkguti).with(['-a']).returns fake_data + + fake_data = "TESTpkg 1.4.5,REV=2007.11.18 1.4.5,REV=2007.11.20" + provider.expects(:pkguti).with(['-c']).returns fake_data + + testpkg = mock 'pkg1' + provider.expects(:new).with(:ensure => "1.4.5,REV=2007.11.18", :name => "TESTpkg", :provider => :pkgutil).returns testpkg + + aliaspkg = mock 'pkg2' + provider.expects(:new).with(:ensure => "1.4.5,REV=2007.11.18", :name => "mypkg", :provider => :pkgutil).returns aliaspkg + + provider.instances.should == [testpkg,aliaspkg] + end + + it "shouldn't mind noise in the -a output" do + fake_data = "noisy output here" + provider.expects(:pkguti).with(['-a']).returns fake_data + + fake_data = "TESTpkg 1.4.5,REV=2007.11.18 1.4.5,REV=2007.11.20" + provider.expects(:pkguti).with(['-c']).returns fake_data + + testpkg = mock 'pkg1' + provider.expects(:new).with(:ensure => "1.4.5,REV=2007.11.18", :name => "TESTpkg", :provider => :pkgutil).returns testpkg + + provider.instances.should == [testpkg] + end end end -- cgit From f8c2f1afa4a9ef71681a96b83b2abdc303a4b0bf Mon Sep 17 00:00:00 2001 From: Dominic Cleal Date: Wed, 13 Apr 2011 09:44:04 +0100 Subject: (#4258) Stop file and config checks from breaking spec Moved all file and config checks into healthcheck method which is then stubbed in the spec. --- spec/unit/provider/package/pkgutil_spec.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'spec') diff --git a/spec/unit/provider/package/pkgutil_spec.rb b/spec/unit/provider/package/pkgutil_spec.rb index 4f0e0ccd7..f1d21f450 100755 --- a/spec/unit/provider/package/pkgutil_spec.rb +++ b/spec/unit/provider/package/pkgutil_spec.rb @@ -9,6 +9,9 @@ describe provider do @resource = stub 'resource' @resource = Puppet::Type.type(:package).new(:name => "TESTpkg", :ensure => :present) @provider = provider.new(@resource) + + # Stub all file and config tests + provider.stubs(:healthcheck) end it "should have an install method" do -- cgit From 174e87a9b150a06a4ff9d696a6008fc08b05568b Mon Sep 17 00:00:00 2001 From: Matt Robinson Date: Thu, 14 Apr 2011 11:33:03 -0700 Subject: (#4258) Fix pkgutil spec test to have the correct provider The resource being used for testing didn't explicitly set the provider, so it ended up using whatever the default provider was on the system on which it was run. This was problematic when running the specs on a Mac since the default provider is pkgdmg and that provider doesn't seem to be upgradeable. So when you tried: @resource[:ensure] = :latest You got the error: 1) Puppet::Type::Package::ProviderPkgutil when installing should use a command without versioned package Failure/Error: @resource[:ensure] = :latest Puppet::Error: Parameter ensure failed: Provider must have features 'upgradeable' to set 'ensure' to 'latest' # ./lib/puppet/parameter.rb:171:in `fail' # ./lib/puppet/parameter.rb:257:in `validate' # ./lib/puppet/property.rb:300:in `should=' # ./lib/puppet/property.rb:300:in `each' # ./lib/puppet/property.rb:300:in `should=' # ./lib/puppet/property.rb:337:in `value=' # ./lib/puppet/type.rb:416:in `[]=' # ./spec/unit/provider/package/pkgutil_spec.rb:35 Reviewed-by: Daniel Pittman --- spec/unit/provider/package/pkgutil_spec.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'spec') diff --git a/spec/unit/provider/package/pkgutil_spec.rb b/spec/unit/provider/package/pkgutil_spec.rb index f1d21f450..5549b3f6d 100755 --- a/spec/unit/provider/package/pkgutil_spec.rb +++ b/spec/unit/provider/package/pkgutil_spec.rb @@ -6,8 +6,11 @@ provider = Puppet::Type.type(:package).provider(:pkgutil) describe provider do before(:each) do - @resource = stub 'resource' - @resource = Puppet::Type.type(:package).new(:name => "TESTpkg", :ensure => :present) + @resource = Puppet::Type.type(:package).new( + :name => "TESTpkg", + :ensure => :present, + :provider => :pkgutil + ) @provider = provider.new(@resource) # Stub all file and config tests -- cgit