|
5 | 5 | describe provider_class do
|
6 | 6 | before(:each) do
|
7 | 7 | type = Puppet::Type.type(:package).new(
|
8 |
| - name: 'module', source: 'http://source.com' |
| 8 | + name: 'module', source: 'http://source.com', ensure: :present |
9 | 9 | )
|
10 | 10 | @provider_instance = provider_class.new(type)
|
11 | 11 | 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 | + ) |
19 | 20 | end
|
20 | 21 | describe :instances do
|
21 | 22 | specify 'returns an array of :windowspowershell providers' do
|
|
24 | 25 | expect(instances).to all(be_instance_of(provider_class))
|
25 | 26 | end
|
26 | 27 | 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 |
27 | 69 | end
|
0 commit comments