summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrishichawda <rishichawda@users.noreply.github.com>2021-10-06 23:03:30 +0530
committerrishichawda <rishichawda@users.noreply.github.com>2021-10-06 23:03:30 +0530
commit7c783e3c14885f68aa0d540a6011273046c1f678 (patch)
tree4f34ad1368dbc480fe58d7997547bb3961c3bc1f
parent1b811ab164e9170676d67b6f88c1129e1b44f07c (diff)
downloadchef-7c783e3c14885f68aa0d540a6011273046c1f678.tar.gz
functional tests
Signed-off-by: rishichawda <rishichawda@users.noreply.github.com>
-rw-r--r--spec/functional/resource/macos_userdefaults_spec.rb119
1 files changed, 119 insertions, 0 deletions
diff --git a/spec/functional/resource/macos_userdefaults_spec.rb b/spec/functional/resource/macos_userdefaults_spec.rb
new file mode 100644
index 0000000000..45dd655413
--- /dev/null
+++ b/spec/functional/resource/macos_userdefaults_spec.rb
@@ -0,0 +1,119 @@
+#
+# 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::MacosUserDefaults do
+ def create_resource
+ node = Chef::Node.new
+ events = Chef::EventDispatch::Dispatcher.new
+ run_context = Chef::RunContext.new(node, {}, events)
+ resource = Chef::Resource::MacosUserDefaults.new("test", run_context)
+ resource
+ end
+
+ let(:resource) do
+ create_resource
+ end
+
+ context "has a default value" do
+ it ":macos_userdefaults for resource name" do
+ expect(resource.name).to eq("test")
+ end
+
+ it "NSGlobalDomain for the domain property" do
+ expect(resource.domain).to eq("NSGlobalDomain")
+ end
+
+ it "nil for the host property" do
+ expect(resource.host).to be_nil
+ end
+
+ it "nil for the user property" do
+ expect(resource.user).to be_nil
+ end
+
+ it ":write for resource action" do
+ expect(resource.action).to eq([:write])
+ end
+ end
+
+ it "supports :write, :delete actions" do
+ expect { resource.action :write }.not_to raise_error
+ expect { resource.action :delete }.not_to raise_error
+ end
+
+ context "can process expected data" do
+ it "set array values" do
+ resource.domain "/Library/Preferences/ManagedInstalls"
+ resource.key "TestArrayValues"
+ resource.value [ "/Library/Managed Installs/fake.log", "/Library/Managed Installs/also_fake.log"]
+ resource.run_action(:write)
+ expect(resource.get_preference resource).to eq([ "/Library/Managed Installs/fake.log", "/Library/Managed Installs/also_fake.log"])
+ end
+
+ it "set dictionary value" do
+ resource.domain "/Library/Preferences/ManagedInstalls"
+ resource.key "TestDictionaryValues"
+ resource.value "User": "/Library/Managed Installs/way_fake.log"
+ resource.run_action(:write)
+ expect(resource.get_preference resource).to eq("User" => "/Library/Managed Installs/way_fake.log")
+ end
+
+ it "set array of dictionaries" do
+ resource.domain "/Library/Preferences/ManagedInstalls"
+ resource.key "TestArrayWithDictionary"
+ resource.value [ { "User": "/Library/Managed Installs/way_fake.log" } ]
+ resource.run_action(:write)
+ expect(resource.get_preference resource).to eq([ { "User"=> "/Library/Managed Installs/way_fake.log" } ])
+ end
+
+ it "set boolean for preference value" do
+ resource.domain "/Library/Preferences/ManagedInstalls"
+ resource.key "TestBooleanValue"
+ resource.value true
+ resource.run_action(:write)
+ expect(resource.get_preference resource).to eq(true)
+ end
+
+ it "sets value to global domain when domain is not passed" do
+ resource.key "TestKey"
+ resource.value 1
+ resource.run_action(:write)
+ expect(resource.get_preference resource).to eq(1)
+ end
+
+ it "short domain names" do
+ resource.domain "com.apple.dock"
+ resource.key "titlesize"
+ resource.value "20"
+ resource.run_action(:write)
+ expect(resource.get_preference resource).to eq("20")
+ end
+ end
+
+ it "we can delete a preference with full path" do
+ resource.domain "/Library/Preferences/ManagedInstalls"
+ resource.key "TestKey"
+ expect { resource.run_action(:delete) }. to_not raise_error
+ end
+
+ it "we can delete a preference with short name" do
+ resource.domain "com.apple.dock"
+ resource.key "titlesize"
+ expect { resource.run_action(:delete) }. to_not raise_error
+ end
+end