summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2020-08-26 19:17:05 -0700
committerTim Smith <tsmith84@gmail.com>2020-08-27 15:18:55 -0700
commit3f02bd1eed113c10164400cde477d5dae871f86d (patch)
tree0138da57bd0d95c84c985d2e3c422551208e1e61
parent66f45381f0ad332ef6d2f80645d54bd45c3e8f4e (diff)
downloadchef-3f02bd1eed113c10164400cde477d5dae871f86d.tar.gz
Rename the cron_command method for easier diffing
This makes the specs easier to diff. I also shuffled around some specs 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.rb38
2 files changed, 21 insertions, 21 deletions
diff --git a/lib/chef/resource/chef_client_cron.rb b/lib/chef/resource/chef_client_cron.rb
index 7e216a75a3..ab435c39f8 100644
--- a/lib/chef/resource/chef_client_cron.rb
+++ b/lib/chef/resource/chef_client_cron.rb
@@ -164,7 +164,7 @@ class Chef
mailto new_resource.mailto if new_resource.mailto
user new_resource.user
comment new_resource.comment if new_resource.comment
- command cron_command
+ command client_command
end
end
@@ -193,7 +193,7 @@ class Chef
#
# @return [String]
#
- def cron_command
+ def client_command
cmd = ""
cmd << "/bin/sleep #{splay_sleep_time(new_resource.splay)}; "
cmd << "#{which("nice")} -n #{new_resource.nice} " if new_resource.nice
diff --git a/spec/unit/resource/chef_client_cron_spec.rb b/spec/unit/resource/chef_client_cron_spec.rb
index 00d12b82a8..25286de106 100644
--- a/spec/unit/resource/chef_client_cron_spec.rb
+++ b/spec/unit/resource/chef_client_cron_spec.rb
@@ -29,6 +29,11 @@ describe Chef::Resource::ChefClientCron do
expect(resource.action).to eql([:add])
end
+ it "supports :add and :remove actions" do
+ expect { resource.action :add }.not_to raise_error
+ expect { resource.action :remove }.not_to raise_error
+ end
+
it "coerces splay to an Integer" do
resource.splay "10"
expect(resource.splay).to eql(10)
@@ -38,6 +43,10 @@ describe Chef::Resource::ChefClientCron 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 "raises an error if nice is less than -20" do
expect { resource.nice(-21) }.to raise_error(Chef::Exceptions::ValidationFailed)
end
@@ -51,10 +60,6 @@ describe Chef::Resource::ChefClientCron do
expect(resource.nice).to eql(10)
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 /Library/Logs/Chef on macOS systems" do
node.automatic_attrs[:platform_family] = "mac_os_x"
node.automatic_attrs[:platform] = "mac_os_x"
@@ -66,11 +71,6 @@ describe Chef::Resource::ChefClientCron do
expect(resource.log_directory).to eql("/var/log/chef")
end
- it "supports :add and :remove actions" do
- expect { resource.action :add }.not_to raise_error
- expect { resource.action :remove }.not_to raise_error
- end
-
describe "#splay_sleep_time" do
it "uses shard_seed attribute if present" do
node.automatic_attrs[:shard_seed] = "73399073"
@@ -84,7 +84,7 @@ describe Chef::Resource::ChefClientCron do
end
end
- describe "#cron_command" do
+ describe "#client_command" do
before do
allow(provider).to receive(:splay_sleep_time).and_return("123")
end
@@ -92,55 +92,55 @@ describe Chef::Resource::ChefClientCron do
let(:root_path) { windows? ? "C:\\chef/client.rb" : "/etc/chef/client.rb" }
it "creates a valid command if using all default properties" do
- expect(provider.cron_command).to eql(
+ expect(provider.client_command).to eql(
"/bin/sleep 123; /opt/chef/bin/chef-client -c #{root_path} -L /var/log/chef/client.log"
)
end
it "uses daemon_options if set" do
resource.daemon_options ["--foo 1", "--bar 2"]
- expect(provider.cron_command).to eql(
+ expect(provider.client_command).to eql(
"/bin/sleep 123; /opt/chef/bin/chef-client --foo 1 --bar 2 -c #{root_path} -L /var/log/chef/client.log"
)
end
it "uses custom config dir if set" do
resource.config_directory "/etc/some_other_dir"
- expect(provider.cron_command).to eql("/bin/sleep 123; /opt/chef/bin/chef-client -c /etc/some_other_dir/client.rb -L /var/log/chef/client.log")
+ expect(provider.client_command).to eql("/bin/sleep 123; /opt/chef/bin/chef-client -c /etc/some_other_dir/client.rb -L /var/log/chef/client.log")
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(
+ expect(provider.client_command).to eql(
"/bin/sleep 123; /opt/chef/bin/chef-client -c #{root_path} -L /var/log/my-chef/my-client.log"
)
end
it "uses mailto if set" do
resource.mailto "bob@example.com"
- expect(provider.cron_command).to eql(
+ expect(provider.client_command).to eql(
"/bin/sleep 123; /opt/chef/bin/chef-client -c #{root_path} -L /var/log/chef/client.log || 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(
+ expect(provider.client_command).to eql(
"/bin/sleep 123; /usr/local/bin/chef-client -c #{root_path} -L /var/log/chef/client.log"
)
end
it "appends to the log file appending if set to false" do
resource.append_log_file false
- expect(provider.cron_command).to eql(
+ expect(provider.client_command).to eql(
"/bin/sleep 123; /opt/chef/bin/chef-client -c #{root_path} > /var/log/chef/client.log 2>&1"
)
end
it "sets the license acceptance flag if set" do
resource.accept_chef_license true
- expect(provider.cron_command).to eql(
+ expect(provider.client_command).to eql(
"/bin/sleep 123; /opt/chef/bin/chef-client -c #{root_path} --chef-license accept -L /var/log/chef/client.log"
)
end
@@ -148,7 +148,7 @@ describe Chef::Resource::ChefClientCron do
it "uses nice if set" do
allow(provider).to receive(:which).with("nice").and_return("/usr/bin/nice")
resource.nice(-15)
- expect(provider.cron_command).to eql(
+ expect(provider.client_command).to eql(
"/bin/sleep 123; /usr/bin/nice -n -15 /opt/chef/bin/chef-client -c /etc/chef/client.rb -L /var/log/chef/client.log"
)
end