From 305ad5eee2e90c2e7e561b0be8476c5e1447ae82 Mon Sep 17 00:00:00 2001 From: Henry Buckle Date: Wed, 30 Jan 2019 22:01:25 +0000 Subject: [PATCH] add some extra package tests --- spec/unit/puppet/provider/psmodule_spec.rb | 58 +++++++++++++++++++--- 1 file changed, 50 insertions(+), 8 deletions(-) diff --git a/spec/unit/puppet/provider/psmodule_spec.rb b/spec/unit/puppet/provider/psmodule_spec.rb index ad734a5..35bcec8 100644 --- a/spec/unit/puppet/provider/psmodule_spec.rb +++ b/spec/unit/puppet/provider/psmodule_spec.rb @@ -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 @@ -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