diff options
author | Bryan McLellan <btm@opscode.com> | 2013-01-24 20:18:26 -0800 |
---|---|---|
committer | Bryan McLellan <btm@opscode.com> | 2013-06-18 13:46:04 -0700 |
commit | 4ee5dc9c95e75ec835c6e6d35298ef67c445b579 (patch) | |
tree | ff487eec66b259742ad8fd8d61fb83db7f6a85d5 /spec/unit/cookbook/synchronizer_spec.rb | |
parent | febf9c2be9a35ac5f756c207f4dad9853839951a (diff) | |
download | chef-4ee5dc9c95e75ec835c6e6d35298ef67c445b579.tar.gz |
CHEF-3045: Re-provide lost support for no_lazy_load
Originally added in 1938b77, but the move of the cookbook sync code
in f880869c93 got messed up in bad merge b36f636
Also, add something test-like.
Diffstat (limited to 'spec/unit/cookbook/synchronizer_spec.rb')
-rw-r--r-- | spec/unit/cookbook/synchronizer_spec.rb | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/spec/unit/cookbook/synchronizer_spec.rb b/spec/unit/cookbook/synchronizer_spec.rb index e84fd3cfc5..4c6aa0c0ed 100644 --- a/spec/unit/cookbook/synchronizer_spec.rb +++ b/spec/unit/cookbook/synchronizer_spec.rb @@ -63,6 +63,7 @@ describe Chef::CookbookSynchronizer do "checksum" => "abc456" } @cookbook_a_manifest["attributes"] = [ @cookbook_a_default_attrs ] @cookbook_a_manifest["templates"] = [{"path" => "templates/default/apache2.conf.erb", "url" => "http://chef.example.com/ffffff"}] + @cookbook_a_manifest["files"] = [{"path" => "files/default/megaman.conf", "url" => "http://chef.example.com/megaman.conf"}] @cookbook_a.manifest = @cookbook_a_manifest @cookbook_manifest["cookbook_a"] = @cookbook_a @@ -102,7 +103,7 @@ describe Chef::CookbookSynchronizer do before do # Would rather not stub out methods on the test subject, but setting up # the state is a PITA and tests for this behavior are above. - @synchronizer.should_receive(:clear_obsoleted_cookbooks) + @synchronizer.stub!(:clear_obsoleted_cookbooks) @server_api = mock("Chef::REST (mock)") @file_cache = mock("Chef::FileCache (mock)") @@ -162,6 +163,53 @@ describe Chef::CookbookSynchronizer do @synchronizer.sync_cookbooks end + context "Chef::Config[:no_lazy_load] is true" do + before do + Chef::Config[:no_lazy_load] = true + @synchronizer = Chef::CookbookSynchronizer.new(@cookbook_manifest, @events) + @synchronizer.stub!(:server_api).and_return(@server_api) + @synchronizer.stub!(:cache).and_return(@file_cache) + @synchronizer.stub!(:clear_obsoleted_cookbooks) + + @cookbook_a_file_default_tempfile = mock("Tempfile for cookbook_a megaman.conf file", + :path => "/tmp/cookbook_a_file_default_tempfile") + @cookbook_a_template_default_tempfile = mock("Tempfile for cookbook_a apache.conf.erb template", + :path => "/tmp/cookbook_a_template_default_tempfile") + end + + after do + Chef::Config[:no_lazy_load] = false + end + + it "fetches templates and cookbook files" do + @file_cache.should_receive(:has_key?). + with("cookbooks/cookbook_a/files/default/megaman.conf"). + and_return(false) + @file_cache.should_receive(:has_key?). + with("cookbooks/cookbook_a/templates/default/apache2.conf.erb"). + and_return(false) + + @server_api.should_receive(:get_rest). + with('http://chef.example.com/megaman.conf', true). + and_return(@cookbook_a_file_default_tempfile) + @file_cache.should_receive(:move_to). + with("/tmp/cookbook_a_file_default_tempfile", "cookbooks/cookbook_a/files/default/megaman.conf") + @file_cache.should_receive(:load). + with("cookbooks/cookbook_a/files/default/megaman.conf", false). + and_return("/file-cache/cookbooks/cookbook_a/default/megaman.conf") + + @server_api.should_receive(:get_rest). + with('http://chef.example.com/ffffff', true). + and_return(@cookbook_a_template_default_tempfile) + @file_cache.should_receive(:move_to). + with("/tmp/cookbook_a_template_default_tempfile", "cookbooks/cookbook_a/templates/default/apache2.conf.erb") + @file_cache.should_receive(:load). + with("cookbooks/cookbook_a/templates/default/apache2.conf.erb", false). + and_return("/file-cache/cookbooks/cookbook_a/templates/default/apache2.conf.erb") + + @synchronizer.sync_cookbooks + end + end end context "when the cache contains outdated files" do |