~bkerensa/ubuntu/raring/puppet/new-upstream-release

« back to all changes in this revision

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

  • Committer: Benjamin Kerensa
  • Date: 2012-11-21 23:50:52 UTC
  • mfrom: (1.1.30)
  • Revision ID: bkerensa@ubuntu.com-20121121235052-ah7nzabp77sh69gb
New Upstream Release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env rspec
 
1
#! /usr/bin/env ruby
2
2
require 'spec_helper'
3
3
require 'stringio'
4
4
 
5
5
provider = Puppet::Type.type(:package).provider(:pacman)
6
6
 
7
7
describe provider do
 
8
  let(:no_extra_options) { { :custom_environment => {} } }
 
9
  let(:executor) { Puppet::Util::Execution }
 
10
  let(:resolver) { Puppet::Util }
 
11
 
8
12
  before do
9
 
    provider.stubs(:command).with(:pacman).returns('/usr/bin/pacman')
10
 
    @resource = stub 'resource'
11
 
    @resource.stubs(:[]).returns("package")
12
 
    @resource.stubs(:name).returns("name")
 
13
    resolver.stubs(:which).with('/usr/bin/pacman').returns('/usr/bin/pacman')
 
14
    provider.stubs(:which).with('/usr/bin/pacman').returns('/usr/bin/pacman')
 
15
    @resource = Puppet::Type.type(:package).new(:name => 'package')
13
16
    @provider = provider.new(@resource)
14
17
  end
15
18
 
20
23
      })
21
24
    end
22
25
 
23
 
    it "should call pacman" do
24
 
      provider.
 
26
    it "should call pacman to install the right package quietly" do
 
27
      executor.
25
28
        expects(:execute).
26
29
        at_least_once.
27
 
        with { |args|
28
 
          args[0] == "/usr/bin/pacman"
29
 
        }.
 
30
        with(["/usr/bin/pacman", "--noconfirm", "--noprogressbar", "-Sy", @resource[:name]], no_extra_options).
30
31
        returns ""
31
32
 
32
33
      @provider.install
33
34
    end
34
35
 
35
 
    it "should be quiet" do
36
 
      provider.
37
 
        expects(:execute).
38
 
        with { |args|
39
 
          args[1,2] == ["--noconfirm", "--noprogressbar"]
40
 
        }.
41
 
        returns("")
42
 
 
43
 
      @provider.install
44
 
    end
45
 
 
46
 
    it "should install the right package" do
47
 
      provider.
48
 
        expects(:execute).
49
 
        with { |args|
50
 
          args[3,4] == ["-Sy", @resource[0]]
51
 
        }.
52
 
        returns("")
53
 
 
54
 
      @provider.install
55
 
    end
56
 
 
57
36
    it "should raise an ExecutionFailure if the installation failed" do
58
 
      provider.stubs(:execute).returns("")
 
37
      executor.stubs(:execute).returns("")
59
38
      @provider.expects(:query).returns(nil)
60
39
 
61
40
      lambda { @provider.install }.should raise_exception(Puppet::ExecutionFailure)
62
41
    end
 
42
 
 
43
    context "when :source is specified" do
 
44
      before :each do
 
45
        @install = sequence("install")
 
46
      end
 
47
 
 
48
      context "recognizable by pacman" do
 
49
        %w{
 
50
          /some/package/file
 
51
          http://some.package.in/the/air
 
52
          ftp://some.package.in/the/air
 
53
        }.each do |source|
 
54
          it "should install #{source} directly" do
 
55
            @resource[:source] = source
 
56
 
 
57
            executor.expects(:execute).
 
58
              with(all_of(includes("-Sy"), includes("--noprogressbar")), no_extra_options).
 
59
              in_sequence(@install).
 
60
              returns("")
 
61
 
 
62
            executor.expects(:execute).
 
63
              with(all_of(includes("-U"), includes(source)), no_extra_options).
 
64
              in_sequence(@install).
 
65
              returns("")
 
66
 
 
67
            @provider.install
 
68
          end
 
69
        end
 
70
      end
 
71
 
 
72
      context "as a file:// URL" do
 
73
        before do
 
74
          @package_file = "file:///some/package/file"
 
75
          @actual_file_path = "/some/package/file"
 
76
          @resource[:source] = @package_file
 
77
        end
 
78
 
 
79
        it "should install from the path segment of the URL" do
 
80
          executor.expects(:execute).
 
81
            with(all_of(includes("-Sy"),
 
82
                        includes("--noprogressbar"),
 
83
                        includes("--noconfirm")),
 
84
                 no_extra_options).
 
85
            in_sequence(@install).
 
86
            returns("")
 
87
 
 
88
          executor.expects(:execute).
 
89
            with(all_of(includes("-U"), includes(@actual_file_path)), no_extra_options).
 
90
            in_sequence(@install).
 
91
            returns("")
 
92
 
 
93
          @provider.install
 
94
        end
 
95
      end
 
96
 
 
97
      context "as a puppet URL" do
 
98
        before do
 
99
          @resource[:source] = "puppet://server/whatever"
 
100
        end
 
101
 
 
102
        it "should fail" do
 
103
          lambda { @provider.install }.should raise_error(Puppet::Error)
 
104
        end
 
105
      end
 
106
 
 
107
      context "as a malformed URL" do
 
108
        before do
 
109
          @resource[:source] = "blah://"
 
110
        end
 
111
 
 
112
        it "should fail" do
 
113
          lambda { @provider.install }.should raise_error(Puppet::Error)
 
114
        end
 
115
      end
 
116
    end
63
117
  end
64
118
 
65
119
  describe "when updating" do
70
124
  end
71
125
 
72
126
  describe "when uninstalling" do
73
 
    it "should call pacman" do
74
 
      provider.
 
127
    it "should call pacman to remove the right package quietly" do
 
128
      executor.
75
129
        expects(:execute).
76
 
        with { |args|
77
 
          args[0] == "/usr/bin/pacman"
78
 
        }.
 
130
        with(["/usr/bin/pacman", "--noconfirm", "--noprogressbar", "-R", @resource[:name]], no_extra_options).
79
131
        returns ""
80
132
 
81
133
      @provider.uninstall
82
134
    end
83
 
 
84
 
    it "should be quiet" do
85
 
      provider.
86
 
        expects(:execute).
87
 
        with { |args|
88
 
          args[1,2] == ["--noconfirm", "--noprogressbar"]
89
 
        }.
90
 
        returns("")
91
 
 
92
 
      @provider.uninstall
93
 
    end
94
 
 
95
 
    it "should remove the right package" do
96
 
      provider.
97
 
        expects(:execute).
98
 
        with { |args|
99
 
          args[3,4] == ["-R", @resource[0]]
100
 
        }.
101
 
        returns("")
102
 
 
103
 
      @provider.uninstall
104
 
    end
105
135
  end
106
136
 
107
137
  describe "when querying" do
108
138
    it "should query pacman" do
109
 
      provider.
 
139
      executor.
110
140
        expects(:execute).
111
 
        with(["/usr/bin/pacman", "-Qi", @resource[0]])
 
141
        with(["/usr/bin/pacman", "-Qi", @resource[:name]], no_extra_options)
112
142
      @provider.query
113
143
    end
114
144
 
136
166
Description    : A library-based package manager with dependency support
137
167
EOF
138
168
 
139
 
      provider.expects(:execute).returns(query_output)
 
169
      executor.expects(:execute).returns(query_output)
140
170
      @provider.query.should == {:ensure => "1.01.3-2"}
141
171
    end
142
172
 
143
173
    it "should return a nil if the package isn't found" do
144
 
      provider.expects(:execute).returns("")
 
174
      executor.expects(:execute).returns("")
145
175
      @provider.query.should be_nil
146
176
    end
147
177
 
148
178
    it "should return a hash indicating that the package is missing on error" do
149
 
      provider.expects(:execute).raises(Puppet::ExecutionFailure.new("ERROR!"))
 
179
      executor.expects(:execute).raises(Puppet::ExecutionFailure.new("ERROR!"))
150
180
      @provider.query.should == {
151
181
        :ensure => :purged,
152
182
        :status => 'missing',
153
 
        :name => @resource[0],
 
183
        :name => @resource[:name],
154
184
        :error => 'ok',
155
185
      }
156
186
    end
195
225
 
196
226
  describe "when determining the latest version" do
197
227
    it "should refresh package list" do
198
 
      refreshed = states('refreshed').starts_as('unrefreshed')
199
 
      provider.
 
228
      get_latest_version = sequence("get_latest_version")
 
229
      executor.
200
230
        expects(:execute).
201
 
        when(refreshed.is('unrefreshed')).
202
 
        with(['/usr/bin/pacman', '-Sy']).
203
 
        then(refreshed.is('refreshed'))
 
231
        in_sequence(get_latest_version).
 
232
        with(['/usr/bin/pacman', '-Sy'], no_extra_options)
204
233
 
205
 
      provider.
 
234
      executor.
206
235
        stubs(:execute).
207
 
        when(refreshed.is('refreshed')).
 
236
        in_sequence(get_latest_version).
208
237
        returns("")
209
238
 
210
239
      @provider.latest
211
240
    end
212
241
 
213
242
    it "should get query pacman for the latest version" do
214
 
      refreshed = states('refreshed').starts_as('unrefreshed')
215
 
      provider.
 
243
      get_latest_version = sequence("get_latest_version")
 
244
      executor.
216
245
        stubs(:execute).
217
 
        when(refreshed.is('unrefreshed')).
218
 
        then(refreshed.is('refreshed'))
 
246
        in_sequence(get_latest_version)
219
247
 
220
 
      provider.
 
248
      executor.
221
249
        expects(:execute).
222
 
        when(refreshed.is('refreshed')).
223
 
        with(['/usr/bin/pacman', '-Sp', '--print-format', '%v', @resource[0]]).
 
250
        in_sequence(get_latest_version).
 
251
        with(['/usr/bin/pacman', '-Sp', '--print-format', '%v', @resource[:name]], no_extra_options).
224
252
        returns("")
225
253
 
226
254
      @provider.latest
227
255
    end
228
256
 
229
257
    it "should return the version number from pacman" do
230
 
      provider.
 
258
      executor.
231
259
        expects(:execute).
232
260
        at_least_once().
233
261
        returns("1.00.2-3\n")