diff options
author | Tim Smith <tsmith84@gmail.com> | 2020-08-26 14:40:15 -0700 |
---|---|---|
committer | Tim Smith <tsmith84@gmail.com> | 2020-08-26 14:40:15 -0700 |
commit | 92001258bd817b532b915ac53ac16f4762bd643e (patch) | |
tree | 583a0a14641bcebf777124611081c89ffb9fc974 | |
parent | ff8a59dab5091968171c69297c315a6943ea28ed (diff) | |
download | chef-92001258bd817b532b915ac53ac16f4762bd643e.tar.gz |
Validate nice values in the launchd resource
Make sure people give us proper nice values. Also the upper value is 19 not 20.
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r-- | lib/chef/resource/launchd.rb | 3 | ||||
-rw-r--r-- | spec/unit/resource/launchd_spec.rb | 8 |
2 files changed, 10 insertions, 1 deletions
diff --git a/lib/chef/resource/launchd.rb b/lib/chef/resource/launchd.rb index 70ff7b8974..a6125f7981 100644 --- a/lib/chef/resource/launchd.rb +++ b/lib/chef/resource/launchd.rb @@ -187,7 +187,8 @@ class Chef description: "Specify services to be registered with the bootstrap subsystem." property :nice, Integer, - description: "The program scheduling priority value in the range -20 to 20." + description: "The program scheduling priority value in the range -20 to 19.", + callbacks: { "should be a Integer between -20 and 19" => proc { |v| v >= -20 && v <= 19 } } property :on_demand, [ TrueClass, FalseClass ], description: "Keep a job alive. Only applies to macOS version 10.4 (and earlier); use keep_alive instead for newer versions." diff --git a/spec/unit/resource/launchd_spec.rb b/spec/unit/resource/launchd_spec.rb index bf3fd39952..62f5ad0b92 100644 --- a/spec/unit/resource/launchd_spec.rb +++ b/spec/unit/resource/launchd_spec.rb @@ -37,4 +37,12 @@ describe Chef::Resource::Launchd do expect { resource.action :enable }.not_to raise_error expect { resource.action :restart }.not_to raise_error 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 end |