summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThom May <thom@may.lt>2017-12-18 10:32:11 +0000
committerGitHub <noreply@github.com>2017-12-18 10:32:11 +0000
commit5660d0ebf249794f1591749f0953eccdf0658040 (patch)
treebada54f48c568f317e2eb556afde0c7a1991f70e
parent10252cc8f4f855d5de65efb645583f89bf8771f2 (diff)
parente04eb4a65d30e9a140bb02ccb597d5dc33508a64 (diff)
downloadchef-5660d0ebf249794f1591749f0953eccdf0658040.tar.gz
Merge pull request #6686 from chef/msu_and_cab_defaults
Fix bugs in handling 'source' in msu_package and cab_package
-rw-r--r--lib/chef/resource/cab_package.rb3
-rw-r--r--lib/chef/resource/msu_package.rb4
-rw-r--r--spec/unit/resource/cab_package_spec.rb20
-rw-r--r--spec/unit/resource/msu_package_spec.rb22
4 files changed, 37 insertions, 12 deletions
diff --git a/lib/chef/resource/cab_package.rb b/lib/chef/resource/cab_package.rb
index 73e639814d..fcf3f02b86 100644
--- a/lib/chef/resource/cab_package.rb
+++ b/lib/chef/resource/cab_package.rb
@@ -34,7 +34,8 @@ class Chef
unless s.nil?
uri_scheme?(s) ? s : Chef::Util::PathHelper.canonical_path(s, false)
end
- end)
+ end),
+ default: lazy { |r| r.package_name }
end
end
end
diff --git a/lib/chef/resource/msu_package.rb b/lib/chef/resource/msu_package.rb
index 65959c5621..93c8fbbe21 100644
--- a/lib/chef/resource/msu_package.rb
+++ b/lib/chef/resource/msu_package.rb
@@ -31,12 +31,12 @@ class Chef
default_action :install
property :source, String,
- name_property: true,
coerce: (proc do |s|
unless s.nil?
uri_scheme?(s) ? s : Chef::Util::PathHelper.canonical_path(s, false)
end
- end)
+ end),
+ default: lazy { |r| r.package_name }
property :checksum, String, desired_state: false
end
end
diff --git a/spec/unit/resource/cab_package_spec.rb b/spec/unit/resource/cab_package_spec.rb
index aa4890f171..38b9322958 100644
--- a/spec/unit/resource/cab_package_spec.rb
+++ b/spec/unit/resource/cab_package_spec.rb
@@ -32,7 +32,25 @@ describe Chef::Resource::CabPackage do
expect(resource.resource_name).to eql(:cab_package)
end
- it "coerce its name to a package_name" do
+ it "sets the default action as :install" do
+ expect(resource.action).to eql([:install])
+ end
+
+ it "coerces name property to package_name property" do
expect(resource.package_name).to eql("test_pkg")
end
+
+ it "coerces name property to a source property if source not provided" do
+ expect(resource.source).to end_with("test_pkg")
+ end
+
+ it "coerces name property to a source property if source not provided and package_name is" do
+ resource.package_name("package.cab")
+ expect(resource.source).to end_with("package.cab")
+ end
+
+ it "coerces source property if it does not looks like a path" do
+ resource.source("package.cab")
+ expect(resource.source).not_to eq("package.cab")
+ end
end
diff --git a/spec/unit/resource/msu_package_spec.rb b/spec/unit/resource/msu_package_spec.rb
index 66aacbc020..8b4926798a 100644
--- a/spec/unit/resource/msu_package_spec.rb
+++ b/spec/unit/resource/msu_package_spec.rb
@@ -31,19 +31,25 @@ describe Chef::Resource::MsuPackage do
expect(resource.resource_name).to eql(:msu_package)
end
- it "sets the source as its name and then coerces it to a path" do
- expect(resource.source).to end_with("test_pkg")
- end
-
it "sets the default action as :install" do
expect(resource.action).to eql([:install])
end
- it "raises error if invalid action is given" do
- expect { resource.action :abc }.to raise_error(Chef::Exceptions::ValidationFailed)
+ it "coerces name property to package_name property" do
+ expect(resource.package_name).to eql("test_pkg")
end
- it "coerce its name to a package_name" do
- expect(resource.package_name).to eql("test_pkg")
+ it "coerces name property to a source property if source not provided" do
+ expect(resource.source).to end_with("test_pkg")
+ end
+
+ it "coerces name property to a source property if source not provided and package_name is" do
+ resource.package_name("package.msu")
+ expect(resource.source).to end_with("package.msu")
+ end
+
+ it "coerces source property if it does not looks like a path" do
+ resource.source("package.msu")
+ expect(resource.source).not_to eq("package.msu")
end
end