summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2020-03-23 17:02:04 -0700
committerTim Smith <tsmith84@gmail.com>2020-03-23 17:02:47 -0700
commit9a38a1d341c3260d0a8796d0afd302f6cca9c6a6 (patch)
tree1bd93803edc6668659cf2089f3da4b3a4646095a /spec
parentcea81cc0c83ec374b26eb19a4f0ae007670edeb6 (diff)
downloadchef-9a38a1d341c3260d0a8796d0afd302f6cca9c6a6.tar.gz
Fix some bugs in command generation and add specs
Signed-off-by: Tim Smith <tsmith@chef.io>
Diffstat (limited to 'spec')
-rw-r--r--spec/unit/resource/chef_client_cron_spec.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/spec/unit/resource/chef_client_cron_spec.rb b/spec/unit/resource/chef_client_cron_spec.rb
index a62be5d49e..fec9461eeb 100644
--- a/spec/unit/resource/chef_client_cron_spec.rb
+++ b/spec/unit/resource/chef_client_cron_spec.rb
@@ -61,4 +61,40 @@ describe Chef::Resource::ChefClientCron do
expect(provider.splay_sleep_time(300)).to eql(114)
end
end
+
+ describe "#cron_command" do
+ before do
+ node.automatic_attrs[:shard_seed] = "73399073"
+ end
+
+ it "creates a valid command if using all default properties" do
+ expect(provider.cron_command).to eql("/bin/sleep 73399073; /opt/chef/bin/chef-client > /var/log/chef/client.log 2>&1")
+ end
+
+ it "uses daemon_options if set" do
+ resource.daemon_options ["--foo 1", "--bar 2"]
+ expect(provider.cron_command).to eql("/bin/sleep 73399073; /opt/chef/bin/chef-client --foo 1 --bar 2 > /var/log/chef/client.log 2>&1")
+ end
+
+ it "uses custom log files / paths if set" do
+ resource.log_file_name "my-client.log"
+ resource.log_directory "/var/log/my-chef/"
+ expect(provider.cron_command).to eql("/bin/sleep 73399073; /opt/chef/bin/chef-client > /var/log/my-chef/my-client.log 2>&1")
+ end
+
+ it "uses mailto if set" do
+ resource.mailto "bob@example.com"
+ expect(provider.cron_command).to eql("/bin/sleep 73399073; /opt/chef/bin/chef-client > /var/log/chef/client.log 2>&1 || echo \"Chef Infra Client execution failed\"")
+ end
+
+ it "uses custom chef-client binary if set" do
+ resource.chef_binary_path "/usr/local/bin/chef-client"
+ expect(provider.cron_command).to eql("/bin/sleep 73399073; /usr/local/bin/chef-client > /var/log/chef/client.log 2>&1")
+ end
+
+ it "appends to the log file appending if set" do
+ resource.append_log_file true
+ expect(provider.cron_command).to eql("/bin/sleep 73399073; /opt/chef/bin/chef-client >> /var/log/chef/client.log 2>&1")
+ end
+ end
end