summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2019-08-23 15:01:12 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2019-08-26 14:09:12 -0700
commita8a6ea0734998c32e015259b385ee4fc3e9ccfa8 (patch)
treeb743de046fb7455920cd034df42c642e2ed857ab /spec
parentdd0009d7e77f192cadb1632f2159a6dbc880980f (diff)
downloadchef-a8a6ea0734998c32e015259b385ee4fc3e9ccfa8.tar.gz
Fix node[:cookbooks] attribute
closes #8817 Note that if any calling code winds up seeing this error message: ``` NoMethodError: undefined method `set_cookbook_attribute' for nil:NilClass ``` That means that the cookbook_collection was set before the node was set on the run_context. That wouldn't be a bug in core chef, that must be fixed in the caller to reverse the order of operations. Since I only made the positional arguments to the run_context constructor optional in Chef-15.0 though I don't expect this breaks any existing code written in the past month or two, but if anything crops up in the future, consider this a definitive statement that the caller must reverse the order of their operations and this error being thrown is a feature not a bug to be fixed. (The fact that we silently aborted rather than threw a NoMethodError on NilClass meant that we shipped this defect -- sometimes defensive programming can be overly defensive and swallow real errors). Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'spec')
-rw-r--r--spec/integration/client/client_spec.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/spec/integration/client/client_spec.rb b/spec/integration/client/client_spec.rb
index 68cfd015ab..7c0cbc6a63 100644
--- a/spec/integration/client/client_spec.rb
+++ b/spec/integration/client/client_spec.rb
@@ -369,6 +369,28 @@ describe "chef-client" do
end
end
+ when_the_repository "has a cookbook that outputs some node attributes" do
+ before do
+ file "cookbooks/x/recipes/default.rb", <<~'EOM'
+ puts "COOKBOOKS: #{node[:cookbooks]}"
+ EOM
+ file "cookbooks/x/metadata.rb", <<~EOM
+ name 'x'
+ version '0.0.1'
+ EOM
+ file "config/client.rb", <<~EOM
+ local_mode true
+ cookbook_path "#{path_to("cookbooks")}"
+ EOM
+ end
+
+ it "should fail the chef client run" do
+ result = shell_out("#{chef_client} -c \"#{path_to("config/client.rb")}\" -o 'x::default' --no-fork", cwd: chef_dir)
+ result.error!
+ expect(result.stdout).to include('COOKBOOKS: {"x"=>{"version"=>"0.0.1"}}')
+ end
+ end
+
when_the_repository "has a cookbook that should fail chef_version checks" do
before do
file "cookbooks/x/recipes/default.rb", ""