summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2020-08-26 15:02:46 -0700
committerGitHub <noreply@github.com>2020-08-26 15:02:46 -0700
commit3cca65b641a4dab175e23d0e505a4032caa740a4 (patch)
tree0e9c4f53b339fe4637b56bad21fdfaf6cd7083a4
parentd3f88ab5ebdc7d053f9710334bb8245507452262 (diff)
parent23b03189365fb612f628c9bd2a6d4000bf9d2e78 (diff)
downloadchef-3cca65b641a4dab175e23d0e505a4032caa740a4.tar.gz
Merge pull request #10357 from chef/better_launchd_properties
Improve input handling and validation in chef_client_launchd
-rw-r--r--lib/chef/resource/chef_client_launchd.rb11
-rw-r--r--spec/unit/resource/chef_client_launchd_spec.rb (renamed from spec/unit/resource/chef_client_launchd.rb)22
2 files changed, 29 insertions, 4 deletions
diff --git a/lib/chef/resource/chef_client_launchd.rb b/lib/chef/resource/chef_client_launchd.rb
index 34b6285661..704fd47ad1 100644
--- a/lib/chef/resource/chef_client_launchd.rb
+++ b/lib/chef/resource/chef_client_launchd.rb
@@ -52,8 +52,10 @@ class Chef
description: "The working directory to run the #{Chef::Dist::PRODUCT} from.",
default: "/var/root"
- property :interval, Integer,
+ property :interval, [Integer, String],
description: "Time in minutes between #{Chef::Dist::PRODUCT} executions.",
+ coerce: proc { |x| Integer(x) },
+ callbacks: { "should be a positive number" => proc { |v| v > 0 } },
default: 30
property :accept_chef_license, [true, false],
@@ -84,9 +86,10 @@ class Chef
default: lazy { {} },
description: "A Hash containing additional arbitrary environment variables under which the launchd daemon will be run in the form of `({'ENV_VARIABLE' => 'VALUE'})`."
- property :nice, Integer,
- description: "The process priority to run the #{Chef::Dist::CLIENT} process at.",
- default: 0
+ property :nice, [Integer, String],
+ description: "The process priority to run the #{Chef::Dist::CLIENT} process at. A value of -20 is the highest priority and 19 is the lowest priority.",
+ coerce: proc { |x| Integer(x) },
+ callbacks: { "should be an Integer between -20 and 19" => proc { |v| v >= -20 && v <= 19 } }
property :low_priority_io, [true, false],
description: "Run the #{Chef::Dist::CLIENT} process with low priority disk IO",
diff --git a/spec/unit/resource/chef_client_launchd.rb b/spec/unit/resource/chef_client_launchd_spec.rb
index 6ec7889c79..4d07471ed5 100644
--- a/spec/unit/resource/chef_client_launchd.rb
+++ b/spec/unit/resource/chef_client_launchd_spec.rb
@@ -38,6 +38,28 @@ describe Chef::Resource::ChefClientLaunchd do
expect { resource.action :disable }.not_to raise_error
end
+ it "raises an error if interval is not a positive number" do
+ expect { resource.interval("-10") }.to raise_error(Chef::Exceptions::ValidationFailed)
+ end
+
+ it "coerces interval to an Integer" do
+ resource.interval "10"
+ expect(resource.interval).to eql(10)
+ end
+
+ it "raises an error if nice is less than -20" do
+ expect { resource.nice(-21) }.to raise_error(Chef::Exceptions::ValidationFailed)
+ end
+
+ it "raises an error if nice is greater than 19" do
+ expect { resource.nice(20) }.to raise_error(Chef::Exceptions::ValidationFailed)
+ end
+
+ it "coerces nice to an Integer" do
+ resource.nice "10"
+ expect(resource.nice).to eql(10)
+ end
+
describe "#all_daemon_options" do
it "returns log and config flags if by default" do
expect(provider.all_daemon_options).to eql(