summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2020-03-20 23:16:39 -0700
committerTim Smith <tsmith84@gmail.com>2020-03-23 15:46:31 -0700
commit65fbd27f8a7adf0a644123afb4046cbfc0179702 (patch)
treebd54441e76c2937dd6c27898fa1746e56805c24a /spec
parent9872480a7e679e383cbc289a1bb81042c6bbafcd (diff)
downloadchef-65fbd27f8a7adf0a644123afb4046cbfc0179702.tar.gz
Initial commit of unit tests
Signed-off-by: Tim Smith <tsmith@chef.io>
Diffstat (limited to 'spec')
-rw-r--r--spec/unit/resource/chef_client_cron_spec.rb64
1 files changed, 64 insertions, 0 deletions
diff --git a/spec/unit/resource/chef_client_cron_spec.rb b/spec/unit/resource/chef_client_cron_spec.rb
new file mode 100644
index 0000000000..a62be5d49e
--- /dev/null
+++ b/spec/unit/resource/chef_client_cron_spec.rb
@@ -0,0 +1,64 @@
+#
+# Author:: Tim Smith (<tsmith@chef.io>)
+# Copyright:: 2020, Chef Software Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+require "spec_helper"
+
+describe Chef::Resource::ChefClientCron do
+ let(:node) { Chef::Node.new }
+ let(:events) { Chef::EventDispatch::Dispatcher.new }
+ let(:run_context) { Chef::RunContext.new(node, {}, events) }
+ let(:resource) { Chef::Resource::ChefClientCron.new("fakey_fakerton", run_context) }
+ let(:provider) { resource.provider_for_action(:add) }
+
+ it "sets the default action as :add" do
+ expect(resource.action).to eql([:add])
+ 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
+ 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
+ node.automatic_attrs[:platform_family] = "ubuntu"
+ 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"
+ expect(provider.splay_sleep_time(300)).to eql("73399073")
+ end
+
+ it "uses a hex conversion of a md5 hash of the splay if present" do
+ node.automatic_attrs[:shard_seed] = nil
+ allow(node).to receive(:name).and_return("test_node")
+ expect(provider.splay_sleep_time(300)).to eql(114)
+ end
+ end
+end