diff options
author | Shahul Hameed <skhajamohid1@bloomberg.net> | 2015-12-23 14:36:03 -0500 |
---|---|---|
committer | Shahul Khajamohideen <skhajamohid1@bloomberg.net> | 2015-12-28 11:05:48 -0500 |
commit | 8e50394485b9558d0996159a3d961d46c903c729 (patch) | |
tree | 607804893e1357d36841a719fc1f72bc396eb36f | |
parent | c80f62c35ce480a89a00973ec62fafdf061f9340 (diff) | |
download | ohai-8e50394485b9558d0996159a3d961d46c903c729.tar.gz |
Add tests for packages plugin on windows
-rw-r--r-- | lib/ohai/plugins/packages.rb | 8 | ||||
-rw-r--r-- | spec/data/plugins/wmiproduct.output | 34 | ||||
-rw-r--r-- | spec/unit/plugins/packages_spec.rb | 122 |
3 files changed, 93 insertions, 71 deletions
diff --git a/lib/ohai/plugins/packages.rb b/lib/ohai/plugins/packages.rb index ada255c4..d6d3439c 100644 --- a/lib/ohai/plugins/packages.rb +++ b/lib/ohai/plugins/packages.rb @@ -1,6 +1,8 @@ # Author:: "Christian Höltje" <choltje@us.ibm.com> # Author:: "Christopher M. Luciano" <cmlucian@us.ibm.com> +# Author:: Shahul Khajamohideen (<skhajamohid1@bloomberg.net>) # Copyright (C) 2015 IBM Corp. +# Copyright (C) 2015 Bloomberg Finance L.P. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -54,9 +56,9 @@ Ohai.plugin(:Packages) do w32_product = wmi.instances_of('Win32_Product') w32_product.find_all.each do |product| - packagename = product['packagename'] - package = packages[packagename] = Mash.new - %w(name version vendor installdate).each do |attr| + name = product['name'] + package = packages[name] = Mash.new + %w(version vendor installdate).each do |attr| package[attr] = product[attr] end end diff --git a/spec/data/plugins/wmiproduct.output b/spec/data/plugins/wmiproduct.output deleted file mode 100644 index c5b80e94..00000000 --- a/spec/data/plugins/wmiproduct.output +++ /dev/null @@ -1,34 +0,0 @@ -[#<WmiLite::Wmi::Instance:0x27a7a00 @wmi_ole_object=#<WIN32OLE:0x27a7a18>, @property_map={"assignmenttype"=>0, "capti -on"=>"NXLOG-CE", "description"=>"NXLOG-CE", "helplink"=>nil, "helptelephone"=>nil, "identifyingnumber"=>"{22FA28AB-3C1B- -438B-A8B5-E23892C8B567}", "installdate"=>"20150511", "installdate2"=>nil, "installlocation"=>nil, "installsource"=>"C:\\ -chef\\cache\\", "installstate"=>5, "language"=>"1033", "localpackage"=>"C:\\Windows\\Installer\\30884.msi", "name"=>"NXL -OG-CE", "packagecache"=>"C:\\Windows\\Installer\\30884.msi", "packagecode"=>"{EC3A13C4-4634-47FC-9662-DC293CB96F9F}", "p -ackagename"=>"nexlog-ce-2.8.1248.msi", "productid"=>nil, "regcompany"=>nil, "regowner"=>nil, "skunumber"=>nil, "transfor -ms"=>nil, "urlinfoabout"=>nil, "urlupdateinfo"=>nil, "vendor"=>"nxsec.com", "version"=>"2.8.1248", "wordcount"=>2}>, #<W -miLite::Wmi::Instance:0x27a4910 @wmi_ole_object=#<WIN32OLE:0x27a4928>, @property_map={"assignmenttype"=>1, "caption"=>"M -icrosoft .NET Framework 4.5.1 Multi-Targeting Pack", "description"=>"Microsoft .NET Framework 4.5.1 Multi-Targeting Pack -", "helplink"=>nil, "helptelephone"=>nil, "identifyingnumber"=>"{6A0C6700-EA93-372C-8871-DCCF13D160A4}", "installdate"=> -"20150512", "installdate2"=>nil, "installlocation"=>nil, "installsource"=>"C:\\ProgramData\\Package Cache\\{6A0C6700-EA9 -3-372C-8871-DCCF13D160A4}v4.5.50932\\packages\\netfx_451mtpack\\", "installstate"=>5, "language"=>"1033", "localpackage" -=>"C:\\Windows\\Installer\\4853a5.msi", "name"=>"Microsoft .NET Framework 4.5.1 Multi-Targeting Pack", "packagecache"=>" -C:\\Windows\\Installer\\4853a5.msi", "packagecode"=>"{D6098F6F-BA25-46AC-8358-CEBEA010E3BA}", "packagename"=>"netfx_451m -tpack.msi", "productid"=>nil, "regcompany"=>nil, "regowner"=>nil, "skunumber"=>nil, "transforms"=>nil, "urlinfoabout"=>n -il, "urlupdateinfo"=>nil, "vendor"=>"Microsoft Corporation", "version"=>"4.5.50932", "wordcount"=>2}>, #<WmiLite::Wmi::I -nstance:0x278e4d0 @wmi_ole_object=#<WIN32OLE:0x278e4e8>, @property_map={"assignmenttype"=>1, "caption"=>"Microsoft SQL S -erver Compact 4.0 SP1 x64 ENU", "description"=>"Microsoft SQL Server Compact 4.0 SP1 x64 ENU", "helplink"=>"http://go.mi -crosoft.com/fwlink/?LinkId=81488", "helptelephone"=>nil, "identifyingnumber"=>"{78909610-D229-459C-A936-25D92283D3FD}", -"installdate"=>"20150512", "installdate2"=>nil, "installlocation"=>"C:\\Program Files\\Microsoft SQL Server Compact Edit -ion\\", "installsource"=>"C:\\Program Files (x86)\\Microsoft SQL Server Compact Edition\\Installer\\", "installstate"=>5 -, "language"=>"1033", "localpackage"=>"C:\\Windows\\Installer\\4854fb.msi", "name"=>"Microsoft SQL Server Compact 4.0 SP -1 x64 ENU", "packagecache"=>"C:\\Windows\\Installer\\4854fb.msi", "packagecode"=>"{22846EBD-F1FF-4067-B118-A5D71D3E938B} -", "packagename"=>"SSCERuntime_x64-ENU.msi", "productid"=>nil, "regcompany"=>nil, "regowner"=>nil, "skunumber"=>nil, "tr -ansforms"=>nil, "urlinfoabout"=>nil, "urlupdateinfo"=>nil, "vendor"=>"Microsoft Corporation", "version"=>"4.0.8876.1", " -wordcount"=>2}>, #<WmiLite::Wmi::Instance:0x278c538 @wmi_ole_object=#<WIN32OLE:0x278c550>, @property_map={"assignmenttyp -e"=>1, "caption"=>"Strawberry Perl (64-bit)", "description"=>"Strawberry Perl (64-bit)", "helplink"=>"http://strawberryp -erl.com/support.html", "helptelephone"=>nil, "identifyingnumber"=>"{843B6A60-6CF3-1014-B3E5-B42EDCB56166}", "installdate -"=>"20150512", "installdate2"=>nil, "installlocation"=>"C:\\strawberry\\", "installsource"=>"C:\\Users\\ADMINI~1\\AppDat -a\\Local\\Temp\\2\\chocolatey\\StrawberryPerl\\", "installstate"=>5, "language"=>"1033", "localpackage"=>"C:\\Windows\\I -nstaller\\8bf25.msi", "name"=>"Strawberry Perl (64-bit)", "packagecache"=>"C:\\Windows\\Installer\\8bf25.msi", "packagec -ode"=>"{BA2AE79C-7A4B-47FD-A032-D8950297EEB2}", "packagename"=>"StrawberryPerlInstall.MSI", "productid"=>nil, "regcompan -y"=>nil, "regowner"=>nil, "skunumber"=>nil, "transforms"=>nil, "urlinfoabout"=>"http://strawberryperl.com/", "urlupdatei -nfo"=>nil, "vendor"=>"strawberryperl.com project", "version"=>"5.16.3001", "wordcount"=>2}>] diff --git a/spec/unit/plugins/packages_spec.rb b/spec/unit/plugins/packages_spec.rb index 7496d7b3..437121c0 100644 --- a/spec/unit/plugins/packages_spec.rb +++ b/spec/unit/plugins/packages_spec.rb @@ -1,5 +1,7 @@ # Author:: Christopher M. Luciano (<cmlucian@us.ibm.com>) -# Copyright:: +# Author:: Shahul Khajamohideen (<skhajamohid1@bloomberg.net>) +# Copyright (C) 2015 IBM Corp. +# Copyright (C) 2015 Bloomberg Finance L.P. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,12 +19,10 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') -describe Ohai::System, "plugin packages" do - - context "on debian" do - - let (:plugin) do - get_plugin("packages").tap do |plugin| +describe Ohai::System, 'plugin packages' do + context 'on debian' do + let(:plugin) do + get_plugin('packages').tap do |plugin| plugin[:platform_family] = 'debian' end end @@ -34,27 +34,26 @@ describe Ohai::System, "plugin packages" do before(:each) do allow(plugin).to receive(:collect_os).and_return(:linux) allow(plugin).to receive(:shell_out) - .with("dpkg-query -W") - .and_return(mock_shell_out(0, stdout, "")) + .with('dpkg-query -W') + .and_return(mock_shell_out(0, stdout, '')) plugin.run end - it "calls dpkg query" do + it 'calls dpkg query' do expect(plugin).to receive(:shell_out) - .with("dpkg-query -W") - .and_return(mock_shell_out(0, stdout, "")) + .with('dpkg-query -W') + .and_return(mock_shell_out(0, stdout, '')) plugin.run end - it "gets the packages and versions" do - expect(plugin[:packages]['vim-common'][:version]).to eq("2:7.4.052-1ubuntu3") + it 'gets the packages and versions' do + expect(plugin[:packages]['vim-common'][:version]).to eq('2:7.4.052-1ubuntu3') end end - context "on fedora" do - - let (:plugin) do - get_plugin("packages").tap do |plugin| + context 'on fedora' do + let(:plugin) do + get_plugin('packages').tap do |plugin| plugin[:platform_family] = 'fedora' end end @@ -67,46 +66,101 @@ describe Ohai::System, "plugin packages" do before(:each) do allow(plugin).to receive(:collect_os).and_return(:linux) - allow(plugin).to receive(:shell_out).with("rpm -qa --queryformat #{format}").and_return(mock_shell_out(0, stdout, "")) + allow(plugin).to receive(:shell_out).with("rpm -qa --queryformat #{format}").and_return(mock_shell_out(0, stdout, '')) plugin.run end - it "calls rpm -qa" do + it 'calls rpm -qa' do expect(plugin).to receive(:shell_out) .with("rpm -qa --queryformat #{format}") - .and_return(mock_shell_out(0, stdout, "")) + .and_return(mock_shell_out(0, stdout, '')) plugin.run end - it "gets the packages and versions/release" do - expect(plugin[:packages]['vim-common'][:version]).to eq("7.2.411") - expect(plugin[:packages]['vim-common'][:release]).to eq("1.8.el6") + it 'gets the packages and versions/release' do + expect(plugin[:packages]['vim-common'][:version]).to eq('7.2.411') + expect(plugin[:packages]['vim-common'][:release]).to eq('1.8.el6') end end - context "on windows", :windows_only do - + context 'on windows', :windows_only do require 'wmi-lite' - let (:plugin) do - get_plugin("packages").tap do |plugin| + let(:plugin) do + get_plugin('packages').tap do |plugin| plugin[:platform_family] = 'windows' end end - let(:w32_product) do - File.read(File.join(SPEC_PLUGIN_PATH, 'wmiproduct.output')) + let(:win32_product_output) do + [{ 'assignmenttype' => 0, + 'caption' => 'NXLOG-CE', + 'description' => 'NXLOG-CE', + 'helplink' => nil, + 'helptelephone' => nil, + 'identifyingnumber' => '{22FA28AB-3C1B-438B-A8B5-E23892C8B567}', + 'installdate' => '20150511', + 'installdate2' => nil, + 'installlocation' => nil, + 'installsource' => 'C:\\chef\\cache\\', + 'installstate' => 5, + 'language' => '1033', + 'localpackage' => 'C:\\Windows\\Installer\\30884.msi', + 'name' => 'NXLOG-CE', + 'packagecache' => 'C:\\Windows\\Installer\\30884.msi', + 'packagecode' => '{EC3A13C4-4634-47FC-9662-DC293CB96F9F}', + 'packagename' => 'nexlog-ce-2.8.1248.msi', + 'productid' => nil, + 'regcompany' => nil, + 'regowner' => nil, + 'skunumber' => nil, + 'transforms' => nil, + 'urlinfoabout' => nil, + 'urlupdateinfo' => nil, + 'vendor' => 'nxsec.com', + 'version' => '2.8.1248', + 'wordcount' => 2 }, + { 'assignmenttype' => 1, + 'caption' => 'Chef Development Kit v0.7.0', + 'description' => 'Chef Development Kit v0.7.0', + 'helplink' => 'http://www.getchef.com/support/', + 'helptelephone' => nil, + 'identifyingnumber' => '{90754A33-404C-4172-8F3B-7F04CE98011C}', + 'installdate' => '20150925', 'installdate2' => nil, + 'installlocation' => nil, + 'installsource' => 'C:\\Users\\skhajamohid1\\Downloads\\', + 'installstate' => 5, 'language' => '1033', + 'localpackage' => 'C:\\WINDOWS\\Installer\\d9e1ca7.msi', + 'name' => 'Chef Development Kit v0.7.0', + 'packagecache' => 'C:\\WINDOWS\\Installer\\d9e1ca7.msi', + 'packagecode' => '{9B82FB86-40AE-4CDF-9DE8-97574F9395B9}', + 'packagename' => 'chefdk-0.7.0-1 (2).msi', + 'productid' => nil, + 'regcompany' => nil, + 'regowner' => nil, + 'skunumber' => nil, + 'transforms' => nil, + 'urlinfoabout' => nil, + 'urlupdateinfo' => nil, + 'vendor' => "\"Chef Software, Inc. <maintainers@chef.io>\"", + 'version' => '0.7.0.1', + 'wordcount' => 2 }] end before(:each) do allow(plugin).to receive(:collect_os).and_return(:windows) + expect_any_instance_of(WmiLite::Wmi).to receive(:instances_of).with('Win32_Product').and_return(win32_product_output) plugin.run end - it "gets the packages and versions/release" do - expect(plugin[:packages]['chefdk-0.6.2-1.msi'][:version]).to eq("0.6.2.1") - end + it 'gets the package info' do + expect(plugin[:packages]['Chef Development Kit v0.7.0'][:version]).to eq('0.7.0.1') + expect(plugin[:packages]['Chef Development Kit v0.7.0'][:vendor]).to eq("\"Chef Software, Inc. <maintainers@chef.io>\"") + expect(plugin[:packages]['Chef Development Kit v0.7.0'][:installdate]).to eq('20150925') + expect(plugin[:packages]['NXLOG-CE'][:version]).to eq('2.8.1248') + expect(plugin[:packages]['NXLOG-CE'][:vendor]).to eq('nxsec.com') + expect(plugin[:packages]['NXLOG-CE'][:installdate]).to eq('20150511') + end end - end |