summaryrefslogtreecommitdiffstats
path: root/spec/unit
diff options
context:
space:
mode:
authorNigel Kersten <nigelk@google.com>2009-04-09 16:15:28 -0700
committerJames Turnbull <james@lovedthanlost.net>2009-04-22 03:25:07 +1000
commit50e0f3d0161bc4160e36a93d15fba53302b8727b (patch)
treea5d3f1cf66bebbc53d8de0513596aebdd552f2b7 /spec/unit
parentc1be88742d143128ed8240316b6269b585c5084e (diff)
downloadpuppet-50e0f3d0161bc4160e36a93d15fba53302b8727b.tar.gz
puppet-50e0f3d0161bc4160e36a93d15fba53302b8727b.tar.xz
puppet-50e0f3d0161bc4160e36a93d15fba53302b8727b.zip
Fix #2142 - Convert pkgdmg provider to use plists instead of string scanning for future proofing
update pkgdmg patch with feedback from dev-list initial checking of pkgdmg package provider tests clean up fail conditions to raise Puppet::Error instead Finalized tests for pkgdmg provider remove duplicate facter/util/plist require
Diffstat (limited to 'spec/unit')
-rwxr-xr-xspec/unit/provider/package/pkgdmg.rb73
1 files changed, 73 insertions, 0 deletions
diff --git a/spec/unit/provider/package/pkgdmg.rb b/spec/unit/provider/package/pkgdmg.rb
new file mode 100755
index 000000000..ea65ba2d4
--- /dev/null
+++ b/spec/unit/provider/package/pkgdmg.rb
@@ -0,0 +1,73 @@
+#!/usr/bin/env ruby
+
+Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f) : Dir.chdir("..") { s.call(f) } }).call("spec/spec_helper.rb") }
+
+provider = Puppet::Type.type(:package).provider(:pkgdmg)
+
+describe provider do
+ before do
+ @resource = stub 'resource', :[] => "dummypkgdmg"
+ @provider = provider.new(@resource)
+
+ @fakemountpoint = "/tmp/dmg.foo"
+ @fakehdiutilinfo = {"system-entities" => [{"mount-point" => @fakemountpoint}] }
+ @fakehdiutilplist = Plist::Emit.dump(@fakehdiutilinfo)
+
+ @hdiutilmountargs = ["mount", "-plist", "-nobrowse", "-readonly",
+ "-noidme", "-mountrandom", "/tmp"]
+ end
+
+ it "should not be versionable" do
+ provider.versionable?.should be_false
+ end
+
+ it "should not be uninstallable" do
+ provider.uninstallable?.should be_false
+ end
+
+ describe "when installing it should fail when" do
+ it "no source is specified" do
+ @resource.stubs(:[]).with(:source).returns nil
+ lambda { @provider.install }.should raise_error(Puppet::Error)
+ end
+
+ it "no name is specified" do
+ @resource.stubs(:[]).with(:name).returns nil
+ lambda { @provider.install }.should raise_error(Puppet::Error)
+ end
+
+ it "the source does not end in .dmg" do
+ @resource.stubs(:[]).with(:source).returns "notendingindotdmg"
+ lambda { @provider.install }.should raise_error(Puppet::Error)
+ end
+
+ it "a disk image with no system entities is mounted" do
+ @provider.stubs(:[]).with(:hdiutil).returns ""
+ lambda { @provider.install }.should raise_error(Puppet::Error)
+ end
+ end
+
+ # These tests shouldn't be this messy. The pkgdmg provider needs work...
+ describe "when installing" do
+ before do
+ fh = mock 'filehandle'
+ fh.stubs(:path).yields "/tmp/foo"
+ @resource.stubs(:[]).with(:source).returns "foo.dmg"
+ File.stubs(:open).yields fh
+ end
+
+ it "should call hdiutil to mount and eject the disk image" do
+ Dir.stubs(:entries).returns []
+ @provider.class.expects(:hdiutil).with("eject", @fakemountpoint).returns 0
+ @provider.class.expects(:hdiutil).with("mount", "-plist", "-nobrowse", "-readonly", "-noidme", "-mountrandom", "/tmp", nil).returns @fakehdiutilplist
+ @provider.install
+ end
+
+ it "should call installpkg if a pkg/mpkg is found on the dmg" do
+ Dir.stubs(:entries).returns ["foo.pkg"]
+ @provider.class.stubs(:hdiutil).returns @fakehdiutilplist
+ @provider.class.expects(:installpkg).with("#{@fakemountpoint}/foo.pkg", @resource[:name], "foo.dmg").returns ""
+ @provider.install
+ end
+ end
+end