Skip to content

Commit 305ad5e

Browse files
committed
add some extra package tests
1 parent 22f738c commit 305ad5e

File tree

1 file changed

+50
-8
lines changed

1 file changed

+50
-8
lines changed

spec/unit/puppet/provider/psmodule_spec.rb

+50-8
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@
55
describe provider_class do
66
before(:each) do
77
type = Puppet::Type.type(:package).new(
8-
name: 'module', source: 'http://source.com'
8+
name: 'module', source: 'http://source.com', ensure: :present
99
)
1010
@provider_instance = provider_class.new(type)
1111
allow(provider_class).to receive(:invoke_ps_command).with(
12-
provider_class.instances_command).and_return(
13-
[
14-
'{"name":"PackageManagement","ensure":["1.1.6.0","1.1.7.0"],"provider":"windowspowershell"}',
15-
'{"name":"Pester","ensure":["4.0.8"],"provider":"windowspowershell"}',
16-
'{"name":"PowerShellGet","ensure":["1.5.0.0"],"provider":"windowspowershell"}'
17-
]
18-
)
12+
provider_class.instances_command
13+
).and_return(
14+
[
15+
'{"name":"PackageManagement","ensure":["1.1.6.0","1.1.7.0"],"provider":"windowspowershell"}',
16+
'{"name":"Pester","ensure":["4.0.8"],"provider":"windowspowershell"}',
17+
'{"name":"PowerShellGet","ensure":["1.5.0.0"],"provider":"windowspowershell"}'
18+
]
19+
)
1920
end
2021
describe :instances do
2122
specify 'returns an array of :windowspowershell providers' do
@@ -24,4 +25,45 @@
2425
expect(instances).to all(be_instance_of(provider_class))
2526
end
2627
end
28+
describe :install_options do
29+
specify 'flattens an array of options to a command string' do
30+
input = ['-foo', '-bar']
31+
output = @provider_instance.install_options input
32+
expect(output).to eq('-foo -bar')
33+
end
34+
specify 'flattens a mixed array of options to a command string' do
35+
input = ['-foobar', { '-foo' => 'bar' }]
36+
output = @provider_instance.install_options input
37+
expect(output).to eq('-foobar -foo bar')
38+
end
39+
end
40+
describe :install_command do
41+
specify 'with name and source' do
42+
output = @provider_instance.install_command
43+
expect(output).to eq(
44+
'Install-Module module -Scope AllUsers -Force -Repository http://source.com'
45+
)
46+
end
47+
specify 'with name, version and source' do
48+
type = Puppet::Type.type(:package).new(
49+
name: 'module', ensure: '1.0.0', source: 'http://source.com'
50+
)
51+
provider_instance = provider_class.new(type)
52+
output = provider_instance.install_command
53+
expect(output).to eq(
54+
'Install-Module module -Scope AllUsers -Force -RequiredVersion 1.0.0 -Repository http://source.com'
55+
)
56+
end
57+
specify 'with name, version, source and install_options' do
58+
type = Puppet::Type.type(:package).new(
59+
name: 'module', ensure: '1.0.0', source: 'http://source.com',
60+
install_options: ['-foobar', { '-foo' => 'bar' }]
61+
)
62+
provider_instance = provider_class.new(type)
63+
output = provider_instance.install_command
64+
expect(output).to eq(
65+
'Install-Module module -Scope AllUsers -Force -RequiredVersion 1.0.0 -Repository http://source.com -foobar -foo bar'
66+
)
67+
end
68+
end
2769
end

0 commit comments

Comments
 (0)