diff options
author | David Duponchel <dduponchel@mediarithmics.com> | 2016-03-04 15:48:46 +0100 |
---|---|---|
committer | David Duponchel <dduponchel@mediarithmics.com> | 2016-03-07 20:44:35 +0100 |
commit | 4bf4b62d6631abb6453f055eb034eaea69cbf5bc (patch) | |
tree | a049e652524cfa010f1e9ceaec6f8b392efbe594 /spec | |
parent | 60c8124366ab34b5992fc03c508b345218c90dfe (diff) | |
download | chef-4bf4b62d6631abb6453f055eb034eaea69cbf5bc.tar.gz |
preferred_manifest_record: fix pretty print.
The `preferred_manifest_record` function pretty prints the list of
existing files when the asked file can't be found. To do that, the root
path of the cookbook is removed from each existing file but the update
is done on the `existing_files` variable, not on a copy. When called
several times, this variable will eventually be equals to `[nil]`,
leading to a NoMethodError.
Without the fix, the new unit test fails with
> expected Chef::Exceptions::FileNotFound, got #<NoMethodError: undefined method `[]' for nil:NilClass> with backtrace:
> # ./lib/chef/cookbook_version.rb:321:in `block in preferred_manifest_record'
> # ./lib/chef/cookbook_version.rb:319:in `map!'
> # ./lib/chef/cookbook_version.rb:319:in `preferred_manifest_record'
> # ./spec/unit/cookbook_version_file_specificity_spec.rb:318:in `block (3 levels) in <top (required)>'
> # ./spec/unit/cookbook_version_file_specificity_spec.rb:317:in `block (2 levels) in <top (required)>'
Fixes #2561.
Diffstat (limited to 'spec')
-rw-r--r-- | spec/unit/cookbook_version_file_specificity_spec.rb | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/spec/unit/cookbook_version_file_specificity_spec.rb b/spec/unit/cookbook_version_file_specificity_spec.rb index 2bc20ac64e..df9e6571d8 100644 --- a/spec/unit/cookbook_version_file_specificity_spec.rb +++ b/spec/unit/cookbook_version_file_specificity_spec.rb @@ -21,7 +21,7 @@ require "spec_helper" describe Chef::CookbookVersion, "file specificity" do before(:each) do - @cookbook = Chef::CookbookVersion.new "test-cookbook" + @cookbook = Chef::CookbookVersion.new("test-cookbook", "/cookbook-folder") @cookbook.manifest = { "files" => [ @@ -301,6 +301,29 @@ describe Chef::CookbookVersion, "file specificity" do expect(manifest_record[:checksum]).to eq("csum4-platver-full") end + it "should raise a FileNotFound exception without match" do + node = Chef::Node.new + + expect { + @cookbook.preferred_manifest_record(node, :files, "doesn't_exist.rb") + }.to raise_error(Chef::Exceptions::FileNotFound) + end + it "should raise a FileNotFound exception consistently without match" do + node = Chef::Node.new + + expect { + @cookbook.preferred_manifest_record(node, :files, "doesn't_exist.rb") + }.to raise_error(Chef::Exceptions::FileNotFound) + + expect { + @cookbook.preferred_manifest_record(node, :files, "doesn't_exist.rb") + }.to raise_error(Chef::Exceptions::FileNotFound) + + expect { + @cookbook.preferred_manifest_record(node, :files, "doesn't_exist.rb") + }.to raise_error(Chef::Exceptions::FileNotFound) + end + describe "when fetching the contents of a directory by file specificity" do it "should return a directory of manifest records based on priority preference: host" do |