diff options
author | Jacob Zaval <jazava@microsoft.com> | 2022-03-10 13:17:54 -0800 |
---|---|---|
committer | Jacob Zaval <jazava@microsoft.com> | 2022-03-10 13:17:54 -0800 |
commit | 94a99f8e027ea418425682cc5820b202b6e656da (patch) | |
tree | 11dcea9c19ed449b99dc19ec94f5d651ba276e9e | |
parent | f932770f33d1f75e625da7375ab8732e43fdbcd6 (diff) | |
download | chef-94a99f8e027ea418425682cc5820b202b6e656da.tar.gz |
add functional spec for plist, fix hash implementation
Signed-off-by: Jacob Zaval <jazava@microsoft.com>
-rw-r--r-- | lib/chef/resource/plist.rb | 7 | ||||
-rw-r--r-- | spec/functional/resource/plist_spec.rb | 25 |
2 files changed, 31 insertions, 1 deletions
diff --git a/lib/chef/resource/plist.rb b/lib/chef/resource/plist.rb index 536b848eed..29aa246c73 100644 --- a/lib/chef/resource/plist.rb +++ b/lib/chef/resource/plist.rb @@ -189,7 +189,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)}" }.join(sep) + 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..c8158a8ad6 --- /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.strip.to_i).to eq(4) + end + end +end |