Skip to content
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

Merged
merged 10 commits into from
Jan 30, 2017

Conversation

dheerajd-msys
Copy link
Contributor

@dheerajd-msys dheerajd-msys commented Jan 18, 2017

This PR is created to fix issues which I committed on #5700

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
Copy link
Contributor

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
Copy link
Contributor

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

Copy link
Contributor Author

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 .

Copy link
Member

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)
Copy link
Contributor

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...

Copy link
Contributor Author

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")
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Member

@mwrock mwrock left a 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

@thommay thommay added Type: Enhancement Adds new functionality. and removed Enhancement labels Jan 25, 2017
@piyushawasthi piyushawasthi force-pushed the dh/url_support_cab branch 5 times, most recently from 27d9953 to dcdc183 Compare January 27, 2017 11:46
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>
@btm
Copy link
Contributor

btm commented Jan 27, 2017

@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"

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")

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

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

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>
@mwrock mwrock merged commit 3862a7d into chef:master Jan 30, 2017
@lamont-granquist lamont-granquist changed the title dh/url support cab Cab_Package: dh/url support cab Feb 17, 2017
@chef chef locked and limited conversation to collaborators Nov 16, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants