From f2409c1bf8fc3033ba225e03dd5c9b5979e83290 Mon Sep 17 00:00:00 2001 From: danielsdeleo Date: Thu, 18 Dec 2014 12:25:40 -0800 Subject: [PATCH] Allow relative paths for generator cookbook config Fixes an issue where Chef is unable to locate templates when the generator_cookbook is given via a relative path --- lib/chef-dk/chef_runner.rb | 4 ++-- spec/unit/chef_runner_spec.rb | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/lib/chef-dk/chef_runner.rb b/lib/chef-dk/chef_runner.rb index 7a5672042..dd4eacb75 100644 --- a/lib/chef-dk/chef_runner.rb +++ b/lib/chef-dk/chef_runner.rb @@ -26,7 +26,7 @@ class ChefRunner attr_reader :run_list def initialize(cookbook_path, run_list) - @cookbook_path = cookbook_path + @cookbook_path = File.expand_path(cookbook_path) @run_list = run_list @formatter = nil @ohai = nil @@ -39,7 +39,7 @@ def converge message = "Could not find cookbook(s) to satisfy run list #{run_list.inspect} in #{cookbook_path}" raise CookbookNotFound.new(message, e) rescue => e - raise ChefConvergeError("Chef failed to converge: #{e}", e) + raise ChefConvergeError.new("Chef failed to converge: #{e}", e) end def run_context diff --git a/spec/unit/chef_runner_spec.rb b/spec/unit/chef_runner_spec.rb index 3ed7ab950..99c57b2b7 100644 --- a/spec/unit/chef_runner_spec.rb +++ b/spec/unit/chef_runner_spec.rb @@ -72,6 +72,32 @@ expect(test_state[:loaded_recipes]).to eq([ "recipe_one", "recipe_two" ]) expect(test_state[:converged_recipes]).to eq([ "recipe_one", "recipe_two" ]) end + + context "when the embedded chef run fails" do + + let(:embedded_runner) { instance_double("Chef::Runner") } + + before do + allow(Chef::Runner).to receive(:new).and_return(embedded_runner) + allow(embedded_runner).to receive(:converge).and_raise("oops") + end + + it "wraps the exception in a ChefConvergeError" do + expect { chef_runner.converge }.to raise_error(ChefDK::ChefConvergeError) + end + + end + + context "when cookbook_path is relative" do + + let(:default_cookbook_path) { "~/heres_some_cookbooks" } + + it "expands the path" do + expect(chef_runner.cookbook_path).to eq(File.expand_path(default_cookbook_path)) + end + + end + end