Skip to content

Commit

Permalink
add some extra package tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hbuckle committed Jan 30, 2019
1 parent 22f738c commit 305ad5e
Showing 1 changed file with 50 additions and 8 deletions.
58 changes: 50 additions & 8 deletions spec/unit/puppet/provider/psmodule_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@
describe provider_class do
before(:each) do
type = Puppet::Type.type(:package).new(
name: 'module', source: 'http://source.com'
name: 'module', source: 'http://source.com', ensure: :present
)
@provider_instance = provider_class.new(type)
allow(provider_class).to receive(:invoke_ps_command).with(
provider_class.instances_command).and_return(
[
'{"name":"PackageManagement","ensure":["1.1.6.0","1.1.7.0"],"provider":"windowspowershell"}',
'{"name":"Pester","ensure":["4.0.8"],"provider":"windowspowershell"}',
'{"name":"PowerShellGet","ensure":["1.5.0.0"],"provider":"windowspowershell"}'
]
)
provider_class.instances_command
).and_return(
[
'{"name":"PackageManagement","ensure":["1.1.6.0","1.1.7.0"],"provider":"windowspowershell"}',
'{"name":"Pester","ensure":["4.0.8"],"provider":"windowspowershell"}',
'{"name":"PowerShellGet","ensure":["1.5.0.0"],"provider":"windowspowershell"}'
]
)
end
describe :instances do
specify 'returns an array of :windowspowershell providers' do
Expand All @@ -24,4 +25,45 @@
expect(instances).to all(be_instance_of(provider_class))
end
end
describe :install_options do
specify 'flattens an array of options to a command string' do
input = ['-foo', '-bar']
output = @provider_instance.install_options input
expect(output).to eq('-foo -bar')
end
specify 'flattens a mixed array of options to a command string' do
input = ['-foobar', { '-foo' => 'bar' }]
output = @provider_instance.install_options input
expect(output).to eq('-foobar -foo bar')
end
end
describe :install_command do
specify 'with name and source' do
output = @provider_instance.install_command
expect(output).to eq(
'Install-Module module -Scope AllUsers -Force -Repository http://source.com'
)
end
specify 'with name, version and source' do
type = Puppet::Type.type(:package).new(
name: 'module', ensure: '1.0.0', source: 'http://source.com'
)
provider_instance = provider_class.new(type)
output = provider_instance.install_command
expect(output).to eq(
'Install-Module module -Scope AllUsers -Force -RequiredVersion 1.0.0 -Repository http://source.com'
)
end
specify 'with name, version, source and install_options' do
type = Puppet::Type.type(:package).new(
name: 'module', ensure: '1.0.0', source: 'http://source.com',
install_options: ['-foobar', { '-foo' => 'bar' }]
)
provider_instance = provider_class.new(type)
output = provider_instance.install_command
expect(output).to eq(
'Install-Module module -Scope AllUsers -Force -RequiredVersion 1.0.0 -Repository http://source.com -foobar -foo bar'
)
end
end
end

0 comments on commit 305ad5e

Please sign in to comment.