summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorVasu1105 <vasundhara.jagdale@clogeny.com>2016-09-26 14:11:09 +0530
committerVasu1105 <vasundhara.jagdale@clogeny.com>2016-09-30 17:27:23 +0530
commit8e32fd5ed4665245523a4e02a8bba5f773afe42b (patch)
tree455727d618fce001f4b5d25fdccd31bd67535aed /spec
parent09b44d56bc3f9285360b6b93f7798e6de4dd8dfd (diff)
downloadchef-8e32fd5ed4665245523a4e02a8bba5f773afe42b.tar.gz
Fixed review comments
Signed-off-by: Vasu1105 <vasundhara.jagdale@clogeny.com>
Diffstat (limited to 'spec')
-rw-r--r--spec/data/templates/chef-seattle20160930-4388-1crv7ef.txt1
-rw-r--r--spec/data/templates/chef-seattle20160930-4388-jjfoae.txt1
-rw-r--r--spec/data/templates/chef-seattle20160930-4388-umeq2c.txt1
-rw-r--r--spec/functional/assets/dummy-cab-23448.cabbin1455340 -> 0 bytes
-rw-r--r--spec/functional/resource/cab_package_spec.rb54
-rw-r--r--spec/unit/provider/package/cab_spec.rb49
6 files changed, 41 insertions, 65 deletions
diff --git a/spec/data/templates/chef-seattle20160930-4388-1crv7ef.txt b/spec/data/templates/chef-seattle20160930-4388-1crv7ef.txt
new file mode 100644
index 0000000000..f476ccd704
--- /dev/null
+++ b/spec/data/templates/chef-seattle20160930-4388-1crv7ef.txt
@@ -0,0 +1 @@
+Do do do do, do do do do, do do do do, do do do do \ No newline at end of file
diff --git a/spec/data/templates/chef-seattle20160930-4388-jjfoae.txt b/spec/data/templates/chef-seattle20160930-4388-jjfoae.txt
new file mode 100644
index 0000000000..f476ccd704
--- /dev/null
+++ b/spec/data/templates/chef-seattle20160930-4388-jjfoae.txt
@@ -0,0 +1 @@
+Do do do do, do do do do, do do do do, do do do do \ No newline at end of file
diff --git a/spec/data/templates/chef-seattle20160930-4388-umeq2c.txt b/spec/data/templates/chef-seattle20160930-4388-umeq2c.txt
new file mode 100644
index 0000000000..f476ccd704
--- /dev/null
+++ b/spec/data/templates/chef-seattle20160930-4388-umeq2c.txt
@@ -0,0 +1 @@
+Do do do do, do do do do, do do do do, do do do do \ No newline at end of file
diff --git a/spec/functional/assets/dummy-cab-23448.cab b/spec/functional/assets/dummy-cab-23448.cab
deleted file mode 100644
index 41eea0b77c..0000000000
--- a/spec/functional/assets/dummy-cab-23448.cab
+++ /dev/null
Binary files differ
diff --git a/spec/functional/resource/cab_package_spec.rb b/spec/functional/resource/cab_package_spec.rb
deleted file mode 100644
index c0750ed480..0000000000
--- a/spec/functional/resource/cab_package_spec.rb
+++ /dev/null
@@ -1,54 +0,0 @@
-#
-# Author:: Vasundhara Jagdale (<vasundhara.jagdale@msystechnologies.com>)
-# Copyright:: Copyright 2015-2016, 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"
-require "chef/mixin/powershell_out"
-
-describe Chef::Resource::CabPackage, :windows_only do
- include Chef::Mixin::PowershellOut
-
- let(:package_source) { File.join(CHEF_SPEC_ASSETS, "dummy-cab-23448.cab") }
-
- let(:new_resource) do
- new_resource = Chef::Resource::CabPackage.new("test-package", run_context)
- new_resource.source = package_source
- new_resource
- end
-
- let(:installed_version) { proc { stdout = powershell_out!("dism.exe /Online /Get-PackageInfo /PackagePath:\"#{new_resource.source}\" /NoRestart").stdout } }
-
- context "installing package" do
- after { remove_package }
-
- it "installs the package" do
- new_resource.run_action(:install)
- expect(new_resource).to be_updated_by_last_action
- end
-
- it "raises error if package is not found" do
- new_resource.source = File.join(CHEF_SPEC_ASSETS, "test.cab")
- expect { new_resource.run_action(:install) }.to raise_error Chef::Exceptions::Package
- end
- end
-end
-
-def remove_package
- pkg_to_remove = Chef::Resource::CabPackage.new("test-package", run_context)
- pkg_to_remove.source = package_source
- pkg_to_remove.run_action(:remove)
-end
diff --git a/spec/unit/provider/package/cab_spec.rb b/spec/unit/provider/package/cab_spec.rb
index 9ce0c77485..5e16795aa8 100644
--- a/spec/unit/provider/package/cab_spec.rb
+++ b/spec/unit/provider/package/cab_spec.rb
@@ -51,13 +51,13 @@ The operation completed successfully
before do
new_resource.source = "C:\\Temp\\Test6.1-KB2664825-v3-x64.cab"
installed_package_list_obj = double(stdout: installed_package_list_stdout)
- allow(provider).to receive(:powershell_out).with("dism.exe /Online /Get-Packages /NoRestart", { timeout: timeout }).and_return(installed_package_list_obj)
+ allow(provider).to receive(:dism_command).with("/Get-Packages").and_return(installed_package_list_obj)
package_version_obj = double(stdout: package_version_stdout)
- allow(provider).to receive(:powershell_out).with("dism.exe /Online /Get-PackageInfo /PackagePath:\"#{new_resource.source}\" /NoRestart", { timeout: timeout }).and_return(package_version_obj)
+ allow(provider).to receive(:dism_command).with("/Get-PackageInfo /PackagePath:\"#{new_resource.source}\"").and_return(package_version_obj)
end
def allow_package_info(package_path = nil, package_name = nil)
- get_pakage_info_stdout = <<-EOF
+ get_package_info_stdout = <<-EOF
Deployment Image Servicing and Management tool
Version: 6.1.7600.16385
@@ -72,15 +72,15 @@ State : Installed
Dependency : Language Pack
The operation completed successfully
EOF
- get_pakage_info_obj = double(stdout: get_pakage_info_stdout)
+ get_package_info_obj = double(stdout: get_package_info_stdout)
if package_path
- allow(provider).to receive(:powershell_out).with("dism.exe /Online /Get-PackageInfo /PackagePath:\"#{package_path}\" /NoRestart", { timeout: timeout }).and_return(get_pakage_info_obj)
+ allow(provider).to receive(:dism_command).with("/Get-PackageInfo /PackagePath:\"#{package_path}\"").and_return(get_package_info_obj)
else
- allow(provider).to receive(:powershell_out).with("dism.exe /Online /Get-PackageInfo /PackageName:\"#{package_name}\" /NoRestart", { timeout: timeout }).and_return(get_pakage_info_obj)
+ allow(provider).to receive(:dism_command).with("/Get-PackageInfo /PackageName:\"#{package_name}\"").and_return(get_package_info_obj)
end
end
- def allow_get_packags
+ def allow_get_packages
get_packages_stdout = <<-EOF
Deployment Image Servicing and Management tool
Version: 6.1.7600.16385
@@ -107,7 +107,7 @@ Install Time : 11/21/2010 3:40 AM
The operation completed successfully.
EOF
get_packages_obj = double(stdout: get_packages_stdout)
- allow(provider).to receive(:powershell_out).with("dism.exe /Online /Get-Packages /NoRestart", { timeout: timeout }).and_return(get_packages_obj)
+ allow(provider).to receive(:dism_command).with("/Get-Packages").and_return(get_packages_obj)
end
describe "#load_current_resource" do
@@ -142,7 +142,7 @@ The operation completed successfully.
describe "#installed_version" do
it "returns the current installed version of package" do
allow_package_info(new_resource.source, nil)
- allow_get_packags
+ allow_get_packages
allow_package_info(nil, "Package_for_KB2664825~31bf3856ad364e35~amd64~~6.1.3.0")
expect(provider.installed_version).to eql("6.1.3.0")
end
@@ -158,7 +158,7 @@ The operation completed successfully.
it "removes packages if package is installed" do
allow_package_info(new_resource.source, nil)
- allow_get_packags
+ allow_get_packages
allow_package_info(nil, "Package_for_KB2664825~31bf3856ad364e35~amd64~~6.1.3.0")
provider.load_current_resource
expect(provider.installed_version).not_to eql(nil)
@@ -179,7 +179,7 @@ The operation completed successfully.
it "does not install package if already installed" do
allow_package_info(new_resource.source, nil)
- allow_get_packags
+ allow_get_packages
allow_package_info(nil, "Package_for_KB2664825~31bf3856ad364e35~amd64~~6.1.3.0")
provider.load_current_resource
expect(provider.installed_version).not_to eql(nil)
@@ -188,4 +188,31 @@ The operation completed successfully.
expect(new_resource).not_to be_updated_by_last_action
end
end
+
+ context "Invalid package source" do
+ def package_version_stdout
+ package_version_stdout = <<-EOF
+
+Deployment Image Servicing and Management tool
+Version: 6.1.7600.16385
+
+Image Version: 6.1.7600.16385
+
+An error occurred trying to open - c:\\temp\\test6.1-KB2664825-v3-x64.cab Error: 0x80070003
+Error: 3
+The system cannot find the path specified.
+The DISM log file can be found at C:\\Windows\\Logs\\DISM\\dism.log.
+ EOF
+ end
+
+ before do
+ new_resource.source = "C:\\Temp\\Test6.1-KB2664825-v3-x64.cab"
+ installed_package_list_obj = double(stdout: installed_package_list_stdout)
+ allow(provider).to receive(:dism_command).with("/Get-Packages").and_return(installed_package_list_obj)
+ end
+
+ it "raises error for invalid source path or file" do
+ expect { provider.load_current_resource }.to raise_error(Chef::Exceptions::Package, "DISM: The system cannot find the path or file specified.")
+ end
+ end
end