summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/chef/resource/chef_client_launchd.rb10
-rw-r--r--spec/unit/resource/chef_client_launchd.rb22
2 files changed, 29 insertions, 3 deletions
diff --git a/lib/chef/resource/chef_client_launchd.rb b/lib/chef/resource/chef_client_launchd.rb
index 34b6285661..0500991edc 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,8 +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.",
+ 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 a Integer between -20 and 19" => proc { |v| v >= -20 && v <= 19 } },
default: 0
property :low_priority_io, [true, false],
diff --git a/spec/unit/resource/chef_client_launchd.rb b/spec/unit/resource/chef_client_launchd.rb
index 6ec7889c79..4d07471ed5 100644
--- a/spec/unit/resource/chef_client_launchd.rb
+++ b/spec/unit/resource/chef_client_launchd.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(