summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2017-12-15 09:25:46 -0800
committerGitHub <noreply@github.com>2017-12-15 09:25:46 -0800
commitdaebb1e6be72e27fb3e39e050e0d32d35c31a24e (patch)
tree3504b74a88b8911137ecba19b03b4da061265e89
parent1c487ab5977446746f9b389e429707ec8142b063 (diff)
parentbeff611b6f40e5bcb005a822b1e5c4a989e588ad (diff)
downloadchef-daebb1e6be72e27fb3e39e050e0d32d35c31a24e.tar.gz
Merge pull request #6671 from chef/resource_fixes
Avoid a few initializers in resources by using the DSL we have
-rw-r--r--lib/chef/resource/cab_package.rb6
-rw-r--r--lib/chef/resource/chocolatey_package.rb6
-rw-r--r--lib/chef/resource/dsc_script.rb1
-rw-r--r--lib/chef/resource/env.rb1
-rw-r--r--lib/chef/resource/msu_package.rb10
-rw-r--r--lib/chef/resource/windows_task.rb14
-rw-r--r--spec/unit/resource/msu_package_spec.rb8
-rw-r--r--spec/unit/resource/windows_task_spec.rb2
8 files changed, 16 insertions, 32 deletions
diff --git a/lib/chef/resource/cab_package.rb b/lib/chef/resource/cab_package.rb
index b7acfb0ec9..73e639814d 100644
--- a/lib/chef/resource/cab_package.rb
+++ b/lib/chef/resource/cab_package.rb
@@ -24,15 +24,11 @@ class Chef
class CabPackage < Chef::Resource::Package
include Chef::Mixin::Uris
+ resource_name :cab_package
provides :cab_package, os: "windows"
allowed_actions :install, :remove
- def initialize(name, run_context = nil)
- super
- @resource_name = :cab_package
- end
-
property :source, String,
coerce: (proc do |s|
unless s.nil?
diff --git a/lib/chef/resource/chocolatey_package.rb b/lib/chef/resource/chocolatey_package.rb
index a443b9a1d7..77bdcb197a 100644
--- a/lib/chef/resource/chocolatey_package.rb
+++ b/lib/chef/resource/chocolatey_package.rb
@@ -22,15 +22,11 @@ class Chef
class Resource
class ChocolateyPackage < Chef::Resource::Package
+ resource_name :chocolatey_package
provides :chocolatey_package, os: "windows"
allowed_actions :install, :upgrade, :remove, :uninstall, :purge, :reconfig
- def initialize(name, run_context = nil)
- super
- @resource_name = :chocolatey_package
- end
-
# windows can't take Array options yet
property :options, String
diff --git a/lib/chef/resource/dsc_script.rb b/lib/chef/resource/dsc_script.rb
index 7da29a651a..7682c7e778 100644
--- a/lib/chef/resource/dsc_script.rb
+++ b/lib/chef/resource/dsc_script.rb
@@ -24,6 +24,7 @@ class Chef
class DscScript < Chef::Resource
include Chef::DSL::Powershell
+ resource_name :dsc_script
provides :dsc_script, os: "windows"
default_action :run
diff --git a/lib/chef/resource/env.rb b/lib/chef/resource/env.rb
index 746369f02d..7071be4b91 100644
--- a/lib/chef/resource/env.rb
+++ b/lib/chef/resource/env.rb
@@ -20,6 +20,7 @@
class Chef
class Resource
class Env < Chef::Resource
+ resource_name :env
provides :env, os: "windows"
default_action :create
diff --git a/lib/chef/resource/msu_package.rb b/lib/chef/resource/msu_package.rb
index 753992c185..65959c5621 100644
--- a/lib/chef/resource/msu_package.rb
+++ b/lib/chef/resource/msu_package.rb
@@ -24,18 +24,14 @@ class Chef
class MsuPackage < Chef::Resource::Package
include Chef::Mixin::Uris
+ resource_name :msu_package
provides :msu_package, os: "windows"
allowed_actions :install, :remove
-
- def initialize(name, run_context = nil)
- super
- @resource_name = :msu_package
- @source = name
- @action = :install
- end
+ 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)
diff --git a/lib/chef/resource/windows_task.rb b/lib/chef/resource/windows_task.rb
index 78076e08e5..344ce50b64 100644
--- a/lib/chef/resource/windows_task.rb
+++ b/lib/chef/resource/windows_task.rb
@@ -22,19 +22,13 @@ class Chef
class Resource
class WindowsTask < Chef::Resource
+ resource_name :windows_task
provides :windows_task, os: "windows"
allowed_actions :create, :delete, :run, :end, :enable, :disable
default_action :create
- def initialize(name, run_context = nil)
- super
- @resource_name = :windows_task
- @task_name = name
- @action = :create
- end
-
- property :task_name, String, regex: [/\A[^\/\:\*\?\<\>\|]+\z/]
+ property :task_name, String, regex: [/\A[^\/\:\*\?\<\>\|]+\z/], name_property: true
property :command, String
property :cwd, String
property :user, String, default: "SYSTEM"
@@ -59,7 +53,7 @@ class Chef
property :months, String
property :idle_time, Integer
property :random_delay, [String, Integer]
- property :execution_time_limit, [String, Integer], default: "PT72H" # 72 hours in ISO08601 duration format
+ property :execution_time_limit, [String, Integer], default: "PT72H" # 72 hours in ISO8601 duration format
attr_accessor :exists, :status, :enabled
@@ -71,7 +65,7 @@ class Chef
end
if execution_time_limit
- unless execution_time_limit == "PT72H" # don't double convert an iso08601 format duration
+ unless execution_time_limit == "PT72H" # don't double convert an ISO8601 format duration
raise ArgumentError, "Invalid value passed for `execution_time_limit`. Please pass seconds as an Integer (e.g. 60) or a String with numeric values only (e.g. '60')." unless numeric_value_in_string?(execution_time_limit)
duration = sec_to_dur(execution_time_limit)
execution_time_limit(duration)
diff --git a/spec/unit/resource/msu_package_spec.rb b/spec/unit/resource/msu_package_spec.rb
index 349a382b31..66aacbc020 100644
--- a/spec/unit/resource/msu_package_spec.rb
+++ b/spec/unit/resource/msu_package_spec.rb
@@ -31,16 +31,16 @@ describe Chef::Resource::MsuPackage do
expect(resource.resource_name).to eql(:msu_package)
end
- it "sets the source as it's name" do
- expect(resource.source).to eql("test_pkg")
+ 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)
+ 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)
+ expect { resource.action :abc }.to raise_error(Chef::Exceptions::ValidationFailed)
end
it "coerce its name to a package_name" do
diff --git a/spec/unit/resource/windows_task_spec.rb b/spec/unit/resource/windows_task_spec.rb
index 131df524fc..fe0c55ecaf 100644
--- a/spec/unit/resource/windows_task_spec.rb
+++ b/spec/unit/resource/windows_task_spec.rb
@@ -35,7 +35,7 @@ describe Chef::Resource::WindowsTask do
end
it "sets the default action as :create" do
- expect(resource.action).to eql(:create)
+ expect(resource.action).to eql([:create])
end
it "sets the default user as System" do