3
Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f) : Dir.chdir("..") { s.call(f) } }).call("spec/spec_helper.rb") }
5
provider = Puppet::Type.type(:package).provider(:pkgdmg)
9
@resource = stub 'resource', :[] => "dummypkgdmg"
10
@provider = provider.new(@resource)
12
@fakemountpoint = "/tmp/dmg.foo"
13
@fakehdiutilinfo = {"system-entities" => [{"mount-point" => @fakemountpoint}] }
14
@fakehdiutilplist = Plist::Emit.dump(@fakehdiutilinfo)
16
@hdiutilmountargs = ["mount", "-plist", "-nobrowse", "-readonly",
17
"-noidme", "-mountrandom", "/tmp"]
20
it "should not be versionable" do
21
provider.versionable?.should be_false
24
it "should not be uninstallable" do
25
provider.uninstallable?.should be_false
28
describe "when installing it should fail when" do
29
it "no source is specified" do
30
@resource.stubs(:[]).with(:source).returns nil
31
lambda { @provider.install }.should raise_error(Puppet::Error)
34
it "no name is specified" do
35
@resource.stubs(:[]).with(:name).returns nil
36
lambda { @provider.install }.should raise_error(Puppet::Error)
39
it "the source does not end in .dmg" do
40
@resource.stubs(:[]).with(:source).returns "notendingindotdmg"
41
lambda { @provider.install }.should raise_error(Puppet::Error)
44
it "a disk image with no system entities is mounted" do
45
@provider.stubs(:[]).with(:hdiutil).returns ""
46
lambda { @provider.install }.should raise_error(Puppet::Error)
50
# These tests shouldn't be this messy. The pkgdmg provider needs work...
51
describe "when installing" do
53
fh = mock 'filehandle'
54
fh.stubs(:path).yields "/tmp/foo"
55
@resource.stubs(:[]).with(:source).returns "foo.dmg"
56
File.stubs(:open).yields fh
59
it "should call hdiutil to mount and eject the disk image" do
60
Dir.stubs(:entries).returns []
61
@provider.class.expects(:hdiutil).with("eject", @fakemountpoint).returns 0
62
@provider.class.expects(:hdiutil).with("mount", "-plist", "-nobrowse", "-readonly", "-noidme", "-mountrandom", "/tmp", nil).returns @fakehdiutilplist
66
it "should call installpkg if a pkg/mpkg is found on the dmg" do
67
Dir.stubs(:entries).returns ["foo.pkg"]
68
@provider.class.stubs(:hdiutil).returns @fakehdiutilplist
69
@provider.class.expects(:installpkg).with("#{@fakemountpoint}/foo.pkg", @resource[:name], "foo.dmg").returns ""