File: sun_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 (112 lines) | stat: -rw-r--r-- 4,103 bytes parent folder | download | duplicates (3)
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
require 'spec_helper'

describe Puppet::Type.type(:package).provider(:sun) do
  let(:resource) { Puppet::Type.type(:package).new(:name => 'dummy', :ensure => :installed, :provider => :sun) }
  let(:provider) { resource.provider }

  describe 'provider features' do
    it { is_expected.to be_installable }
    it { is_expected.to be_uninstallable }
    it { is_expected.to be_upgradeable }
    it { is_expected.not_to be_versionable }
  end

  [:install, :uninstall, :latest, :query, :update].each do |method|
    it "should have a #{method} method" do
      expect(provider).to respond_to(method)
    end
  end

  context '#install' do
    it "should install a package" do
      resource[:ensure] = :installed
      resource[:source] = '/cdrom'
      expect(provider).to receive(:pkgadd).with(['-d', '/cdrom', '-n', 'dummy'])
      provider.install
    end

    it "should install a package if it is not present on update" do
      expect(provider).to receive(:pkginfo).with('-l', 'dummy').and_return(File.read(my_fixture('dummy.server')))
      expect(provider).to receive(:pkgrm).with(['-n', 'dummy'])
      expect(provider).to receive(:install)
      provider.update
    end

     it "should install a package on global zone if -G specified" do
      resource[:ensure] = :installed
      resource[:source] = '/cdrom'
      resource[:install_options] = '-G'
      expect(provider).to receive(:pkgadd).with(['-d', '/cdrom', '-G', '-n', 'dummy'])
      provider.install
    end
  end

  context '#uninstall' do
    it "should uninstall a package" do
      expect(provider).to receive(:pkgrm).with(['-n','dummy'])
      provider.uninstall
    end
  end

  context '#update' do
    it "should call uninstall if not :absent on info2hash" do
      allow(provider).to receive(:info2hash).and_return({:name => 'SUNWdummy', :ensure => "11.11.0,REV=2010.10.12.04.23"})
      expect(provider).to receive(:uninstall)
      expect(provider).to receive(:install)
      provider.update
    end

    it "should not call uninstall if :absent on info2hash" do
      allow(provider).to receive(:info2hash).and_return({:name => 'SUNWdummy', :ensure => :absent})
      expect(provider).to receive(:install)
      provider.update
    end
  end

  context '#query' do
    it "should find the package on query" do
      expect(provider).to receive(:pkginfo).with('-l', 'dummy').and_return(File.read(my_fixture('dummy.server')))
      expect(provider.query).to eq({
        :name     => 'SUNWdummy',
        :category=>"system",
        :platform=>"i386",
        :ensure   => "11.11.0,REV=2010.10.12.04.23",
        :root=>"/",
        :description=>"Dummy server (9.6.1-P3)",
        :vendor => "Oracle Corporation",
      })
    end

    it "shouldn't find the package on query if it is not present" do
      expect(provider).to receive(:pkginfo).with('-l', 'dummy').and_raise(Puppet::ExecutionFailure, "Execution of 'pkginfo -l dummy' returned 3: ERROR: information for \"dummy\" not found.")
      expect(provider.query).to eq({:ensure => :absent})
    end

    it "unknown message should raise error." do
      expect(provider).to receive(:pkginfo).with('-l', 'dummy').and_return('RANDOM')
      expect { provider.query }.to raise_error Puppet::Error
    end
  end

  context '#instance' do
    it "should list instances when there are packages in the system" do
      expect(described_class).to receive(:pkginfo).with('-l').and_return(File.read(my_fixture('simple')))
      instances = provider.class.instances.map { |p| {:name => p.get(:name), :ensure => p.get(:ensure)} }
      expect(instances.size).to eq(2)
      expect(instances[0]).to eq({
        :name     => 'SUNWdummy',
        :ensure   => "11.11.0,REV=2010.10.12.04.23",
      })
      expect(instances[1]).to eq({
        :name     => 'SUNWdummyc',
        :ensure   => "11.11.0,REV=2010.10.12.04.24",
      })
    end

    it "should return empty if there were no packages" do
      expect(described_class).to receive(:pkginfo).with('-l').and_return('')
      instances = provider.class.instances
      expect(instances.size).to eq(0)
    end
  end
end