diff --git a/test/helper.rb b/test/helper.rb index aca2c1311..3f88e1ea8 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -94,7 +94,8 @@ class MockLoader 'gem list --local -a -q ^rubocop$' => cmd.call('gem-list-local-a-q-rubocop'), 'npm ls -g --json bower' => cmd.call('npm-ls-g--json-bower'), 'pip show jinja2' => cmd.call('pip-show-jinja2'), - "Get-Package -Name 'Mozilla Firefox' | ConvertTo-Json" => cmd.call('get-package'), + "Get-Package -Name 'Mozilla Firefox' | ConvertTo-Json" => cmd.call('get-package-firefox'), + "Get-Package -Name 'Ruby 2.1.6-p336-x64' | ConvertTo-Json" => cmd.call('get-package-ruby'), "New-Object -Type PSObject | Add-Member -MemberType NoteProperty -Name Service -Value (Get-Service -Name dhcp| Select-Object -Property Name, DisplayName, Status) -PassThru | Add-Member -MemberType NoteProperty -Name WMI -Value (Get-WmiObject -Class Win32_Service | Where-Object {$_.Name -eq 'dhcp' -or $_.DisplayName -eq 'dhcp'} | Select-Object -Property StartMode) -PassThru | ConvertTo-Json" => cmd.call('get-service-dhcp'), "Get-WindowsFeature | Where-Object {$_.Name -eq 'dhcp' -or $_.DisplayName -eq 'dhcp'} | Select-Object -Property Name,DisplayName,Description,Installed,InstallState | ConvertTo-Json" => cmd.call('get-windows-feature'), 'lsmod' => cmd.call('lsmod'), diff --git a/test/unit/mock/cmd/get-package b/test/unit/mock/cmd/get-package-firefox similarity index 100% rename from test/unit/mock/cmd/get-package rename to test/unit/mock/cmd/get-package-firefox diff --git a/test/unit/mock/cmd/get-package-ruby b/test/unit/mock/cmd/get-package-ruby new file mode 100644 index 000000000..42b7114fd --- /dev/null +++ b/test/unit/mock/cmd/get-package-ruby @@ -0,0 +1,18 @@ +[ + { + "ProviderName": "Programs", + "Status": "Installed", + "SearchKey": "Ruby 2.1.6-p336-x64", + "CanonicalId": "programs:Ruby 2.1.6-p336-x64/2.1.6-p336", + "Name": "Ruby 2.1.6-p336-x64", + "Version": "2.1.6-p336" + }, + { + "ProviderName": "Programs", + "Status": "Installed", + "SearchKey": "Ruby 2.1.6-p336-x64", + "CanonicalId": "programs:Ruby 2.1.6-p336-x64/2.1.6-p336", + "Name": "Ruby 2.1.6-p336-x64", + "Version": "2.1.6-p336" + } +] diff --git a/test/unit/resource_oneget_test.rb b/test/unit/resource_oneget_test.rb index 77d968bc0..ef1be61a0 100644 --- a/test/unit/resource_oneget_test.rb +++ b/test/unit/resource_oneget_test.rb @@ -4,9 +4,9 @@ require 'helper' require 'vulcano/resource' describe 'Vulcano::Resources::Passwd' do - let(:resource) { load_resource('oneget', 'Mozilla Firefox') } it 'verify oneget package detail parsing' do + resource = MockLoader.new(:windows).load_resource('oneget', 'Mozilla Firefox') pkg = { name: 'Mozilla Firefox 40.0.3 (x86 en-US)', version: '40.0.3', @@ -14,6 +14,30 @@ describe 'Vulcano::Resources::Passwd' do installed: true, } _(resource.installed?).must_equal true + _(resource.version).must_equal '40.0.3' + _(resource.info).must_equal pkg + end + + # catch cases where we recieve multiple return values + # eg. happens if you do 'choco install ruby' + it 'filter dups of Get-Package' do + resource = MockLoader.new(:windows).load_resource('oneget', 'Ruby 2.1.6-p336-x64') + pkg = { + name: 'Ruby 2.1.6-p336-x64', + version: '2.1.6-p336', + type: 'oneget', + installed: true, + } + _(resource.installed?).must_equal true + _(resource.version).must_equal '2.1.6-p336' + _(resource.info).must_equal pkg + end + + it 'should skip on linux' do + resource = MockLoader.new(:centos7).load_resource('oneget', 'Not available') + pkg = { type: 'oneget', installed: false } + _(resource.installed?).must_equal false + _(resource.version).must_equal nil _(resource.info).must_equal pkg end end