Lines 1-83
Link Here
|
1 |
#!/usr/bin/env rspec |
1 |
#!/usr/bin/env rspec |
2 |
require 'spec_helper' |
2 |
require 'spec_helper' |
3 |
|
3 |
|
4 |
provider = Puppet::Type.type(:package).provider(:pkgdmg) |
4 |
describe Puppet::Type.type(:package).provider(:pkgdmg) do |
|
|
5 |
let(:resource) { Puppet::Type.type(:package).new(:name => 'foo', :provider => :pkgdmg) } |
6 |
let(:provider) { described_class.new(resource) } |
5 |
|
7 |
|
6 |
describe provider do |
8 |
it { should_not be_versionable } |
7 |
before do |
9 |
it { should_not be_uninstallable } |
8 |
@resource = stub 'resource', :[] => "dummypkgdmg" |
|
|
9 |
@provider = provider.new(@resource) |
10 |
|
11 |
@fakemountpoint = "/tmp/dmg.foo" |
12 |
@fakepkgfile = "/tmp/test.pkg" |
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 |
|
10 |
|
28 |
describe "when installing it should fail when" do |
11 |
describe "when installing it should fail when" do |
29 |
it "no source is specified" do |
12 |
before :each do |
30 |
@resource.stubs(:[]).with(:source).returns nil |
13 |
Puppet::Util.expects(:execute).never |
31 |
lambda { @provider.install }.should raise_error(Puppet::Error) |
|
|
32 |
end |
14 |
end |
33 |
|
15 |
|
34 |
it "no name is specified" do |
16 |
it "no source is specified" do |
35 |
@resource.stubs(:[]).with(:name).returns nil |
17 |
expect { provider.install }.should raise_error(Puppet::Error, /must specify a package source/) |
36 |
lambda { @provider.install }.should raise_error(Puppet::Error) |
|
|
37 |
end |
18 |
end |
38 |
|
19 |
|
39 |
it "the source does not end in .dmg or .pkg" do |
20 |
it "the source does not end in .dmg or .pkg" do |
40 |
@resource.stubs(:[]).with(:source).returns "notendingindotdmgorpkg" |
21 |
resource[:source] = "bar" |
41 |
lambda { @provider.install }.should raise_error(Puppet::Error) |
22 |
expect { provider.install }.should raise_error(Puppet::Error, /must specify a source string ending in .*dmg.*pkg/) |
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 |
23 |
end |
48 |
end |
24 |
end |
49 |
|
25 |
|
50 |
# These tests shouldn't be this messy. The pkgdmg provider needs work... |
26 |
# These tests shouldn't be this messy. The pkgdmg provider needs work... |
51 |
describe "when installing a pkgdmg" do |
27 |
describe "when installing a pkgdmg" do |
|
|
28 |
let(:fake_mountpoint) { "/tmp/dmg.foo" } |
29 |
let(:empty_hdiutil_plist) { Plist::Emit.dump({}) } |
30 |
let(:fake_hdiutil_plist) { Plist::Emit.dump({"system-entities" => [{"mount-point" => fake_mountpoint}]}) } |
31 |
|
52 |
before do |
32 |
before do |
53 |
fh = mock 'filehandle' |
33 |
fh = mock 'filehandle' |
54 |
fh.stubs(:path).yields "/tmp/foo" |
34 |
fh.stubs(:path).yields "/tmp/foo" |
55 |
@resource.stubs(:[]).with(:source).returns "foo.dmg" |
35 |
resource[:source] = "foo.dmg" |
56 |
File.stubs(:open).yields fh |
36 |
File.stubs(:open).yields fh |
|
|
37 |
Dir.stubs(:mktmpdir).returns "/tmp/testtmp123" |
38 |
FileUtils.stubs(:remove_entry_secure) |
39 |
end |
40 |
|
41 |
it "should fail when a disk image with no system entities is mounted" do |
42 |
described_class.stubs(:hdiutil).returns(empty_hdiutil_plist) |
43 |
expect { provider.install }.should raise_error(Puppet::Error, /No disk entities/) |
57 |
end |
44 |
end |
58 |
|
45 |
|
59 |
it "should call hdiutil to mount and eject the disk image" do |
46 |
it "should call hdiutil to mount and eject the disk image" do |
60 |
Dir.stubs(:entries).returns [] |
47 |
Dir.stubs(:entries).returns [] |
61 |
@provider.class.expects(:hdiutil).with("eject", @fakemountpoint).returns 0 |
48 |
provider.class.expects(:hdiutil).with("eject", fake_mountpoint).returns 0 |
62 |
@provider.class.expects(:hdiutil).with("mount", "-plist", "-nobrowse", "-readonly", "-noidme", "-mountrandom", "/tmp", nil).returns @fakehdiutilplist |
49 |
provider.class.expects(:hdiutil).with("mount", "-plist", "-nobrowse", "-readonly", "-noidme", "-mountrandom", "/tmp", nil).returns fake_hdiutil_plist |
63 |
@provider.install |
50 |
provider.install |
64 |
end |
51 |
end |
65 |
|
52 |
|
66 |
it "should call installpkg if a pkg/mpkg is found on the dmg" do |
53 |
it "should call installpkg if a pkg/mpkg is found on the dmg" do |
67 |
Dir.stubs(:entries).returns ["foo.pkg"] |
54 |
Dir.stubs(:entries).returns ["foo.pkg"] |
68 |
@provider.class.stubs(:hdiutil).returns @fakehdiutilplist |
55 |
provider.class.stubs(:hdiutil).returns fake_hdiutil_plist |
69 |
@provider.class.expects(:installpkg).with("#{@fakemountpoint}/foo.pkg", @resource[:name], "foo.dmg").returns "" |
56 |
provider.class.expects(:installpkg).with("#{fake_mountpoint}/foo.pkg", resource[:name], "foo.dmg").returns "" |
70 |
@provider.install |
57 |
provider.install |
|
|
58 |
end |
59 |
|
60 |
describe "from a remote source" do |
61 |
let(:tmpdir) { "/tmp/good123" } |
62 |
|
63 |
before :each do |
64 |
resource[:source] = "http://fake.puppetlabs.com/foo.dmg" |
65 |
end |
66 |
|
67 |
it "should call tmpdir and use the returned directory" do |
68 |
Dir.expects(:mktmpdir).returns tmpdir |
69 |
Dir.stubs(:entries).returns ["foo.pkg"] |
70 |
described_class.expects(:curl).with do |*args| |
71 |
args[0] == "-o" and args[1].include? tmpdir |
72 |
end |
73 |
described_class.stubs(:hdiutil).returns fake_hdiutil_plist |
74 |
described_class.expects(:installpkg) |
75 |
|
76 |
provider.install |
77 |
end |
71 |
end |
78 |
end |
72 |
end |
79 |
end |
73 |
|
80 |
|
74 |
describe "when installing flat pkg file" do |
81 |
describe "when installing flat pkg file" do |
75 |
it "should call installpkg if a flat pkg file is found instead of a .dmg image" do |
82 |
it "should call installpkg if a flat pkg file is found instead of a .dmg image" do |
76 |
@resource.stubs(:[]).with(:source).returns "/tmp/test.pkg" |
83 |
resource[:source] = "/tmp/test.pkg" |
77 |
@resource.stubs(:[]).with(:name).returns "testpkg" |
84 |
resource[:name] = "testpkg" |
78 |
@provider.class.expects(:installpkgdmg).with("#{@fakepkgfile}", "testpkg").returns "" |
85 |
provider.class.expects(:installpkgdmg).with("/tmp/test.pkg", "testpkg").returns "" |
79 |
@provider.install |
86 |
provider.install |
80 |
end |
87 |
end |
81 |
end |
88 |
end |
82 |
|
|
|
83 |
end |
89 |
end |