~ubuntu-branches/ubuntu/lucid/puppet/lucid-security

« back to all changes in this revision

Viewing changes to spec/unit/provider/package/pkgdmg.rb

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2009-12-23 00:48:10 UTC
  • mfrom: (1.1.10 upstream) (3.1.7 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091223004810-3i4oryds922g5n59
Tags: 0.25.1-3ubuntu1
* Merge from debian testing.  Remaining changes:
  - debian/rules:
    + Don't start puppet when first installing puppet.
  - debian/puppet.conf, lib/puppet/defaults.rb:
    + Move templates to /etc/puppet
  - lib/puppet/defaults.rb:
    + Fix /var/lib/puppet/state ownership.
  - man/man8/puppet.conf.8: 
    + Fix broken URL in manpage.
  - debian/control:
    + Update maintainer accordint to spec.
    + Puppetmaster Recommends -> Suggests
    + Created puppet-testsuite as a seperate. Allow the users to run puppet's 
      testsuite.
  - tests/Rakefile: Fix rakefile so that the testsuite can acutally be ran.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env ruby
 
2
 
 
3
Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f) : Dir.chdir("..") { s.call(f) } }).call("spec/spec_helper.rb") }
 
4
 
 
5
provider = Puppet::Type.type(:package).provider(:pkgdmg)
 
6
 
 
7
describe provider do
 
8
    before do
 
9
        @resource = stub 'resource', :[] => "dummypkgdmg"
 
10
        @provider = provider.new(@resource)
 
11
 
 
12
        @fakemountpoint = "/tmp/dmg.foo"
 
13
        @fakehdiutilinfo = {"system-entities" => [{"mount-point" => @fakemountpoint}] }
 
14
        @fakehdiutilplist = Plist::Emit.dump(@fakehdiutilinfo)
 
15
 
 
16
        @hdiutilmountargs = ["mount", "-plist", "-nobrowse", "-readonly",
 
17
                             "-noidme", "-mountrandom", "/tmp"]
 
18
    end
 
19
 
 
20
    it "should not be versionable" do
 
21
        provider.versionable?.should be_false
 
22
    end
 
23
 
 
24
    it "should not be uninstallable" do
 
25
        provider.uninstallable?.should be_false
 
26
    end
 
27
 
 
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)
 
32
        end
 
33
 
 
34
        it "no name is specified" do
 
35
            @resource.stubs(:[]).with(:name).returns nil
 
36
            lambda { @provider.install }.should raise_error(Puppet::Error)
 
37
        end
 
38
 
 
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)
 
42
        end
 
43
 
 
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)
 
47
        end
 
48
    end
 
49
 
 
50
    # These tests shouldn't be this messy. The pkgdmg provider needs work...
 
51
    describe "when installing" do
 
52
        before 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
 
57
        end
 
58
 
 
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
 
63
            @provider.install
 
64
        end
 
65
 
 
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 ""
 
70
            @provider.install
 
71
        end
 
72
    end
 
73
end