summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThom May <thom@chef.io>2017-04-12 11:19:25 +0100
committerThom May <thom@chef.io>2017-04-25 10:17:54 +0100
commiteec35681949ef35d0f13f6f7425072327ddc4825 (patch)
tree1535451f99729090599e852c059eb4ec8a6ccf92
parent71863634ac50dbfb2601de536828b779517066ae (diff)
downloadchef-eec35681949ef35d0f13f6f7425072327ddc4825.tar.gz
add tests for CookbookManifest.each_file
Signed-off-by: Thom May <thom@may.lt>
-rw-r--r--spec/unit/cookbook_manifest_spec.rb19
1 files changed, 17 insertions, 2 deletions
diff --git a/spec/unit/cookbook_manifest_spec.rb b/spec/unit/cookbook_manifest_spec.rb
index d77c07e0f7..a28eaff3d3 100644
--- a/spec/unit/cookbook_manifest_spec.rb
+++ b/spec/unit/cookbook_manifest_spec.rb
@@ -114,7 +114,7 @@ describe Chef::CookbookManifest do
let(:match_md5) { /[0-9a-f]{32}/ }
- def map_to_file_specs(paths)
+ def map_to_file_specs(paths, full: false)
paths.map do |path|
relative_path = Pathname.new(path).relative_path_from(Pathname.new(cookbook_root)).to_s
@@ -131,7 +131,11 @@ describe Chef::CookbookManifest do
"path" => relative_path,
"checksum" => Chef::Digester.generate_md5_checksum_for_file(path),
"specificity" => "default",
- }
+ }.tap do |fp|
+ if full
+ fp["full_path"] = path
+ end
+ end
end
end
@@ -163,6 +167,17 @@ describe Chef::CookbookManifest do
end
end
+ context ".each_file" do
+ it "yields all the files" do
+ files = map_to_file_specs(all_files, full: true)
+ expect(cookbook_manifest.to_enum(:each_file)).to match_array(files)
+ end
+
+ it "excludes certain file parts" do
+ files = map_to_file_specs(all_files, full: true).reject { |f| seg = f["name"].split("/")[0]; %w{ files templates }.include?(seg) }
+ expect(cookbook_manifest.to_enum(:each_file, excluded_parts: %w{ files templates })).to match_array(files)
+ end
+ end
end
describe "providing upstream URLs for save" do