|
16 | 16 |
|
17 | 17 | let(:provider_gem_cmd) { '/opt/puppetlabs/bin/puppetserver' }
|
18 | 18 |
|
19 |
| - custom_environment = { HOME: ENV['HOME'] } |
20 |
| - |
21 |
| - let(:execute_options) { { failonfail: true, combine: true, custom_environment: custom_environment } } |
| 19 | + let(:execute_options) do |
| 20 | + { failonfail: true, combine: true, custom_environment: { 'HOME' => ENV['HOME'] } } |
| 21 | + end |
22 | 22 |
|
23 | 23 | before :each do
|
24 | 24 | resource.provider = provider
|
25 | 25 | allow(Puppet::Util).to receive(:which).with(provider_gem_cmd).and_return(provider_gem_cmd)
|
| 26 | + allow(File).to receive(:file?).with(provider_gem_cmd).and_return(true) |
26 | 27 | end
|
27 | 28 |
|
28 | 29 | describe "#install" do
|
29 | 30 | it "uses the path to the gem command" do
|
30 |
| - allow(described_class).to receive(:validate_command).with(provider_gem_cmd) |
31 |
| - expect(Puppet::Util::Execution).to receive(:execute).with(be_a(Array), execute_options) { |args| expect(args[0]).to eq(provider_gem_cmd) }.and_return('') |
| 31 | + expect(Puppet::Util::Execution).to receive(:execute).with([provider_gem_cmd, be_an(Array)], be_a(Hash)).and_return('') |
32 | 32 | provider.install
|
33 | 33 | end
|
34 | 34 |
|
35 | 35 | it "appends version if given" do
|
36 | 36 | resource[:ensure] = ['1.2.1']
|
37 |
| - expect(described_class).to receive(:puppetservercmd).with(%w{gem install -v 1.2.1 --no-document myresource}).and_return('') |
| 37 | + expect(Puppet::Util::Execution).to receive(:execute).with([provider_gem_cmd, %w{gem install -v 1.2.1 --no-document myresource}], anything).and_return('') |
38 | 38 | provider.install
|
39 | 39 | end
|
40 | 40 |
|
41 | 41 | context "with install_options" do
|
42 | 42 | it "does not append the parameter by default" do
|
43 |
| - expect(described_class).to receive(:puppetservercmd).with(%w{gem install --no-document myresource}).and_return('') |
| 43 | + expect(Puppet::Util::Execution).to receive(:execute).with([provider_gem_cmd, %w{gem install --no-document myresource}], anything).and_return('') |
44 | 44 | provider.install
|
45 | 45 | end
|
46 | 46 |
|
47 | 47 | it "allows setting the parameter" do
|
48 | 48 | resource[:install_options] = [ '--force', {'--bindir' => '/usr/bin' } ]
|
49 |
| - expect(described_class).to receive(:puppetservercmd).with(%w{gem install --force --bindir=/usr/bin --no-document myresource}).and_return('') |
| 49 | + expect(Puppet::Util::Execution).to receive(:execute).with([provider_gem_cmd, %w{gem install --force --bindir=/usr/bin --no-document myresource}], anything).and_return('') |
50 | 50 | provider.install
|
51 | 51 | end
|
52 | 52 | end
|
53 | 53 |
|
54 | 54 | context "with source" do
|
55 | 55 | it "correctly sets http source" do
|
56 | 56 | resource[:source] = 'http://rubygems.com'
|
57 |
| - expect(described_class).to receive(:puppetservercmd).with(%w{gem install --no-document --source http://rubygems.com myresource}).and_return('') |
| 57 | + expect(Puppet::Util::Execution).to receive(:execute).with([provider_gem_cmd, %w{gem install --no-document --source http://rubygems.com myresource}], anything).and_return('') |
58 | 58 | provider.install
|
59 | 59 | end
|
60 | 60 |
|
61 | 61 | it "correctly sets local file source" do
|
62 | 62 | resource[:source] = 'paint-2.2.0.gem'
|
63 |
| - expect(described_class).to receive(:puppetservercmd).with(%w{gem install --no-document paint-2.2.0.gem}).and_return('') |
| 63 | + expect(Puppet::Util::Execution).to receive(:execute).with([provider_gem_cmd, %w{gem install --no-document paint-2.2.0.gem}], anything).and_return('') |
64 | 64 | provider.install
|
65 | 65 | end
|
66 | 66 |
|
67 | 67 | it "correctly sets local file source with URI scheme" do
|
68 | 68 | resource[:source] = 'file:///root/paint-2.2.0.gem'
|
69 |
| - expect(described_class).to receive(:puppetservercmd).with(%w{gem install --no-document /root/paint-2.2.0.gem}).and_return('') |
| 69 | + expect(Puppet::Util::Execution).to receive(:execute).with([provider_gem_cmd, %w{gem install --no-document /root/paint-2.2.0.gem}], anything).and_return('') |
70 | 70 | provider.install
|
71 | 71 | end
|
72 | 72 |
|
|
84 | 84 |
|
85 | 85 | describe "#uninstall" do
|
86 | 86 | it "uses the path to the gem command" do
|
87 |
| - allow(described_class).to receive(:validate_command).with(provider_gem_cmd) |
88 |
| - expect(Puppet::Util::Execution).to receive(:execute).with(be_a(Array), execute_options) { |args| expect(args[0]).to eq(provider_gem_cmd) }.and_return('') |
| 87 | + expect(Puppet::Util::Execution).to receive(:execute).with([provider_gem_cmd, be_an(Array)], be_a(Hash)).and_return('') |
89 | 88 | provider.uninstall
|
90 | 89 | end
|
91 | 90 |
|
92 | 91 | context "with uninstall_options" do
|
93 | 92 | it "does not append the parameter by default" do
|
94 |
| - expect(described_class).to receive(:puppetservercmd).with(%w{gem uninstall --executables --all myresource}).and_return('') |
| 93 | + expect(Puppet::Util::Execution).to receive(:execute).with([provider_gem_cmd, %w{gem uninstall --executables --all myresource}], anything).and_return('') |
95 | 94 | provider.uninstall
|
96 | 95 | end
|
97 | 96 |
|
98 | 97 | it "allows setting the parameter" do
|
99 | 98 | resource[:uninstall_options] = [ '--force', {'--bindir' => '/usr/bin' } ]
|
100 |
| - expect(described_class).to receive(:puppetservercmd).with(%w{gem uninstall --executables --all myresource --force --bindir=/usr/bin}).and_return('') |
| 99 | + expect(Puppet::Util::Execution).to receive(:execute).with([provider_gem_cmd, %w{gem uninstall --executables --all myresource --force --bindir=/usr/bin}], anything).and_return('') |
101 | 100 | provider.uninstall
|
102 | 101 | end
|
103 | 102 | end
|
|
106 | 105 | describe ".gemlist" do
|
107 | 106 | context "listing installed packages" do
|
108 | 107 | it "uses the puppet_gem provider_command to list local gems" do
|
| 108 | + allow(Puppet::Type::Package::ProviderPuppet_gem).to receive(:provider_command).and_return('/opt/puppetlabs/puppet/bin/gem') |
| 109 | + allow(described_class).to receive(:validate_command).with('/opt/puppetlabs/puppet/bin/gem') |
| 110 | + |
109 | 111 | expected = { name: 'world_airports', provider: :puppetserver_gem, ensure: ['1.1.3'] }
|
110 |
| - expect(described_class).to receive(:execute_rubygems_list_command).with(['gem', 'list', '--local']).and_return(File.read(my_fixture('gem-list-local-packages'))) |
| 112 | + expect(Puppet::Util::Execution).to receive(:execute).with(['/opt/puppetlabs/puppet/bin/gem', %w[list --local]], anything).and_return(File.read(my_fixture('gem-list-local-packages'))) |
111 | 113 | expect(described_class.gemlist({ local: true })).to include(expected)
|
112 | 114 | end
|
113 | 115 | end
|
114 | 116 |
|
115 | 117 | it "appends the gem source if given" do
|
116 |
| - expect(described_class).to receive(:puppetservercmd).with(%w{gem list --remote --source https://rubygems.com}).and_return('') |
| 118 | + expect(Puppet::Util::Execution).to receive(:execute).with([provider_gem_cmd, %w{gem list --remote --source https://rubygems.com}], anything).and_return('') |
117 | 119 | described_class.gemlist({ source: 'https://rubygems.com' })
|
118 | 120 | end
|
119 | 121 | end
|
|
0 commit comments