summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2018-03-16 17:01:46 -0700
committerGitHub <noreply@github.com>2018-03-16 17:01:46 -0700
commit42640eb657a517e1222dc4b9f4335365f58affb9 (patch)
treef1f7601ae154ec473eefba7db70114a4a6c95d7b /spec
parent8e9c3623b2a37dd51dc0e57466661306dd30a77d (diff)
parentaef5db08b4b236f0751013d8ee244f7fbea41475 (diff)
downloadchef-42640eb657a517e1222dc4b9f4335365f58affb9.tar.gz
Merge pull request #6979 from chef/sudo
Add the sudo resource from the sudo resource
Diffstat (limited to 'spec')
-rw-r--r--spec/unit/resource/sudo_spec.rb87
1 files changed, 87 insertions, 0 deletions
diff --git a/spec/unit/resource/sudo_spec.rb b/spec/unit/resource/sudo_spec.rb
new file mode 100644
index 0000000000..660eb285da
--- /dev/null
+++ b/spec/unit/resource/sudo_spec.rb
@@ -0,0 +1,87 @@
+#
+# Copyright:: Copyright 2018, 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::Sudo do
+
+ let(:node) { Chef::Node.new }
+ let(:events) { Chef::EventDispatch::Dispatcher.new }
+ let(:run_context) { Chef::RunContext.new(node, {}, events) }
+ let(:resource) { Chef::Resource::Sudo.new("someone", run_context) }
+
+ it "has a resource name of :sudo" do
+ expect(resource.resource_name).to eql(:sudo)
+ end
+
+ it "has a default action of create" do
+ expect(resource.action).to eql([:create])
+ end
+
+ it "the filename property is the name property" do
+ expect(resource.filename).to eql("someone")
+ end
+
+ it "coerces filename property values . & ~ to __" do
+ resource.filename "something.something~"
+ expect(resource.filename).to eql("something__something__")
+ end
+
+ it "supports the legacy 'user' property" do
+ resource.user ["foo"]
+ expect(resource.users).to eql(["foo"])
+ end
+
+ it "supports the legacy 'groups' property" do
+ resource.group ["%foo"]
+ expect(resource.groups).to eql(["%foo"])
+ end
+
+ it "coerces users & groups String vals to Arrays" do
+ resource.users "something"
+ resource.groups "%something"
+ expect(resource.users).to eql(["something"])
+ expect(resource.groups).to eql(["%something"])
+ end
+
+ it "coerces users & group String vals no matter the spacing" do
+ resource.users "user1, user2 , user3 ,user4"
+ resource.groups "group1, group2 , group3 ,group4"
+ expect(resource.users).to eql(%w{user1 user2 user3 user4})
+ expect(resource.groups).to eql(["%group1", "%group2", "%group3", "%group4"])
+ end
+
+ it "coerces groups values to properly start with %" do
+ resource.groups ["foo", "%bar"]
+ expect(resource.groups).to eql(["%foo", "%bar"])
+ end
+
+ it "it sets the config prefix to /etc on linux" do
+ node.automatic[:platform_family] = "debian"
+ expect(resource.config_prefix).to eql("/etc")
+ end
+
+ it "it sets the config prefix to /private/etc on macOS" do
+ node.automatic[:platform_family] = "mac_os_x"
+ expect(resource.config_prefix).to eql("/private/etc")
+ end
+
+ it "it sets the config prefix to /opt/local/etc on smartos" do
+ node.automatic[:platform_family] = "smartos"
+ expect(resource.config_prefix).to eql("/opt/local/etc")
+ end
+end