summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2020-08-19 14:30:43 -0700
committerTim Smith <tsmith84@gmail.com>2020-08-19 14:57:03 -0700
commitd8fc57498efd4b96e09699d4d83df8d6ffad313d (patch)
treeffdce0554bedd8ac9886ebbc0ac56ad2d652d6c1
parent78ccdeaff047c1c8537a3dd686ba1f777858c1c5 (diff)
downloadchef-d8fc57498efd4b96e09699d4d83df8d6ffad313d.tar.gz
Add basic unit test of properties and the helper method
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--cspell.json2
-rw-r--r--lib/chef/resource/chef_client_trusted_certificate.rb1
-rw-r--r--spec/unit/resource/chef_client_trusted_certificate_spec.rb54
3 files changed, 56 insertions, 1 deletions
diff --git a/cspell.json b/cspell.json
index b93f247e1e..96ee3a0d21 100644
--- a/cspell.json
+++ b/cspell.json
@@ -16,6 +16,7 @@
"words": [
"abcz",
"Abdulin",
+ "badssl",
"ABORTIFHUNG",
"ACCOUNTDISABLE",
"activationkey",
@@ -1879,6 +1880,7 @@
"Zanetti",
"Zapp",
"zeproc",
+ "PATHEXT",
"ZEROEXEC",
"ZEROINIT",
"Zimmek",
diff --git a/lib/chef/resource/chef_client_trusted_certificate.rb b/lib/chef/resource/chef_client_trusted_certificate.rb
index d0124ba2ca..855407b12a 100644
--- a/lib/chef/resource/chef_client_trusted_certificate.rb
+++ b/lib/chef/resource/chef_client_trusted_certificate.rb
@@ -81,7 +81,6 @@ class Chef
action :remove do
file cert_path do
action :delete
- mode "0640"
end
end
diff --git a/spec/unit/resource/chef_client_trusted_certificate_spec.rb b/spec/unit/resource/chef_client_trusted_certificate_spec.rb
new file mode 100644
index 0000000000..07ba8acd90
--- /dev/null
+++ b/spec/unit/resource/chef_client_trusted_certificate_spec.rb
@@ -0,0 +1,54 @@
+#
+# 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::ChefClientTrustedCertificate do
+ let(:node) { Chef::Node.new }
+ let(:events) { Chef::EventDispatch::Dispatcher.new }
+ let(:run_context) { Chef::RunContext.new(node, {}, events) }
+ let(:resource) { Chef::Resource::ChefClientTrustedCertificate.new("foo", run_context) }
+ let(:provider) { resource.provider_for_action(:add) }
+
+ it "has a resource name of :chef_client_trusted_certificate" do
+ expect(resource.resource_name).to eql(:chef_client_trusted_certificate)
+ end
+
+ it "has a name property of cert_name" do
+ expect(resource.cert_name).to eql("foo")
+ end
+
+ it "sets the default action as :add" do
+ expect(resource.action).to eql([:add])
+ end
+
+ it "supports :remove action" do
+ expect { resource.action :remove }.not_to raise_error
+ end
+
+ describe "#cert_path" do
+ it "appends .pem to new_resource.cert_name value" do
+ resource.cert_name "something"
+ expect(provider.cert_path).to match(/trusted_certs\/something.pem$/)
+ end
+
+ it "does not append .pem if cert_name already ends in .pem" do
+ resource.cert_name "something.pem"
+ expect(provider.cert_path).to match(/trusted_certs\/something.pem$/)
+ end
+ end
+end