-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cab_Package: dh/url support cab #5732
Conversation
new_resource.version(package_version) | ||
current_resource.version(installed_version) | ||
current_resource | ||
end | ||
|
||
def cab_file_source | ||
@cab_file_source ||= uri_scheme?(new_resource.source) ? download_source_file : @new_resource.source |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tiniest nitpick: use new_resource.source
instead of @new_resource.source
@@ -18,7 +18,7 @@ | |||
|
|||
require "spec_helper" | |||
|
|||
describe Chef::Provider::Package::Cab do | |||
describe Chef::Provider::Package::Cab, :windows_only do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unit tests shouldn't need :windows_only
-- if you need this it indicates you're probably missing some kind of a stub/mock
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I unit tested that on my local without adding filter :windows_only
and it ran properly however Travis was failing since it was using linux environment and file-path was mismatched.
See https://travis-ci.org/chef/chef/jobs/192942094#L2093 .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might consider using platform agnostic paths in the tests like: "#{ENV['TEMP']}/Test6.1-KB2664825-v3-x64.cab"
instead of C:\\Temp\\Test6.1-KB2664825-v3-x64.cab
.
@@ -54,6 +54,7 @@ | |||
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(:dism_command).with("/Get-PackageInfo /PackagePath:\"#{new_resource.source}\"").and_return(package_version_obj) | |||
allow_any_instance_of(Chef::Provider::Package::Cab).to receive(:dism_command).with("/Get-PackageInfo /PackagePath:\"#{new_resource.source}\"").and_return(package_version_obj) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
allow_any_instance_of
is usually codesmell for tests -- can this just be allow(provider).to receive....
? although that seems to be the prior line.... i'm somewhat confused as to why this is necessary...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @lamont-granquist . I will remove this last line.
end | ||
|
||
it "returns a clean cache path where the cab file is downloaded" do | ||
allow(Chef::FileCache).to receive(:create_cache_path).and_return("C:\\chef\\abc\\package") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should probably expect
instead of allow
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @lamont-granquist . Replacing allow
with expect
works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great! Before merging I would attend to @lamont-granquist 's comments
27d9953
to
dcdc183
Compare
Signed-off-by: dheerajd-msys <dheeraj.dubey@msystechnologies.com>
Signed-off-by: dheerajd-msys <dheeraj.dubey@msystechnologies.com>
Signed-off-by: dheerajd-msys <dheeraj.dubey@msystechnologies.com>
Signed-off-by: dheerajd-msys <dheeraj.dubey@msystechnologies.com>
Signed-off-by: dheerajd-msys <dheeraj.dubey@msystechnologies.com>
Signed-off-by: dheerajd-msys <dheeraj.dubey@msystechnologies.com>
Signed-off-by: dheerajd-msys <dheeraj.dubey@msystechnologies.com>
Signed-off-by: dheerajd-msys <dheeraj.dubey@msystechnologies.com>
dcdc183
to
0cb3aba
Compare
@mwrock @lamont-granquist re-review? |
@@ -126,6 +127,49 @@ def allow_get_packages | |||
end | |||
end | |||
|
|||
describe "#source_resource" do | |||
before do | |||
cab_file = "C:\\Temp\\Test6.1-KB2664825-v3-x64.cab" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
source_resource
method is called for URLs. I am a bit doubtful if cab_file
should be given a local path here.
allow(provider).to receive(:cab_file_source).and_return(new_resource.source) | ||
provider.load_current_resource | ||
if windows? | ||
expect(provider.cab_file_source).to be == File.join("#{ENV['TEMP'].downcase}", "\\", "test6.1-kb2664825-v3-x64.cab") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cab_file_source
is stubbed at line#164 and then we are expecting it's value. This spec needs modification.
it "returns local cab file source path if same is set" do | ||
new_resource.source = File.join("#{ENV['TEMP']}", "test6.1-kb2664825-v3-x64.cab") | ||
allow(provider).to receive(:cab_file_source).and_return(new_resource.source) | ||
provider.load_current_resource |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check if it's required to call load_current_resource
here? Can we directly call cab_file_source
method since the spec belongs to that method?
else | ||
expect(provider).to receive(:download_source_file).and_return(File.join("#{ENV['TEMP']}", "test6.1-kb2664825-v3-x64.cab")) | ||
end | ||
provider.load_current_resource |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The spec is for cab_file_source
method. It should ideally be verifying the output of that method only. Please check if load_current_resource
needs to be called.
Signed-off-by: dheerajd-msys <dheeraj.dubey@msystechnologies.com>
Signed-off-by: dheerajd-msys <dheeraj.dubey@msystechnologies.com>
16b6c61
to
558759b
Compare
This PR is created to fix issues which I committed on #5700