summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmulya <logwolvy+github@gmail.com>2021-07-09 16:48:52 +0530
committerAmulya <logwolvy+github@gmail.com>2021-07-09 16:50:05 +0530
commit7f06bb1648f2a1af4d305c5bb6c3255edfe96550 (patch)
treea517ce6b4644e5f498cf335d0bcb1b031a3ed11f
parent66d932f7e5a331434e9353af7788f596824e3eb4 (diff)
downloadchef-7f06bb1648f2a1af4d305c5bb6c3255edfe96550.tar.gz
Fix PR commentsmacos-userdefaults-poc
-rw-r--r--lib/chef/resource/macos_userdefaults.rb34
-rw-r--r--spec/unit/resource/macos_user_defaults_spec.rb6
2 files changed, 24 insertions, 16 deletions
diff --git a/lib/chef/resource/macos_userdefaults.rb b/lib/chef/resource/macos_userdefaults.rb
index 37ad5e5a9c..30061f1617 100644
--- a/lib/chef/resource/macos_userdefaults.rb
+++ b/lib/chef/resource/macos_userdefaults.rb
@@ -80,6 +80,7 @@ class Chef
property :host, [String, Symbol],
description: "Set either :current or a hostname to set the user default at the host level.",
+ default: :all_hosts, # TODO: check backward compatibility and defaults util convention
desired_state: false,
introduced: "16.3"
@@ -94,8 +95,9 @@ class Chef
equal_to: %w{bool string int float array dict},
desired_state: false
- property :user, [String, Symbol],
+ property :user, [String],
description: "The system user that the default will be applied to.",
+ default: 'current_user', # TODO: check backward compatibility and defaults util convention
desired_state: false
property :sudo, [TrueClass, FalseClass],
@@ -129,14 +131,6 @@ class Chef
end
action_class do
- CF_MAPPING = {
- current_user: CF::Preferences::CURRENT_USER,
- all_users: CF::Preferences::ALL_USERS,
- current_host: CF::Preferences::CURRENT_HOST,
- all_hosts: CF::Preferences::ALL_HOSTS,
- current: CF::Preferences::CURRENT_HOST # TODO: deprecation warning for this option
- }
-
def read_preferences(new_resource)
CF::Preferences.get(new_resource.key, new_resource.domain, mapped_user, mapped_host)
end
@@ -146,20 +140,34 @@ class Chef
end
def mapped_user
- CF_MAPPING[valid_user.to_sym] || valid_user.to_s
+ case valid_user.to_sym
+ when :current_user
+ CF::Preferences::CURRENT_USER
+ when :all_users
+ CF::Preferences::ALL_USERS
+ else
+ valid_user.to_s
+ end
end
def mapped_host
- CF_MAPPING[valid_host.to_sym] || valid_host.to_s
+ case valid_host.to_sym
+ when :current # TODO: deprecate this option??
+ CF::Preferences::CURRENT_HOST
+ when :current_host
+ CF::Preferences::CURRENT_HOST
+ when :all_hosts
+ CF::Preferences::ALL_HOSTS
+ else
+ valid_host.to_s
+ end
end
def valid_user
- # TODO: check backward compatibility and defaults util convention
new_resource.user || :current_user
end
def valid_host
- # TODO: check backward compatibility and defaults util convention
new_resource.host || :all_hosts
end
end
diff --git a/spec/unit/resource/macos_user_defaults_spec.rb b/spec/unit/resource/macos_user_defaults_spec.rb
index 883c9b6b85..54f1fb0044 100644
--- a/spec/unit/resource/macos_user_defaults_spec.rb
+++ b/spec/unit/resource/macos_user_defaults_spec.rb
@@ -35,8 +35,8 @@ describe Chef::Resource::MacosUserDefaults do
expect(resource.value).to eq({ "User" => "/Library/Managed Installs/way_fake.log" })
end
- it "the host property defaults to nil" do
- expect(resource.host).to be_nil
+ it "the host property defaults to be all_hosts" do
+ expect(resource.host).to eq :all_hosts
end
it "the sudo property defaults to false" do
@@ -73,7 +73,7 @@ describe Chef::Resource::MacosUserDefaults do
end
it "maps `all_users` to corresponding constant" do
- resource.user = :all_users
+ resource.user = 'all_users'
expect(provider.mapped_user).to eq CF::Preferences::ALL_USERS
end
end