summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan McLellan <btm@loftninjas.org>2014-07-09 17:45:41 -0400
committerBryan McLellan <btm@loftninjas.org>2014-08-29 08:01:47 -0400
commit5d023cb90fd04dca63465e2afa2886afd15a70f6 (patch)
treeaa701055461342d46f451773ddf013f35efe344f
parent0679cf742c50bc4381b98a9d1b6820c024e524da (diff)
downloadchef-5d023cb90fd04dca63465e2afa2886afd15a70f6.tar.gz
CHEF-5075: order matters for recipe_url
Add a test to ensure we maintain the order of fetching the tarball before loading JSON attributes from a file that may be in that recipe tarball Refactor slightly for the benefit of testing
-rw-r--r--lib/chef/application/solo.rb22
-rw-r--r--spec/unit/application/solo_spec.rb22
2 files changed, 33 insertions, 11 deletions
diff --git a/lib/chef/application/solo.rb b/lib/chef/application/solo.rb
index a55882bef1..f0e578d5ef 100644
--- a/lib/chef/application/solo.rb
+++ b/lib/chef/application/solo.rb
@@ -190,14 +190,10 @@ class Chef::Application::Solo < Chef::Application
recipes_path = File.expand_path(File.join(cookbooks_path, '..'))
Chef::Log.debug "Creating path #{recipes_path} to extract recipes into"
- FileUtils.mkdir_p recipes_path
- path = File.join(recipes_path, 'recipes.tgz')
- File.open(path, 'wb') do |f|
- open(Chef::Config[:recipe_url]) do |r|
- f.write(r.read)
- end
- end
- Chef::Mixin::Command.run_command(:command => "tar zxvf #{path} -C #{recipes_path}")
+ FileUtils.mkdir_p(recipes_path)
+ tarball_path = File.join(recipes_path, 'recipes.tgz')
+ fetch_recipe_tarball(Chef::Config[:recipe_url], tarball_path)
+ Chef::Mixin::Command.run_command(:command => "tar zxvf #{tarball_path} -C #{recipes_path}")
end
# json_attribs shuld be fetched after recipe_url tarball is unpacked.
@@ -248,4 +244,14 @@ class Chef::Application::Solo < Chef::Application
end
end
+ private
+
+ def fetch_recipe_tarball(url, path)
+ Chef::Log.debug("Download recipes tarball from #{url} to #{path}")
+ File.open(path, 'wb') do |f|
+ open(url) do |r|
+ f.write(r.read)
+ end
+ end
+ end
end
diff --git a/spec/unit/application/solo_spec.rb b/spec/unit/application/solo_spec.rb
index dfc54db4b0..787f9ff43c 100644
--- a/spec/unit/application/solo_spec.rb
+++ b/spec/unit/application/solo_spec.rb
@@ -49,7 +49,6 @@ describe Chef::Application::Solo do
end
describe "when the json_attribs configuration option is specified" do
-
let(:json_attribs) { {"a" => "b"} }
let(:config_fetcher) { double(Chef::ConfigFetcher, :fetch_json => json_attribs) }
let(:json_source) { "https://foo.com/foo.json" }
@@ -66,8 +65,6 @@ describe Chef::Application::Solo do
end
end
-
-
describe "when the recipe_url configuration option is specified" do
before do
Chef::Config[:cookbook_path] = "#{Dir.tmpdir}/chef-solo/cookbooks"
@@ -104,6 +101,25 @@ describe Chef::Application::Solo do
end
end
+ describe "when the json_attribs and recipe_url configuration options are both specified" do
+ let(:json_attribs) { {"a" => "b"} }
+ let(:config_fetcher) { double(Chef::ConfigFetcher, :fetch_json => json_attribs) }
+ let(:json_source) { "https://foo.com/foo.json" }
+
+ before do
+ Chef::Config[:json_attribs] = json_source
+ Chef::Config[:recipe_url] = "http://icanhas.cheezburger.com/lolcats"
+ Chef::Config[:cookbook_path] = "#{Dir.tmpdir}/chef-solo/cookbooks"
+ FileUtils.stub(:mkdir_p).and_return(true)
+ Chef::Mixin::Command.stub(:run_command).and_return(true)
+ end
+
+ it "should fetch the recipe_url first" do
+ @app.should_receive(:fetch_recipe_tarball).ordered
+ Chef::ConfigFetcher.should_receive(:new).ordered.and_return(config_fetcher)
+ @app.reconfigure
+ end
+ end
describe "after the application has been configured" do
before do