diff options
author | John Keiser <john@johnkeiser.com> | 2016-01-15 10:14:35 -0800 |
---|---|---|
committer | John Keiser <john@johnkeiser.com> | 2016-01-15 15:08:54 -0800 |
commit | 8fee68afb13b8ed00d57bf8cd9da84c333fd15a4 (patch) | |
tree | 3b6bc36ecc2b811a66ade9f3ac5bb4a2bef2c21d | |
parent | 4053ab0c436c97e7c3399404a959e222d7a1df13 (diff) | |
download | chef-8fee68afb13b8ed00d57bf8cd9da84c333fd15a4.tar.gz |
Create a default cookbook artifact that looks like what the pedant tests expect
-rw-r--r-- | lib/chef/chef_fs/chef_fs_data_store.rb | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/lib/chef/chef_fs/chef_fs_data_store.rb b/lib/chef/chef_fs/chef_fs_data_store.rb index a4485aa137..796c41ea92 100644 --- a/lib/chef/chef_fs/chef_fs_data_store.rb +++ b/lib/chef/chef_fs/chef_fs_data_store.rb @@ -293,7 +293,7 @@ class Chef cookbook_type = path[0] result = nil begin - result = Chef::CookbookManifest.new(entry.chef_object).to_hash + result = Chef::CookbookManifest.new(entry.chef_object, policy_mode: cookbook_type == "cookbook_artifacts").to_hash rescue Chef::ChefFS::FileSystem::NotFoundError => e raise ChefZero::DataStore::DataNotFoundError.new(to_zero_path(e.entry), e) end @@ -314,6 +314,23 @@ class Chef end end end + + # Cookbook artifacts act as if certain things aren't set if they are empty + # (e.g. "definitions" and "libraries" are not set if they are empty, but + # "recipes" is) + if cookbook_type == "cookbook_artifacts" + result.delete_if do |key,value| + (value == [] && key != "recipes") + end + result['metadata'] = result['metadata'].to_hash + result['metadata'].delete_if do |key,value| + value == [] || + (value == {} && !%w(dependencies attributes recipes).include?(key)) || + (value == "" && %w(source_url issues_url).include?(key)) || + (value == false && key == "privacy") + end + end + Chef::JSONCompat.to_json_pretty(result) end |