File: pkg_spec.rb

package info (click to toggle)
puppet-agent 7.23.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 19,092 kB
  • sloc: ruby: 245,074; sh: 456; makefile: 38; xml: 33
file content (473 lines) | stat: -rw-r--r-- 25,211 bytes parent folder | download
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
require 'spec_helper'

describe Puppet::Type.type(:package).provider(:pkg), unless: Puppet::Util::Platform.jruby? do
  let (:resource) { Puppet::Resource.new(:package, 'dummy', :parameters => {:name => 'dummy', :ensure => :latest}) }
  let (:provider) { described_class.new(resource) }

  before :each do
    allow(described_class).to receive(:command).with(:pkg).and_return('/bin/pkg')
  end

  def self.it_should_respond_to(*actions)
    actions.each do |action|
      it "should respond to :#{action}" do
        expect(provider).to respond_to(action)
      end
    end
  end

  it_should_respond_to :install, :uninstall, :update, :query, :latest

  context 'default' do
    [ 10 ].each do |ver|
      it "should not be the default provider on Solaris #{ver}" do
        allow(Facter).to receive(:value).with(:osfamily).and_return(:Solaris)
        allow(Facter).to receive(:value).with(:kernelrelease).and_return("5.#{ver}")
        allow(Facter).to receive(:value).with(:operatingsystem).and_return(:Solaris)
        allow(Facter).to receive(:value).with(:operatingsystemmajrelease).and_return("#{ver}")
        expect(described_class).to_not be_default
      end
    end

    [ 11, 12 ].each do |ver|
      it "should be the default provider on Solaris #{ver}" do
        allow(Facter).to receive(:value).with(:osfamily).and_return(:Solaris)
        allow(Facter).to receive(:value).with(:kernelrelease).and_return("5.#{ver}")
        allow(Facter).to receive(:value).with(:operatingsystem).and_return(:Solaris)
        allow(Facter).to receive(:value).with(:operatingsystemmajrelease).and_return("#{ver}")
        expect(described_class).to be_default
      end
    end
  end

  it "should be versionable" do
    expect(described_class).to be_versionable
  end

  describe "#methods" do
    context ":pkg_state" do
      it "should raise error on unknown values" do
        expect {
          expect(described_class.pkg_state('extra')).to
        }.to raise_error(ArgumentError, /Unknown format/)
      end

      ['known', 'installed'].each do |k|
        it "should return known values" do
          expect(described_class.pkg_state(k)).to eq({:status => k})
        end
      end
    end

    context ":ifo_flag" do
      it "should raise error on unknown values" do
        expect {
          expect(described_class.ifo_flag('x--')).to
        }.to raise_error(ArgumentError, /Unknown format/)
      end

      {'i--' => 'installed', '---'=> 'known'}.each do |k, v|
        it "should return known values" do
          expect(described_class.ifo_flag(k)).to eq({:status => v})
        end
      end
    end

    context ":parse_line" do
      it "should raise error on unknown values" do
        expect {
          expect(described_class.parse_line('pkg (mypkg) 1.2.3.4 i-- zzz')).to
        }.to raise_error(ArgumentError, /Unknown line format/)
      end

      {
        'pkg://omnios/SUNWcs@0.5.11,5.11-0.151006:20130506T161045Z    i--' => {:name => 'SUNWcs', :ensure => '0.5.11,5.11-0.151006:20130506T161045Z', :status => 'installed', :provider => :pkg, :publisher => 'omnios'},
        'pkg://omnios/incorporation/jeos/illumos-gate@11,5.11-0.151006:20130506T183443Z if-' => {:name => 'incorporation/jeos/illumos-gate', :ensure => "11,5.11-0.151006:20130506T183443Z", :mark => :hold, :status => 'installed', :provider => :pkg, :publisher => 'omnios'},
        'pkg://solaris/SUNWcs@0.5.11,5.11-0.151.0.1:20101105T001108Z      installed  -----' => {:name => 'SUNWcs', :ensure => '0.5.11,5.11-0.151.0.1:20101105T001108Z', :status => 'installed', :provider => :pkg, :publisher => 'solaris'},
       }.each do |k, v|
        it "[#{k}] should correctly parse" do
          expect(described_class.parse_line(k)).to eq(v)
        end
      end
    end

    context ":latest" do
      before do
        expect(described_class).to receive(:pkg).with(:refresh)
      end

      it "should work correctly for ensure latest on solaris 11 (UFOXI) when there are no further packages to install" do
        expect(described_class).to receive(:pkg).with(:list,'-Hvn','dummy').and_return(File.read(my_fixture('dummy_solaris11.installed')))
        expect(provider.latest).to eq('1.0.6,5.11-0.175.0.0.0.2.537:20131230T130000Z')
      end

      it "should work correctly for ensure latest on solaris 11 in the presence of a certificate expiration warning" do
        expect(described_class).to receive(:pkg).with(:list,'-Hvn','dummy').and_return(File.read(my_fixture('dummy_solaris11.certificate_warning')))
        expect(provider.latest).to eq("1.0.6-0.175.0.0.0.2.537")
      end

      it "should work correctly for ensure latest on solaris 11(known UFOXI)" do
        expect(Puppet::Util::Execution).to receive(:execute)
          .with(['/bin/pkg', 'update', '-n', 'dummy'], {:failonfail => false, :combine => true})
          .and_return(Puppet::Util::Execution::ProcessOutput.new('', 0))

        expect(described_class).to receive(:pkg).with(:list,'-Hvn','dummy').and_return(File.read(my_fixture('dummy_solaris11.known')))
        expect(provider.latest).to eq('1.0.6,5.11-0.175.0.0.0.2.537:20131230T130000Z')
      end

      it "should work correctly for ensure latest on solaris 11 (IFO)" do
        expect(described_class).to receive(:pkg).with(:list,'-Hvn','dummy').and_return(File.read(my_fixture('dummy_solaris11.ifo.installed')))
        expect(provider.latest).to eq('1.0.6,5.11-0.175.0.0.0.2.537:20131230T130000Z')
      end

      it "should work correctly for ensure latest on solaris 11(known IFO)" do
        expect(Puppet::Util::Execution).to receive(:execute)
          .with(['/bin/pkg', 'update', '-n', 'dummy'], {:failonfail => false, :combine => true})
          .and_return(Puppet::Util::Execution::ProcessOutput.new('', 0))

        expect(described_class).to receive(:pkg).with(:list,'-Hvn','dummy').and_return(File.read(my_fixture('dummy_solaris11.ifo.known')))
        expect(provider.latest).to eq('1.0.6,5.11-0.175.0.0.0.2.537:20131230T130000Z')
      end

      it "issues a warning when the certificate has expired" do
        warning = "Certificate '/var/pkg/ssl/871b4ed0ade09926e6adf95f86bf17535f987684' for publisher 'solarisstudio', needed to access 'https://pkg.oracle.com/solarisstudio/release/', will expire in '29' days."
        expect(Puppet).to receive(:warning).with("pkg warning: #{warning}")

        expect(described_class).to receive(:pkg).with(:list,'-Hvn','dummy').and_return(File.read(my_fixture('dummy_solaris11.certificate_warning')))
        provider.latest
      end

      it "doesn't issue a warning when the certificate hasn't expired" do
        expect(Puppet).not_to receive(:warning).with(/pkg warning/)

        expect(described_class).to receive(:pkg).with(:list,'-Hvn','dummy').and_return(File.read(my_fixture('dummy_solaris11.installed')))
        provider.latest
      end

      it "applies install options if available" do
        resource[:install_options] = ['--foo', {'--bar' => 'baz'}]
        expect(described_class).to receive(:pkg).with(:list,'-Hvn','dummy').and_return(File.read(my_fixture('dummy_solaris11.known')))
        expect(Puppet::Util::Execution).to receive(:execute)
          .with(['/bin/pkg', 'update', '-n', '--foo', '--bar=baz', 'dummy'], {failonfail: false, combine: true})
          .and_return(Puppet::Util::Execution::ProcessOutput.new('', 0))
        provider.latest
      end
    end

    context ":instances" do
      it "should correctly parse lines on solaris 11" do
        expect(described_class).to receive(:pkg).with(:list, '-Hv').and_return(File.read(my_fixture('solaris11')))
        expect(described_class).not_to receive(:warning)
        instances = described_class.instances.map { |p| {:name => p.get(:name), :ensure => p.get(:ensure) }}
        expect(instances.size).to eq(2)
        expect(instances[0]).to eq({:name => 'dummy/dummy', :ensure => '3.0,5.11-0.175.0.0.0.2.537:20131230T130000Z'})
        expect(instances[1]).to eq({:name => 'dummy/dummy2', :ensure => '1.8.1.2-0.175.0.0.0.2.537:20131230T130000Z'})
      end

      it "should fail on incorrect lines" do
        fake_output = File.read(my_fixture('incomplete'))
        expect(described_class).to receive(:pkg).with(:list,'-Hv').and_return(fake_output)
        expect {
          described_class.instances
        }.to raise_error(ArgumentError, /Unknown line format pkg/)
      end

      it "should fail on unknown package status" do
        expect(described_class).to receive(:pkg).with(:list,'-Hv').and_return(File.read(my_fixture('unknown_status')))
        expect {
          described_class.instances
        }.to raise_error(ArgumentError, /Unknown format pkg/)
      end
    end

    context ":query" do
      context "on solaris 10" do
        it "should find the package" do
          expect(Puppet::Util::Execution).to receive(:execute)
            .with(['/bin/pkg', 'list', '-Hv', 'dummy'], {:failonfail => false, :combine => true})
            .and_return(Puppet::Util::Execution::ProcessOutput.new(File.read(my_fixture('dummy_solaris10')), 0))
          expect(provider.query).to eq({
            :name      => 'dummy',
            :ensure    => '2.5.5,5.10-0.111:20131230T130000Z',
            :publisher => 'solaris',
            :status    => 'installed',
            :provider  => :pkg,
          })
        end

        it "should return :absent when the package is not found" do
          expect(Puppet::Util::Execution).to receive(:execute)
            .with(['/bin/pkg', 'list', '-Hv', 'dummy'], {:failonfail => false, :combine => true})
            .and_return(Puppet::Util::Execution::ProcessOutput.new('', 1))
          expect(provider.query).to eq({:ensure => :absent, :name => "dummy"})
        end
      end

      context "on solaris 11" do
        it "should find the package" do
          expect(Puppet::Util::Execution).to receive(:execute)
            .with(['/bin/pkg', 'list', '-Hv', 'dummy'], {:failonfail => false, :combine => true})
            .and_return(Puppet::Util::Execution::ProcessOutput.new(File.read(my_fixture('dummy_solaris11.installed')), 0))
          expect(provider.query).to eq({
            :name      => 'dummy',
            :status    => 'installed',
            :ensure    => '1.0.6,5.11-0.175.0.0.0.2.537:20131230T130000Z',
            :publisher => 'solaris',
            :provider  => :pkg,
          })
        end

        it "should return :absent when the package is not found" do
          expect(Puppet::Util::Execution).to receive(:execute)
            .with(['/bin/pkg', 'list', '-Hv', 'dummy'], {:failonfail => false, :combine => true})
            .and_return(Puppet::Util::Execution::ProcessOutput.new('', 1))
          expect(provider.query).to eq({:ensure => :absent, :name => "dummy"})
        end
      end

      it "should return fail when the packageline cannot be parsed" do
        expect(Puppet::Util::Execution).to receive(:execute)
          .with(['/bin/pkg', 'list', '-Hv', 'dummy'], {:failonfail => false, :combine => true})
          .and_return(Puppet::Util::Execution::ProcessOutput.new(File.read(my_fixture('incomplete')), 0))
        expect {
          provider.query
        }.to raise_error(ArgumentError, /Unknown line format/)
      end
    end

    context ":install" do
      [
        { :osrel => '11.0', :flags => ['--accept'] },
        { :osrel => '11.2', :flags => ['--accept', '--sync-actuators-timeout', '900'] },
      ].each do |hash|
        context "with :operatingsystemrelease #{hash[:osrel]}" do
          before :each do
            allow(Facter).to receive(:value).with(:operatingsystemrelease).and_return(hash[:osrel])
          end

          it "should support install options" do
            resource[:install_options] = ['--foo', {'--bar' => 'baz'}]
            expect(provider).to receive(:query).and_return({:ensure => :absent})
            expect(provider).to receive(:properties).and_return({:mark => :hold})
            expect(provider).to receive(:unhold)
            expect(Puppet::Util::Execution).to receive(:execute)
              .with(['/bin/pkg', 'install', *hash[:flags], '--foo', '--bar=baz', 'dummy'], {:failonfail => false, :combine => true})
              .and_return(Puppet::Util::Execution::ProcessOutput.new('', 0))
            provider.install
          end

          it "should accept all licenses" do
            expect(provider).to receive(:query).with(no_args).and_return({:ensure => :absent})
            expect(provider).to receive(:properties).and_return({:mark => :hold})
            expect(Puppet::Util::Execution).to receive(:execute)
              .with(['/bin/pkg', 'install', *hash[:flags], 'dummy'], {:failonfail => false, :combine => true})
              .and_return(Puppet::Util::Execution::ProcessOutput.new('', 0))
            expect(Puppet::Util::Execution).to receive(:execute)
              .with(['/bin/pkg', 'unfreeze', 'dummy'], {:failonfail => false, :combine => true})
              .and_return(Puppet::Util::Execution::ProcessOutput.new('', 0))
            provider.install
          end

          it "should install specific version(1)" do
            # Should install also check if the version installed is the same version we are asked to install? or should we rely on puppet for that?
            resource[:ensure] = '0.0.7,5.11-0.151006:20131230T130000Z'
            expect(provider).to receive(:properties).and_return({:mark => :hold})
            expect(Puppet::Util::Execution).to receive(:execute)
              .with(['/bin/pkg', 'unfreeze', 'dummy'], {:failonfail => false, :combine => true})
              .and_return(Puppet::Util::Execution::ProcessOutput.new('', 0))
            expect(Puppet::Util::Execution).to receive(:execute)
              .with(['/bin/pkg', 'list', '-Hv', 'dummy'], {:failonfail => false, :combine => true})
              .and_return(Puppet::Util::Execution::ProcessOutput.new('pkg://foo/dummy@0.0.6,5.11-0.151006:20131230T130000Z  installed -----', 0))
            expect(Puppet::Util::Execution).to receive(:execute)
              .with(['/bin/pkg', 'update', *hash[:flags], 'dummy@0.0.7,5.11-0.151006:20131230T130000Z'], {:failonfail => false, :combine => true})
              .and_return(Puppet::Util::Execution::ProcessOutput.new('', 0))
            provider.install
          end

          it "should install specific version(2)" do
            resource[:ensure] = '0.0.8'
            expect(provider).to receive(:properties).and_return({:mark => :hold})
            expect(Puppet::Util::Execution).to receive(:execute)
              .with(['/bin/pkg', 'unfreeze', 'dummy'], {:failonfail => false, :combine => true})
              .and_return(Puppet::Util::Execution::ProcessOutput.new('', 0))
            expect(Puppet::Util::Execution).to receive(:execute)
              .with(['/bin/pkg', 'list', '-Hv', 'dummy'], {:failonfail => false, :combine => true})
              .and_return(Puppet::Util::Execution::ProcessOutput.new('pkg://foo/dummy@0.0.7,5.11-0.151006:20131230T130000Z  installed -----', 0))
            expect(Puppet::Util::Execution).to receive(:execute)
              .with(['/bin/pkg', 'update', *hash[:flags], 'dummy@0.0.8'], {:failonfail => false, :combine => true})
              .and_return(Puppet::Util::Execution::ProcessOutput.new('', 0))
            provider.install
          end

          it "should downgrade to specific version" do
            resource[:ensure] = '0.0.7'
            expect(provider).to receive(:properties).and_return({:mark => :hold})
            expect(provider).to receive(:query).with(no_args).and_return({:ensure => '0.0.8,5.11-0.151106:20131230T130000Z'})
            expect(Puppet::Util::Execution).to receive(:execute)
              .with(['/bin/pkg', 'unfreeze', 'dummy'], {:failonfail => false, :combine => true})
              .and_return(Puppet::Util::Execution::ProcessOutput.new('', 0))
            expect(Puppet::Util::Execution).to receive(:execute)
              .with(['/bin/pkg', 'update', *hash[:flags], 'dummy@0.0.7'], {:failonfail => false, :combine => true})
              .and_return(Puppet::Util::Execution::ProcessOutput.new('', 0))
            provider.install
          end

          it "should install any if version is not specified" do
            resource[:ensure] = :present
            expect(provider).to receive(:properties).and_return({:mark => :hold})
            expect(provider).to receive(:query).with(no_args).and_return({:ensure => :absent})
            expect(Puppet::Util::Execution).to receive(:execute)
              .with(['/bin/pkg', 'install', *hash[:flags], 'dummy'], {:failonfail => false, :combine => true})
              .and_return(Puppet::Util::Execution::ProcessOutput.new('', 0))
            expect(Puppet::Util::Execution).to receive(:execute)
              .with(['/bin/pkg', 'unfreeze', 'dummy'], {:failonfail => false, :combine => true})
              .and_return(Puppet::Util::Execution::ProcessOutput.new('', 0))
            provider.install
          end

          it "should install if no version was previously installed, and a specific version was requested" do
            resource[:ensure] = '0.0.7'
            expect(provider).to receive(:properties).and_return({:mark => :hold})
            expect(provider).to receive(:query).with(no_args).and_return({:ensure => :absent})
            expect(Puppet::Util::Execution).to receive(:execute)
              .with(['/bin/pkg', 'unfreeze', 'dummy'], {:failonfail => false, :combine => true})
              .and_return(Puppet::Util::Execution::ProcessOutput.new('', 0))
            expect(Puppet::Util::Execution).to receive(:execute)
              .with(['/bin/pkg', 'install', *hash[:flags], 'dummy@0.0.7'], {:failonfail => false, :combine => true})
              .and_return(Puppet::Util::Execution::ProcessOutput.new('', 0))
            provider.install
          end

          it "installs the latest matching version when given implicit version, and none are installed" do
            resource[:ensure] = '1.0-0.151006'
            is = :absent
            expect(provider).to receive(:query).with(no_args).and_return({:ensure => is})
            expect(provider).to receive(:properties).and_return({:mark => :hold}).exactly(3).times

            expect(described_class).to receive(:pkg)
              .with(:freeze, 'dummy')
            expect(described_class).to receive(:pkg)
              .with(:list, '-Hvfa', 'dummy@1.0-0.151006')
              .and_return(Puppet::Util::Execution::ProcessOutput.new(File.read(my_fixture('dummy_implicit_version')), 0))
            expect(Puppet::Util::Execution).to receive(:execute)
              .with(['/bin/pkg', 'install', '-n', 'dummy@1.0,5.11-0.151006:20140220T084443Z'], {:failonfail => false, :combine => true})
              .and_return(Puppet::Util::Execution::ProcessOutput.new('', 0))
            expect(provider).to receive(:unhold).with(no_args).twice
            expect(Puppet::Util::Execution).to receive(:execute)
              .with(['/bin/pkg', 'install', *hash[:flags], 'dummy@1.0,5.11-0.151006:20140220T084443Z'], {:failonfail => false, :combine => true})
              .and_return(Puppet::Util::Execution::ProcessOutput.new('', 0))
            provider.insync?(is)
            provider.install
          end

          it "updates to the latest matching version when given implicit version" do
            resource[:ensure] = '1.0-0.151006'
            is = '1.0,5.11-0.151006:20140219T191204Z'
            expect(provider).to receive(:query).with(no_args).and_return({:ensure => is})
            expect(provider).to receive(:properties).and_return({:mark => :hold}).exactly(3).times

            expect(described_class).to receive(:pkg)
              .with(:freeze, 'dummy')
            expect(described_class).to receive(:pkg)
              .with(:list, '-Hvfa', 'dummy@1.0-0.151006')
              .and_return(File.read(my_fixture('dummy_implicit_version')))
            expect(Puppet::Util::Execution).to receive(:execute)
              .with(['/bin/pkg', 'update', '-n', 'dummy@1.0,5.11-0.151006:20140220T084443Z'], {:failonfail => false, :combine => true})
              .and_return(Puppet::Util::Execution::ProcessOutput.new('', 0))
            expect(provider).to receive(:unhold).with(no_args).twice
            expect(Puppet::Util::Execution).to receive(:execute)
              .with(['/bin/pkg', 'update', *hash[:flags], 'dummy@1.0,5.11-0.151006:20140220T084443Z'], {:failonfail => false, :combine => true})
              .and_return(Puppet::Util::Execution::ProcessOutput.new('', 0))
            provider.insync?(is)
            provider.install
          end

          it "issues a warning when an implicit version number is used, and in sync" do
            resource[:ensure] = '1.0-0.151006'
            is = '1.0,5.11-0.151006:20140220T084443Z'
            expect(provider).to receive(:warning).with("Implicit version 1.0-0.151006 has 3 possible matches")
            expect(described_class).to receive(:pkg)
              .with(:list, '-Hvfa', 'dummy@1.0-0.151006')
              .and_return(Puppet::Util::Execution::ProcessOutput.new(File.read(my_fixture('dummy_implicit_version')), 0))
            expect(Puppet::Util::Execution).to receive(:execute)
              .with(['/bin/pkg', 'list', '-Hv', 'dummy'], {:failonfail => false, :combine => true})
              .and_return(Puppet::Util::Execution::ProcessOutput.new(File.read(my_fixture('dummy_implicit_version')), 0))
            expect(Puppet::Util::Execution).to receive(:execute)
              .with(['/bin/pkg', 'update', '-n', 'dummy@1.0,5.11-0.151006:20140220T084443Z'], {:failonfail => false, :combine => true})
              .and_return(Puppet::Util::Execution::ProcessOutput.new('', 4))
            provider.insync?(is)
          end

          it "issues a warning when choosing a version number for an implicit match" do
            resource[:ensure] = '1.0-0.151006'
            is = :absent
            expect(provider).to receive(:warning).with("Implicit version 1.0-0.151006 has 3 possible matches")
            expect(provider).to receive(:warning).with("Selecting version '1.0,5.11-0.151006:20140220T084443Z' for implicit '1.0-0.151006'")
            expect(described_class).to receive(:pkg)
              .with(:list, '-Hvfa', 'dummy@1.0-0.151006')
              .and_return(Puppet::Util::Execution::ProcessOutput.new(File.read(my_fixture('dummy_implicit_version')), 0))
            expect(Puppet::Util::Execution).to receive(:execute)
              .with(['/bin/pkg', 'list', '-Hv', 'dummy'], {:failonfail => false, :combine => true})
              .and_return(Puppet::Util::Execution::ProcessOutput.new(File.read(my_fixture('dummy_implicit_version')), 0))
            expect(Puppet::Util::Execution).to receive(:execute)
              .with(['/bin/pkg', 'install', '-n', 'dummy@1.0,5.11-0.151006:20140220T084443Z'], {:failonfail => false, :combine => true})
              .and_return(Puppet::Util::Execution::ProcessOutput.new('', 0))
            provider.insync?(is)
          end

          it "should try 5 times to install and fail when all tries failed" do
            allow_any_instance_of(Kernel).to receive(:sleep)

            expect(provider).to receive(:query).and_return({:ensure => :absent})
            expect(provider).to receive(:properties).and_return({:mark => :hold})
            expect(provider).to receive(:unhold)
            expect(Puppet::Util::Execution).to receive(:execute)
              .with(['/bin/pkg', 'install', *hash[:flags], 'dummy'], {:failonfail => false, :combine => true})
              .and_return(Puppet::Util::Execution::ProcessOutput.new('', 7))
              .exactly(5).times
            expect {
              provider.update
            }.to raise_error(Puppet::Error, /Pkg could not install dummy after 5 tries. Aborting run/)
          end
        end
      end
    end

    context ":update" do
      it "should not raise error if not necessary" do
        expect(provider).to receive(:install).with(true).and_return({:exit => 0})
        provider.update
      end

      it "should not raise error if not necessary (2)" do
        expect(provider).to receive(:install).with(true).and_return({:exit => 4})
        provider.update
      end

      it "should raise error if necessary" do
        expect(provider).to receive(:install).with(true).and_return({:exit => 1})
        expect {
          provider.update
        }.to raise_error(Puppet::Error, /Unable to update/)
      end
    end

    context ":uninstall" do
      it "should support current pkg version" do
        expect(described_class).to receive(:pkg).with(:version).and_return('630e1ffc7a19')
        expect(described_class).to receive(:pkg).with([:uninstall, resource[:name]])
        expect(provider).to receive(:properties).and_return({:hold => false})

        provider.uninstall
      end

      it "should support original pkg commands" do
        expect(described_class).to receive(:pkg).with(:version).and_return('052adf36c3f4')
        expect(described_class).to receive(:pkg).with([:uninstall, '-r', resource[:name]])
        expect(provider).to receive(:properties).and_return({:hold => false})

        provider.uninstall
      end
    end
  end
end