summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorDavin Taddeo <davin@chef.io>2021-05-08 20:59:04 +0000
committerGitHub <noreply@github.com>2021-05-08 13:59:04 -0700
commitf83e0bc97520f5680c8aaff3e1a718773935b2c7 (patch)
treed9aa5cc9cf5cd643fe030287aad5cf91711b9ccc /spec
parentb741b801c4ab504ebbc3baea7c6ba2ea6ea0501d (diff)
downloadchef-f83e0bc97520f5680c8aaff3e1a718773935b2c7.tar.gz
Creating the `inspec_waiver_file_entry` resource for managing and formatting a waiver file (#10098)
Signed-off-by: Tim Smith <tsmith@chef.io>
Diffstat (limited to 'spec')
-rw-r--r--spec/unit/resource/inspec_waiver_file_entry_spec.rb80
1 files changed, 80 insertions, 0 deletions
diff --git a/spec/unit/resource/inspec_waiver_file_entry_spec.rb b/spec/unit/resource/inspec_waiver_file_entry_spec.rb
new file mode 100644
index 0000000000..716bf67464
--- /dev/null
+++ b/spec/unit/resource/inspec_waiver_file_entry_spec.rb
@@ -0,0 +1,80 @@
+#
+# Author:: Davin Taddeo (<davin@chef.io>)
+# Copyright:: Copyright (c) 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::InspecWaiverFileEntry do
+ let(:log_str) { "this is my string to log" }
+ let(:resource) { Chef::Resource::InspecWaiverFileEntry.new("fakey_fakerton") }
+
+ it "has a name of inspec_waiver_file_entry" do
+ expect(resource.resource_name).to eq(:inspec_waiver_file_entry)
+ end
+
+ it "setting the control property to a string does not raise error" do
+ expect { resource.control "my_test_control" }.not_to raise_error
+ end
+
+ it "sets the default action as :add" do
+ expect(resource.action).to eql([:add])
+ end
+
+ it "supports :add action" do
+ expect { resource.action :add }.not_to raise_error
+ end
+
+ it "supports :remove action" do
+ expect { resource.action :remove }.not_to raise_error
+ end
+
+ it "expects expiration property to fail with date format YYYY/MM/DD" do
+ expect { resource.expiration "2022/09/23" }.to raise_error(Chef::Exceptions::ValidationFailed)
+ end
+
+ it "expects expiration property to fail with invalid date 2022-02-31" do
+ expect { resource.expiration "2022-02-31" }.to raise_error(Chef::Exceptions::ValidationFailed)
+ end
+
+ it "expects expiration property to match YYYY-MM-DD" do
+ expect { resource.expiration "2022-09-23" }.not_to raise_error
+ end
+
+ it "expects the run_test property to fail validation when not a true/false value" do
+ expect { resource.run_test "yes" }.to raise_error(Chef::Exceptions::ValidationFailed)
+ end
+
+ it "expects the run_test property to only accept true or false values" do
+ expect { resource.run_test true }.not_to raise_error
+ end
+
+ it "expects the justification property to accept a string value" do
+ expect { resource.justification "Because I don't want to run this compliance test" }.not_to raise_error
+ end
+
+ it "expects the justification property to fail if given a non-string value" do
+ expect { resource.justification true }.to raise_error(Chef::Exceptions::ValidationFailed)
+ end
+
+ it "expects the backup property to fail validation when set to true" do
+ expect { resource.backup true }.to raise_error(Chef::Exceptions::ValidationFailed)
+ end
+
+ it "expects the backup property to fail validation when passed a string" do
+ expect { resource.backup "please" }.to raise_error(Chef::Exceptions::ValidationFailed)
+ end
+end