summaryrefslogtreecommitdiffstats
path: root/spec/unit/provider/package/apt.rb
blob: 0ec1cd9eda796869bf06db5ebac62075ebc51faa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/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(:apt)

describe provider do
    before do
        @resource = stub 'resource', :[] => "asdf"
        @provider = provider.new(@resource)

        @fakeresult = "install ok installed asdf 1.0\n"
    end

    it "should be versionable" do
        provider.should be_versionable
    end

    it "should use :install to update" do
        @provider.expects(:install)
        @provider.update
    end

    it "should use 'apt-get remove' to uninstall" do
        @provider.expects(:aptget).with("-y", "-q", :remove, "asdf")

        @provider.uninstall
    end

    it "should use 'apt-get purge' and 'dpkg purge' to purge" do
        @provider.expects(:aptget).with("-y", "-q", :remove, "--purge", "asdf")
        @provider.expects(:dpkg).with("--purge", "asdf")

        @provider.purge
    end

    it "should use 'apt-cache policy' to determine the latest version of a package" do
        @provider.expects(:aptcache).with(:policy, "asdf").returns "asdf:
Installed: 1:1.0
Candidate: 1:1.1
Version table:
 1:1.0
    650 http://ftp.osuosl.org testing/main Packages
*** 1:1.1
    100 /var/lib/dpkg/status"

        @provider.latest.should == "1:1.1"
    end

    it "should print and error and return nil if no policy is found" do
        @provider.expects(:aptcache).with(:policy, "asdf").returns "asdf:"

        @provider.expects(:err)
        @provider.latest.should be_nil
    end

    it "should be able to preseed" do
        @provider.should respond_to(:run_preseed)
    end

    it "should preseed with the provided responsefile when preseeding is called for" do
        @resource.expects(:[]).with(:responsefile).returns "/my/file"
        FileTest.expects(:exist?).with("/my/file").returns true

        @provider.expects(:info)
        @provider.expects(:preseed).with("/my/file")

        @provider.run_preseed
    end

    it "should not preseed if no responsefile is provided" do
        @resource.expects(:[]).with(:responsefile).returns nil

        @provider.expects(:info)
        @provider.expects(:preseed).never

        @provider.run_preseed
    end

    it "should fail if a cdrom is listed in the sources list and :allowcdrom is not specified"

    describe "when installing" do
        it "should preseed if a responsefile is provided" do
            @resource.expects(:[]).with(:responsefile).returns "/my/file"
            @provider.expects(:run_preseed)

            @provider.stubs(:aptget)
            @provider.install
        end

        it "should check for a cdrom" do
            @provider.expects(:checkforcdrom)

            @provider.stubs(:aptget)
            @provider.install
        end

        it "should use 'apt-get install' with the package name if no version is asked for" do
            @resource.expects(:[]).with(:ensure).returns :installed
            @provider.expects(:aptget).with { |*command| command[-1] == "asdf" and command[-2] == :install }
            
            @provider.install
        end

        it "should specify the package version if one is asked for" do
            @resource.expects(:[]).with(:ensure).returns "1.0"
            @provider.expects(:aptget).with { |*command| command[-1] == "asdf=1.0" }
            
            @provider.install
        end

        it "should do a quiet install" do
            @provider.expects(:aptget).with { |*command| command.include?("-q") }
            
            @provider.install
        end

        it "should default to 'yes' for all questions" do
            @provider.expects(:aptget).with { |*command| command.include?("-y") }
            
            @provider.install
        end

        it "should keep config files if asked" do
            @resource.expects(:[]).with(:configfiles).returns :keep
            @provider.expects(:aptget).with { |*command| command.include?("DPkg::Options::=--force-confold") }
            
            @provider.install
        end

        it "should replace config files if asked" do
            @resource.expects(:[]).with(:configfiles).returns :replace
            @provider.expects(:aptget).with { |*command| command.include?("DPkg::Options::=--force-confnew") }
            
            @provider.install
        end
    end
end