diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2017-01-23 12:17:58 -0800 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2017-01-24 16:48:36 -0800 |
commit | 021e2596ecdde398da4e286ee0d4876522253eb3 (patch) | |
tree | 53c96a68ad2ac15db7aa180e3b2f62bceae778c3 /spec | |
parent | 6dbc75814a2ac434e60a46c848d223c04201be76 (diff) | |
download | chef-021e2596ecdde398da4e286ee0d4876522253eb3.tar.gz |
favor metadata.json over metadata.rb
make sure that if we have a metadata.rb that is not valid to read that
we never parse that and use compiled metadata.json instead.
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'spec')
-rw-r--r-- | spec/data/prefer_metadata_json/metadata.json | 51 | ||||
-rw-r--r-- | spec/data/prefer_metadata_json/metadata.rb | 6 | ||||
-rw-r--r-- | spec/data/prefer_metadata_json/recipes/default.rb | 0 | ||||
-rw-r--r-- | spec/integration/client/client_spec.rb | 33 | ||||
-rw-r--r-- | spec/unit/cookbook/cookbook_version_loader_spec.rb | 9 |
5 files changed, 99 insertions, 0 deletions
diff --git a/spec/data/prefer_metadata_json/metadata.json b/spec/data/prefer_metadata_json/metadata.json new file mode 100644 index 0000000000..eff8836a3b --- /dev/null +++ b/spec/data/prefer_metadata_json/metadata.json @@ -0,0 +1,51 @@ +{ + "name": "prefer_metadata_json", + "description": "", + "long_description": "", + "maintainer": null, + "maintainer_email": null, + "license": "All rights reserved", + "platforms": { + + }, + "dependencies": { + + }, + "recommendations": { + + }, + "suggestions": { + + }, + "conflicting": { + + }, + "providing": { + + }, + "replacing": { + + }, + "attributes": { + + }, + "groupings": { + + }, + "recipes": { + + }, + "version": "1.2.3", + "source_url": "", + "issues_url": "", + "privacy": false, + "chef_versions": [ + + ], + "ohai_versions": [ + + ], + "gems": [ + + ] +} diff --git a/spec/data/prefer_metadata_json/metadata.rb b/spec/data/prefer_metadata_json/metadata.rb new file mode 100644 index 0000000000..a46aa29a5c --- /dev/null +++ b/spec/data/prefer_metadata_json/metadata.rb @@ -0,0 +1,6 @@ +# these deliberately do not match metadata.json +name "test" +version "0.0.1" + +# this raises hard if anything even tries to parse it +raise "TEH SADNESS" diff --git a/spec/data/prefer_metadata_json/recipes/default.rb b/spec/data/prefer_metadata_json/recipes/default.rb new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/spec/data/prefer_metadata_json/recipes/default.rb diff --git a/spec/integration/client/client_spec.rb b/spec/integration/client/client_spec.rb index da3a2b98e4..7a8059066a 100644 --- a/spec/integration/client/client_spec.rb +++ b/spec/integration/client/client_spec.rb @@ -46,6 +46,7 @@ describe "chef-client" do # we're running `chef-client` from the source tree and not the external one. # cf. CHEF-4914 let(:chef_client) { "ruby '#{chef_dir}/chef-client' --minimal-ohai" } + let(:chef_solo) { "ruby '#{chef_dir}/chef-solo' --minimal-ohai" } let(:critical_env_vars) { %w{_ORIGINAL_GEM_PATH GEM_PATH GEM_HOME GEM_ROOT BUNDLE_BIN_PATH BUNDLE_GEMFILE RUBYLIB RUBYOPT RUBY_ENGINE RUBY_ROOT RUBY_VERSION PATH}.map { |o| "#{o}=#{ENV[o]}" } .join(" ") } @@ -499,4 +500,36 @@ EOM expect(result.exitstatus).not_to eq(0) end end + + when_the_repository "has a cookbook with broken metadata.rb, but has metadata.json" do + before do + file "cookbooks/x/recipes/default.rb", "" + file "cookbooks/x/metadata.rb", <<EOM +name 'x' +version '0.0.1' +raise "TEH SADNESS" +EOM + file "cookbooks/x/metadata.json", <<EOM +{ + "name": "x", + "version": "0.0.1" +} +EOM + + file "config/client.rb", <<EOM +local_mode true +cookbook_path "#{path_to('cookbooks')}" +EOM + end + + it "the chef client run should succeed" do + command = shell_out("#{chef_client} -c \"#{path_to('config/client.rb')}\" -o 'x::default' --no-fork", :cwd => chef_dir) + command.error! + end + + it "a chef-solo run should succeed" do + command = shell_out("#{chef_solo} -c \"#{path_to('config/client.rb')}\" -o 'x::default' --no-fork", :cwd => chef_dir) + command.error! + end + end end diff --git a/spec/unit/cookbook/cookbook_version_loader_spec.rb b/spec/unit/cookbook/cookbook_version_loader_spec.rb index 87d0f1e032..786e17f35b 100644 --- a/spec/unit/cookbook/cookbook_version_loader_spec.rb +++ b/spec/unit/cookbook/cookbook_version_loader_spec.rb @@ -104,6 +104,15 @@ describe Chef::Cookbook::CookbookVersionLoader do end + context "when a cookbook's metadata.rb does not parse but the compiled metadata.json is present" do + let(:cookbook_path) { File.join(CHEF_SPEC_DATA, "prefer_metadata_json") } + + it "reads the cookbook" do + expect(loaded_cookbook.metadata.name.to_s).to eq("prefer_metadata_json") + expect(loaded_cookbook.metadata.version.to_s).to eq("1.2.3") + end + end + context "when the given path is not actually a cookbook" do let(:cookbook_path) { File.join(CHEF_SPEC_DATA, "cookbooks/NOTHING_HERE_FOLKS") } |