diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2016-07-01 13:09:29 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-01 13:09:29 -0700 |
commit | 5c15745b070a783e71a353954c7498bcd8232884 (patch) | |
tree | 04aa4e27a27b0f2c1e7738f5576cee6c792a559b | |
parent | 741ac9dde480a934f2f4fc98ada2ffa7ad4f71c0 (diff) | |
parent | 1ab6e838b7dafc06fd5ec8e1ff7add9a7be5e2cb (diff) | |
download | chef-5c15745b070a783e71a353954c7498bcd8232884.tar.gz |
Merge pull request #5075 from chef/lcg/3694-warnings
tweak 3694 warnings
-rw-r--r-- | lib/chef/property.rb | 8 | ||||
-rw-r--r-- | lib/chef/resource_builder.rb | 6 | ||||
-rw-r--r-- | spec/unit/recipe_spec.rb | 21 |
3 files changed, 32 insertions, 3 deletions
diff --git a/lib/chef/property.rb b/lib/chef/property.rb index 45ab4dd522..0589cb4c54 100644 --- a/lib/chef/property.rb +++ b/lib/chef/property.rb @@ -531,8 +531,6 @@ class Chef end end - protected - # # The options this Property will use for get/set behavior and validation. # @@ -583,6 +581,7 @@ class Chef (options.has_key?(:is) && resource.send(:_pv_is, { name => nil }, name, options[:is], raise_error: false)) end + # @api private def get_value(resource) if instance_variable_name resource.instance_variable_get(instance_variable_name) @@ -591,6 +590,7 @@ class Chef end end + # @api private def set_value(resource, value) if instance_variable_name resource.instance_variable_set(instance_variable_name, value) @@ -599,6 +599,7 @@ class Chef end end + # @api private def value_is_set?(resource) if instance_variable_name resource.instance_variable_defined?(instance_variable_name) @@ -607,6 +608,7 @@ class Chef end end + # @api private def reset_value(resource) if instance_variable_name if value_is_set?(resource) @@ -617,6 +619,8 @@ class Chef end end + private + def exec_in_resource(resource, proc, *args) if resource if proc.arity > args.size diff --git a/lib/chef/resource_builder.rb b/lib/chef/resource_builder.rb index d1f5c2e022..1641fe60f2 100644 --- a/lib/chef/resource_builder.rb +++ b/lib/chef/resource_builder.rb @@ -104,7 +104,11 @@ class Chef end def is_trivial_resource?(resource) - identicalish_resources?(resource_class.new(name, run_context), resource) + trivial_resource = resource_class.new(name, run_context) + # force un-lazy the name property on the created trivial resource + name_property = resource_class.properties.find { |sym, p| p.name_property? } + trivial_resource.send(name_property[0]) unless name_property.nil? + identicalish_resources?(trivial_resource, resource) end # this is an equality test specific to checking for 3694 cloning warnings diff --git a/spec/unit/recipe_spec.rb b/spec/unit/recipe_spec.rb index 70164f0a9b..3c30f96b20 100644 --- a/spec/unit/recipe_spec.rb +++ b/spec/unit/recipe_spec.rb @@ -266,6 +266,27 @@ describe Chef::Recipe do end end + class Coerced < Chef::Resource + resource_name :coerced + provides :coerced + default_action :whatever + property :package_name, [String, Array], coerce: proc { |x| [x].flatten }, name_property: true + def after_created + Array(action).each do |action| + run_action(action) + end + end + action :whatever do + package_name # unlazy the package_name + end + end + + it "does not emit 3694 when the name_property is unlazied by running it at compile_time" do + recipe.coerced "string" + expect(Chef).to_not receive(:log_deprecation) + recipe.coerced "string" + end + it "validating resources via build_resource" do expect {recipe.build_resource(:remote_file, "klopp") do source Chef::DelayedEvaluator.new { "http://chef.io" } |