summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2020-07-21 16:03:10 -0700
committerTim Smith <tsmith84@gmail.com>2020-07-21 16:24:57 -0700
commit0a10e6a135d76aab768ed997d9bb63a1826c2d52 (patch)
treed2a5f7654021b8e34885d1add76b21f7c36e722f
parent135d99c2f1daa01982340aa1cf076d16f9a45cdd (diff)
downloadchef-0a10e6a135d76aab768ed997d9bb63a1826c2d52.tar.gz
Add testing of :delete action and fix failures
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--kitchen-tests/cookbooks/end_to_end/recipes/_macos_userdefaults.rb22
-rw-r--r--lib/chef/resource/macos_userdefaults.rb5
-rw-r--r--test.rb54
3 files changed, 21 insertions, 60 deletions
diff --git a/kitchen-tests/cookbooks/end_to_end/recipes/_macos_userdefaults.rb b/kitchen-tests/cookbooks/end_to_end/recipes/_macos_userdefaults.rb
index 9d61ee5df6..3f907c3428 100644
--- a/kitchen-tests/cookbooks/end_to_end/recipes/_macos_userdefaults.rb
+++ b/kitchen-tests/cookbooks/end_to_end/recipes/_macos_userdefaults.rb
@@ -41,7 +41,7 @@ macos_userdefaults "Bogus key with array value" do
domain "/Library/Preferences/ManagedInstalls"
type "array"
key "LogFileArray"
- value [ '/Library/Managed Installs/fake.log', '/Library/Managed Installs/also_fake.log']
+ value [ "/Library/Managed Installs/fake.log", "/Library/Managed Installs/also_fake.log"]
end
# test that we can set a dict
@@ -49,13 +49,27 @@ macos_userdefaults "Bogus key with dict value" do
domain "/Library/Preferences/ManagedInstalls"
type "dict"
key "LogFileDict"
- value "User": '/Library/Managed Installs/way_fake.log'
+ value "User": "/Library/Managed Installs/way_fake.log"
end
# test that we can set a bool
-macos_userdefaults 'Bogus key with boolean value' do
+macos_userdefaults "Bogus key with boolean value" do
domain "/Library/Preferences/ManagedInstalls"
- key 'LoggingIsTheThingToDoRight'
+ key "LoggingIsTheThingToDoRight"
value "yes"
type "bool"
end
+
+# test that we can handle the 2nd client run with :delete
+macos_userdefaults "bogus key" do
+ domain "/Library/Preferences/com.apple.alf"
+ key "globalstatenope"
+ action :delete
+end
+
+# try to delete a key we known is there
+macos_userdefaults "delete a key" do
+ domain "/Library/Preferences/ManagedInstalls"
+ key "LoggingIsTheThingToDoRight"
+ action :delete
+end
diff --git a/lib/chef/resource/macos_userdefaults.rb b/lib/chef/resource/macos_userdefaults.rb
index 7f89b093d0..431fa67eaa 100644
--- a/lib/chef/resource/macos_userdefaults.rb
+++ b/lib/chef/resource/macos_userdefaults.rb
@@ -36,7 +36,7 @@ class Chef
```ruby
macos_userdefaults 'Full keyboard access to all controls' do
key 'AppleKeyboardUIMode'
- value '2'
+ value 2
end
```
@@ -161,7 +161,8 @@ class Chef
action :delete do
description "Delete a key from a domain."
- return unless current_resource.key # if it's not there there's nothing to remove
+ # if it's not there there's nothing to remove
+ return unless current_resource
converge_by("delete domain:#{new_resource.domain} key:#{new_resource.key}") do
diff --git a/test.rb b/test.rb
deleted file mode 100644
index 19b7fd7d2d..0000000000
--- a/test.rb
+++ /dev/null
@@ -1,54 +0,0 @@
-# macos_userdefaults 'Delete non-existent domain' do
-# domain '/Library/Preferences/TimTest'
-# key 'File'
-# action :delete
-# end
-
-# macos_userdefaults 'Add key to new domain' do
-# domain '/Library/Preferences/TimTest'
-# key 'File'
-# value '/usr/local/tim'
-# end
-
-# macos_userdefaults 'Add key to new domain' do
-# domain '/Library/Preferences/TimTest'
-# key 'File'
-# value '/usr/local/tim'
-# end
-
-macos_userdefaults 'Add String key' do
- domain '~/Library/Preferences/unity.BrickLink.Studio.plist'
- key 'StringKey2'
- value '/usr/local/tim2'
-end
-
-macos_userdefaults 'Add boolean key' do
- domain '~/Library/Preferences/unity.BrickLink.Studio.plist'
- key 'BooleanKey'
- value true
-end
-
-macos_userdefaults 'Add array key' do
- domain '~/Library/Preferences/unity.BrickLink.Studio.plist'
- key 'ArrayKey'
- value %w(one two three)
-end
-
-
-# macos_userdefaults 'enable macOS firewall' do
-# domain '/Library/Preferences/com.apple.alf'
-# key 'globalstate'
-# value '1'
-# type 'int'
-# end
-
-# macos_userdefaults 'Bad string test' do
-# domain '/Library/Preferences/ManagedInstalls'
-# key 'Log File'
-# value '/Library/Managed Installs/Logs/ManagedSoftwareUpdate.log'
-# end
-
-
-
-# Bugs:
-# Create/Delete on domain that doesn't exist fails