summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2020-03-23 19:48:14 -0700
committerTim Smith <tsmith84@gmail.com>2020-03-23 20:10:35 -0700
commit3116f5a5dc8d80216e2c28e1be52c97e7eb4da8c (patch)
tree2276b6bb5e897014f721cab8453caf8c8b50361f
parent9745b76aaa950d035fe6c0c6bbc1f13b99ec79ae (diff)
downloadchef-3116f5a5dc8d80216e2c28e1be52c97e7eb4da8c.tar.gz
Validate that splay values are positive
Add some tests for this and fix the naming of other tests Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/chef/resource/chef_client_cron.rb4
-rw-r--r--spec/unit/resource/chef_client_cron_spec.rb13
2 files changed, 14 insertions, 3 deletions
diff --git a/lib/chef/resource/chef_client_cron.rb b/lib/chef/resource/chef_client_cron.rb
index e4ed4bca8f..f90575c7f0 100644
--- a/lib/chef/resource/chef_client_cron.rb
+++ b/lib/chef/resource/chef_client_cron.rb
@@ -93,6 +93,8 @@ class Chef
property :splay, [Integer, String],
default: 300,
+ coerce: proc { |x| Integer(x) },
+ callbacks: { "should be a positive number" => proc { |v| v > 0 } },
description: "A random number of seconds between 0 and X to add to interval so that all #{Chef::Dist::CLIENT} commands don't execute at the same time."
property :environment, Hash,
@@ -123,7 +125,7 @@ class Chef
description: "The path to the #{Chef::Dist::CLIENT} binary."
property :daemon_options, Array,
- default: [],
+ default: lazy { [] },
description: "An array of options to pass to the #{Chef::Dist::CLIENT} command."
action :add do
diff --git a/spec/unit/resource/chef_client_cron_spec.rb b/spec/unit/resource/chef_client_cron_spec.rb
index 2d67efdb31..094bedc91a 100644
--- a/spec/unit/resource/chef_client_cron_spec.rb
+++ b/spec/unit/resource/chef_client_cron_spec.rb
@@ -29,17 +29,26 @@ describe Chef::Resource::ChefClientCron do
expect(resource.action).to eql([:add])
end
+ it "coerces splay to an Integer" do
+ resource.splay "10"
+ expect(resource.splay).to eql(10)
+ end
+
+ it "raises an error if splay is not a positive number" do
+ expect { resource.splay("-10") }.to raise_error(Chef::Exceptions::ValidationFailed)
+ end
+
it "builds a default value for chef_binary_path dist values" do
expect(resource.chef_binary_path).to eql("/opt/chef/bin/chef-client")
end
- it "log_directory is on macOS" do
+ it "log_directory is /Library/Logs/Chef on macOS systems" do
node.automatic_attrs[:platform_family] = "mac_os_x"
node.automatic_attrs[:platform] = "mac_os_x"
expect(resource.log_directory).to eql("/Library/Logs/Chef")
end
- it "log_directory is on non-macOS systems" do
+ it "log_directory is /var/log/chef on non-macOS systems" do
node.automatic_attrs[:platform_family] = "ubuntu"
expect(resource.log_directory).to eql("/var/log/chef")
end