diff options
author | Bryan McLellan <btm@opscode.com> | 2014-02-27 13:50:40 -0800 |
---|---|---|
committer | Bryan McLellan <btm@loftninjas.org> | 2014-03-27 19:19:34 -0400 |
commit | 9e9cab6a89d9dab4ddf852b88eb522610d89f2d8 (patch) | |
tree | e5799c600477a37331f66e618201a042413e60e1 /spec | |
parent | df07eaf9e8905ca1fce72cf3186b30c600fd7251 (diff) | |
download | chef-9e9cab6a89d9dab4ddf852b88eb522610d89f2d8.tar.gz |
CHEF-5087: Add a Windows Installer package provider
Adds the framework for a windows package provider, which must determine the
correct provider by examining metadata about the source file, or the source
file itself.
Provides FFI based access to the Windows Installer functions to retrieve
metadata from the MSI files and from the Windows product database.
Combines both of these into an MSI package provider.
Continues to work alongside the windows_package LWRP.
Diffstat (limited to 'spec')
-rw-r--r-- | spec/unit/provider/package/windows/msi_spec.rb | 60 | ||||
-rw-r--r-- | spec/unit/provider/package/windows_spec.rb | 80 | ||||
-rw-r--r-- | spec/unit/resource/windows_package_spec.rb | 74 |
3 files changed, 214 insertions, 0 deletions
diff --git a/spec/unit/provider/package/windows/msi_spec.rb b/spec/unit/provider/package/windows/msi_spec.rb new file mode 100644 index 0000000000..69322a609d --- /dev/null +++ b/spec/unit/provider/package/windows/msi_spec.rb @@ -0,0 +1,60 @@ +# +# Author:: Bryan McLellan <btm@loftninjas.org> +# Copyright:: Copyright (c) 2014 Chef Software, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' + +describe Chef::Provider::Package::Windows::MSI do + let(:node) { double('Chef::Node') } + let(:events) { double('Chef::Events').as_null_object } # mock all the methods + let(:run_context) { double('Chef::RunContext', :node => node, :events => events) } + let(:new_resource) { Chef::Resource::WindowsPackage.new("calculator.msi") } + let(:provider) { Chef::Provider::Package::Windows::MSI.new(new_resource) } + + describe "expand_options" do + it "returns an empty string if passed no options" do + expect(provider.expand_options(nil)).to eql "" + end + + it "returns a string with a leading space if passed options" do + expect(provider.expand_options("--train nope --town no_way")).to eql(" --train nope --town no_way") + end + end + + describe "installed_version" do + it "returns the installed version" do + provider.stub(:get_product_property).and_return("{23170F69-40C1-2702-0920-000001000000}") + provider.stub(:get_installed_version).with("{23170F69-40C1-2702-0920-000001000000}").and_return("3.14159.1337.42") + expect(provider.installed_version).to eql("3.14159.1337.42") + end + end + + describe "package_version" do + it "returns the version of a package" do + provider.stub(:get_product_property).with(/calculator.msi$/, "ProductVersion").and_return(42) + expect(provider.package_version).to eql(42) + end + end + + describe "install_package" do + # calls shell_out! + end + + describe "remove_package" do + # calls shell_out! + end +end diff --git a/spec/unit/provider/package/windows_spec.rb b/spec/unit/provider/package/windows_spec.rb new file mode 100644 index 0000000000..962bf6fddf --- /dev/null +++ b/spec/unit/provider/package/windows_spec.rb @@ -0,0 +1,80 @@ +# +# Author:: Bryan McLellan <btm@loftninjas.org> +# Copyright:: Copyright (c) 2014 Chef Software, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' + +describe Chef::Provider::Package::Windows do + let(:node) { double('Chef::Node') } + let(:events) { double('Chef::Events').as_null_object } # mock all the methods + let(:run_context) { double('Chef::RunContext', :node => node, :events => events) } + let(:new_resource) { Chef::Resource::WindowsPackage.new("calculator.msi") } + let(:provider) { Chef::Provider::Package::Windows.new(new_resource, run_context) } + + describe "load_current_resource" do + before(:each) do + provider.stub(:package_provider).and_return(double('package_provider', + :installed_version => "1.0", :package_version => "2.0")) + end + + it "creates a current resource with the name of the new resource" do + provider.load_current_resource + expect(provider.current_resource).to be_a(Chef::Resource::WindowsPackage) + expect(provider.current_resource.name).to eql("calculator.msi") + end + + it "sets the current version if the package is installed" do + provider.load_current_resource + expect(provider.current_resource.version).to eql("1.0") + end + + it "sets the version to be installed" do + provider.load_current_resource + expect(provider.new_resource.version).to eql("2.0") + end + end + + describe "package_provider" do + it "sets the package provider to MSI if the the installer type is :msi" do + provider.stub(:installer_type).and_return(:msi) + expect(provider.package_provider).to be_a(Chef::Provider::Package::Windows::MSI) + end + + it "raises an error if the installer_type is unknown" do + provider.stub(:installer_type).and_return(:apt_for_windows) + expect { provider.package_provider }.to raise_error + end + end + + describe "installer_type" do + it "it returns @installer_type if it is set" do + provider.new_resource.installer_type("downeaster") + expect(provider.installer_type).to eql("downeaster") + end + + it "sets installer_type to msi if the source ends in .msi" do + provider.new_resource.source("microsoft_installer.msi") + expect(provider.installer_type).to eql(:msi) + end + + it "raises an error if it cannot determine the installer type" do + provider.new_resource.installer_type(nil) + provider.new_resource.source("tomfoolery.now") + expect { provider.installer_type }.to raise_error(ArgumentError) + end + end +end diff --git a/spec/unit/resource/windows_package_spec.rb b/spec/unit/resource/windows_package_spec.rb new file mode 100644 index 0000000000..23454e97e4 --- /dev/null +++ b/spec/unit/resource/windows_package_spec.rb @@ -0,0 +1,74 @@ +# +# Author:: Bryan McLellan <btm@loftninjas.org> +# Copyright:: Copyright (c) 2014 Chef Software, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' + +describe Chef::Resource::WindowsPackage, "initialize" do + + let(:resource) { Chef::Resource::WindowsPackage.new("solitaire.msi") } + + it "returns a Chef::Resource::WindowsPackage" do + expect(resource).to be_a_kind_of(Chef::Resource::WindowsPackage) + end + + it "sets the resource_name to :windows_package" do + expect(resource.resource_name).to eql(:windows_package) + end + + it "sets the provider to Chef::Provider::Package::Windows" do + expect(resource.provider).to eql(Chef::Provider::Package::Windows) + end + + it "supports setting installer_type" do + resource.installer_type("msi") + expect(resource.installer_type).to eql("msi") + end + + # String, Integer + [ "600", 600 ].each do |val| + it "supports setting a timeout as a #{val.class}" do + resource.timeout(val) + expect(resource.timeout).to eql(val) + end + end + + # String, Integer, Array + [ "42", 42, [47, 48, 49] ].each do |val| + it "supports setting an alternate return value as a #{val.class}" do + resource.returns(val) + expect(resource.returns).to eql(val) + end + end + + it "coverts a source to an absolute path" do + ::File.stub(:absolute_path).and_return("c:\\Files\\frost.msi") + resource.source("frost.msi") + expect(resource.source).to eql "c:\\Files\\frost.msi" + end + + it "converts slashes to backslashes in the source path" do + ::File.stub(:absolute_path).and_return("c:\\frost.msi") + resource.source("c:/frost.msi") + expect(resource.source).to eql "c:\\frost.msi" + end + + it "defaults source to the resource name" do + # it's a little late to stub out File.absolute_path + expect(resource.source).to include("solitaire.msi") + end +end |