summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn McCrae <john.mccrae@progress.com>2022-03-29 16:59:12 -0700
committerGitHub <noreply@github.com>2022-03-29 16:59:12 -0700
commita7b347ceb49f66ee5797ae578fbbcc4e45983aee (patch)
treef9de14f6f8ae6c4e0c7b6577e640340c11c13de3
parentc6177fd7cb1d2910dc470c9d0a85da97481b007c (diff)
parenta04935965f828c3f5b63fe51fe2774f844a90f20 (diff)
downloadchef-a7b347ceb49f66ee5797ae578fbbcc4e45983aee.tar.gz
Merge pull request #12680 from jazaval/plist-file-content
The windows tests were bypassed because they are running on Server 2016 which is deprecated on Github Actions
-rw-r--r--lib/chef/resource/plist.rb9
-rw-r--r--spec/functional/resource/plist_spec.rb25
2 files changed, 32 insertions, 2 deletions
diff --git a/lib/chef/resource/plist.rb b/lib/chef/resource/plist.rb
index 6783ae5f51..d316d81b2a 100644
--- a/lib/chef/resource/plist.rb
+++ b/lib/chef/resource/plist.rb
@@ -84,7 +84,7 @@ class Chef
converge_if_changed :path do
converge_by "create new plist: '#{new_resource.path}'" do
file new_resource.path do
- content {}.to_plist
+ content({}.to_plist)
owner new_resource.owner
group new_resource.group
mode new_resource.mode if property_is_set?(:mode)
@@ -188,7 +188,12 @@ class Chef
sep = " "
arg = case subcommand.to_s
when "add"
- type_to_commandline_string(value)
+ if value.is_a?(Hash)
+ sep = ":"
+ value.map { |k, v| "#{k} #{type_to_commandline_string(v)}" }
+ else
+ type_to_commandline_string(value)
+ end
when "set"
if value.is_a?(Hash)
sep = ":"
diff --git a/spec/functional/resource/plist_spec.rb b/spec/functional/resource/plist_spec.rb
new file mode 100644
index 0000000000..324a01c0c6
--- /dev/null
+++ b/spec/functional/resource/plist_spec.rb
@@ -0,0 +1,25 @@
+require "spec_helper"
+require "plist"
+
+describe Chef::Resource::PlistResource, :macos_only, requires_root: true do
+ include RecipeDSLHelper
+
+ let(:global_prefs) do
+ File.join(Dir.mktmpdir, ".GlobalPreferences.plist")
+ end
+
+ before(:each) do
+ FileUtils.rm_f global_prefs
+ end
+
+ context "make Monday the first DOW" do
+ it "creates a new plist with a hash value" do
+ plist global_prefs do
+ entry "AppleFirstWeekday"
+ value(gregorian: 4)
+ end
+ expect(File.exist?(global_prefs))
+ expect(shell_out!("/usr/libexec/PlistBuddy -c 'Print :\"AppleFirstWeekday\":gregorian' \"#{global_prefs}\"").stdout.to_i).to eq(4)
+ end
+ end
+end