From 08d516d5bfe0336abf99e7606cf7b9a40418686c Mon Sep 17 00:00:00 2001 From: danielsdeleo Date: Tue, 13 Oct 2015 14:50:22 -0700 Subject: [PATCH 1/2] Require CookbookOmnifetch 0.2.2+, improves error messages See: https://github.com/chef/cookbook-omnifetch/pull/2 --- chef-dk.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chef-dk.gemspec b/chef-dk.gemspec index aa4d5adf4..77fa22f17 100644 --- a/chef-dk.gemspec +++ b/chef-dk.gemspec @@ -46,7 +46,7 @@ Gem::Specification.new do |gem| gem.add_dependency "solve", "~> 2.0", ">= 2.0.1" - gem.add_dependency "cookbook-omnifetch", "~> 0.2" + gem.add_dependency "cookbook-omnifetch", "~> 0.2", ">= 0.2.2" gem.add_dependency "diff-lcs", "~> 1.0" gem.add_dependency "paint", "~> 1.0" From 439d09a47f75bac0ed60a354d0d8d474c03af1c6 Mon Sep 17 00:00:00 2001 From: danielsdeleo Date: Tue, 13 Oct 2015 14:51:40 -0700 Subject: [PATCH 2/2] Give CookbookLocationSpecification a usable string representation These show up in some errors generated inside CookbookOmnifetch (in particular if you have code like `cookbook "foo", ">= 5.0", path: "foo"` in your Policyfile.rb, but the cookbook there doesn't satisfy the version constraint). --- lib/chef-dk/policyfile/cookbook_location_specification.rb | 8 ++++++++ .../policyfile/cookbook_location_specification_spec.rb | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/lib/chef-dk/policyfile/cookbook_location_specification.rb b/lib/chef-dk/policyfile/cookbook_location_specification.rb index 3faea5c6a..45ca47986 100644 --- a/lib/chef-dk/policyfile/cookbook_location_specification.rb +++ b/lib/chef-dk/policyfile/cookbook_location_specification.rb @@ -60,6 +60,14 @@ def ==(other) other.source_options == source_options end + def to_s + # Note, this may appear in exceptions + s = "Cookbook '#{name}'" + s << " #{version_constraint}" + s << " #{source_options}" unless source_options.empty? + s + end + def mirrors_canonical_upstream? [:git, :github, :artifactserver].include?(source_type) end diff --git a/spec/unit/policyfile/cookbook_location_specification_spec.rb b/spec/unit/policyfile/cookbook_location_specification_spec.rb index 34358fe4f..b60f4a719 100644 --- a/spec/unit/policyfile/cookbook_location_specification_spec.rb +++ b/spec/unit/policyfile/cookbook_location_specification_spec.rb @@ -77,6 +77,11 @@ expect(cookbook_location_spec.source_options_for_lock).to eq(lock_data) end + it "converts to a readable string with all relevant info" do + expected_s = "Cookbook 'my_cookbook' >= 0.0.0" + expect(cookbook_location_spec.to_s).to eq(expected_s) + end + describe "fetching and querying a cookbook" do before do