summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/unit/cookbook/synchronizer_spec.rb590
1 files changed, 372 insertions, 218 deletions
diff --git a/spec/unit/cookbook/synchronizer_spec.rb b/spec/unit/cookbook/synchronizer_spec.rb
index c52593287a..9b028064d5 100644
--- a/spec/unit/cookbook/synchronizer_spec.rb
+++ b/spec/unit/cookbook/synchronizer_spec.rb
@@ -5,26 +5,28 @@ require 'chef/cookbook_version'
describe Chef::CookbookCacheCleaner do
describe "when cleaning up unused cookbook components" do
- before do
- @cleaner = Chef::CookbookCacheCleaner.instance
- @cleaner.reset!
+ let(:cleaner) do
+ cleaner = Chef::CookbookCacheCleaner.instance
+ cleaner.reset!
+ cleaner
end
it "removes all files that belong to unused cookbooks" do
+ # lolwut?
end
it "removes all files not validated during the chef run" do
file_cache = double("Chef::FileCache with files from unused cookbooks")
unused_template_files = %w{cookbooks/unused/templates/default/foo.conf.erb cookbooks/unused/tempaltes/default/bar.conf.erb}
valid_cached_cb_files = %w{cookbooks/valid1/recipes/default.rb cookbooks/valid2/recipes/default.rb}
- @cleaner.mark_file_as_valid('cookbooks/valid1/recipes/default.rb')
- @cleaner.mark_file_as_valid('cookbooks/valid2/recipes/default.rb')
- file_cache.should_receive(:find).with(File.join(%w{cookbooks ** *})).and_return(valid_cached_cb_files + unused_template_files)
- file_cache.should_receive(:delete).with('cookbooks/unused/templates/default/foo.conf.erb')
- file_cache.should_receive(:delete).with('cookbooks/unused/tempaltes/default/bar.conf.erb')
+ cleaner.mark_file_as_valid('cookbooks/valid1/recipes/default.rb')
+ cleaner.mark_file_as_valid('cookbooks/valid2/recipes/default.rb')
+ expect(file_cache).to receive(:find).with(File.join(%w{cookbooks ** *})).and_return(valid_cached_cb_files + unused_template_files)
+ expect(file_cache).to receive(:delete).with('cookbooks/unused/templates/default/foo.conf.erb')
+ expect(file_cache).to receive(:delete).with('cookbooks/unused/tempaltes/default/bar.conf.erb')
cookbook_hash = {"valid1"=> {}, "valid2" => {}}
- @cleaner.stub(:cache).and_return(file_cache)
- @cleaner.cleanup_file_cache
+ allow(cleaner).to receive(:cache).and_return(file_cache)
+ cleaner.cleanup_file_cache
end
describe "on chef-solo" do
@@ -32,275 +34,427 @@ describe Chef::CookbookCacheCleaner do
Chef::Config[:solo] = true
end
- after do
- Chef::Config[:solo] = false
- end
-
it "does not remove anything" do
- @cleaner.cache.stub(:find).and_return(%w{cookbooks/valid1/recipes/default.rb cookbooks/valid2/recipes/default.rb})
- @cleaner.cache.should_not_receive(:delete)
- @cleaner.cleanup_file_cache
+ allow(cleaner.cache).to receive(:find).and_return(%w{cookbooks/valid1/recipes/default.rb cookbooks/valid2/recipes/default.rb})
+ expect(cleaner.cache).not_to receive(:delete)
+ cleaner.cleanup_file_cache
end
-
end
-
end
end
describe Chef::CookbookSynchronizer do
- before do
+ let(:cookbook_a_default_recipe) do
+ {
+ "path" => "recipes/default.rb",
+ "url" => "http://chef.example.com/abc123",
+ "checksum" => "abc123",
+ }
+ end
+
+ let(:cookbook_a_default_attrs) do
+ {
+ "path" => "attributes/default.rb",
+ "url" => "http://chef.example.com/abc456",
+ "checksum" => "abc456",
+ }
+ end
+
+ let(:cookbook_a_template) do
+ {
+ "path" => "templates/default/apache2.conf.erb",
+ "url" => "http://chef.example.com/ffffff",
+ "checksum" => "abc125",
+ }
+ end
+
+ let(:cookbook_a_file) do
+ {
+ "path" => "files/default/megaman.conf",
+ "url" => "http://chef.example.com/megaman.conf",
+ "checksum" => "abc124",
+ }
+ end
+
+ let(:cookbook_a_manifest) do
segments = [ :resources, :providers, :recipes, :definitions, :libraries, :attributes, :files, :templates, :root_files ]
- @cookbook_manifest = {}
- @cookbook_a = Chef::CookbookVersion.new("cookbook_a")
- @cookbook_a_manifest = segments.inject({}) {|h, segment| h[segment.to_s] = []; h}
- @cookbook_a_default_recipe = { "path" => "recipes/default.rb",
- "url" => "http://chef.example.com/abc123",
- "checksum" => "abc123" }
- @cookbook_a_manifest["recipes"] = [ @cookbook_a_default_recipe ]
-
- @cookbook_a_default_attrs = { "path" => "attributes/default.rb",
- "url" => "http://chef.example.com/abc456",
- "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
-
- @events = Chef::EventDispatch::Dispatcher.new
- @synchronizer = Chef::CookbookSynchronizer.new(@cookbook_manifest, @events)
+ cookbook_a_manifest = segments.inject({}) {|h, segment| h[segment.to_s] = []; h}
+ cookbook_a_manifest["recipes"] = [ cookbook_a_default_recipe ]
+ cookbook_a_manifest["attributes"] = [ cookbook_a_default_attrs ]
+ cookbook_a_manifest["templates"] = [ cookbook_a_template ]
+ cookbook_a_manifest["files"] = [ cookbook_a_file ]
+ cookbook_a_manifest
+ end
+
+ let(:cookbook_a) do
+ cookbook_a = Chef::CookbookVersion.new("cookbook_a")
+ cookbook_a.manifest = cookbook_a_manifest
+ cookbook_a
+ end
+
+ let(:cookbook_manifest) do
+ {
+ "cookbook_a" => cookbook_a
+ }
+ end
+
+ let(:events) { Chef::EventDispatch::Dispatcher.new }
+
+ let(:no_lazy_load) { true }
+
+ let(:synchronizer) do
+ Chef::Config[:no_lazy_load] = no_lazy_load
+ Chef::CookbookSynchronizer.new(cookbook_manifest, events)
end
it "lists the cookbook names" do
- @synchronizer.cookbook_names.should == %w[cookbook_a]
+ expect(synchronizer.cookbook_names).to eq(%w[cookbook_a])
end
it "lists the cookbook manifests" do
- @synchronizer.cookbooks.should == [@cookbook_a]
+ expect(synchronizer.cookbooks).to eq([cookbook_a])
end
context "when the cache contains unneeded cookbooks" do
- before do
- @file_cache = double("Chef::FileCache with files from unused cookbooks")
- @valid_cached_cb_files = %w{cookbooks/valid1/recipes/default.rb cookbooks/valid2/recipes/default.rb}
- @obsolete_cb_files = %w{cookbooks/old1/recipes/default.rb cookbooks/old2/recipes/default.rb}
-
- @cookbook_hash = {"valid1"=> {}, "valid2" => {}}
+ let(:file_cache) { double("Chef::FileCache with files from unused cookbooks") }
- @synchronizer = Chef::CookbookSynchronizer.new(@cookbook_hash, @events)
+ let(:cookbook_manifest) do
+ {"valid1"=> {}, "valid2" => {}}
end
it "removes unneeded cookbooks" do
- @file_cache.should_receive(:find).with(File.join(%w{cookbooks ** *})).and_return(@valid_cached_cb_files + @obsolete_cb_files)
- @file_cache.should_receive(:delete).with('cookbooks/old1/recipes/default.rb')
- @file_cache.should_receive(:delete).with('cookbooks/old2/recipes/default.rb')
- @synchronizer.stub(:cache).and_return(@file_cache)
- @synchronizer.clear_obsoleted_cookbooks
+ valid_cached_cb_files = %w{cookbooks/valid1/recipes/default.rb cookbooks/valid2/recipes/default.rb}
+ obsolete_cb_files = %w{cookbooks/old1/recipes/default.rb cookbooks/old2/recipes/default.rb}
+ expect(file_cache).to receive(:find).with(File.join(%w{cookbooks ** *})).and_return(valid_cached_cb_files + obsolete_cb_files)
+ expect(file_cache).to receive(:delete).with('cookbooks/old1/recipes/default.rb')
+ expect(file_cache).to receive(:delete).with('cookbooks/old2/recipes/default.rb')
+ allow(synchronizer).to receive(:cache).and_return(file_cache)
+ synchronizer.clear_obsoleted_cookbooks
end
end
- describe "when syncing cookbooks with the server" 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.stub(:clear_obsoleted_cookbooks)
+ let(:cookbook_a_default_recipe_tempfile) do
+ double("Tempfile for cookbook_a default.rb recipe",
+ :path => "/tmp/cookbook_a_recipes_default_rb")
+ end
+
+ let(:cookbook_a_default_attribute_tempfile) do
+ double("Tempfile for cookbook_a default.rb attr file",
+ :path => "/tmp/cookbook_a_attributes_default_rb")
+ end
+
+ let(:cookbook_a_file_default_tempfile) do
+ double("Tempfile for cookbook_a megaman.conf file",
+ :path => "/tmp/cookbook_a_file_default_tempfile")
+ end
+
+ let(:cookbook_a_template_default_tempfile) do
+ double("Tempfile for cookbook_a apache.conf.erb template",
+ :path => "/tmp/cookbook_a_template_default_tempfile")
+ end
- @server_api = double("Chef::REST (mock)")
- @file_cache = double("Chef::FileCache (mock)")
- @synchronizer.stub(:server_api).and_return(@server_api)
- @synchronizer.stub(:cache).and_return(@file_cache)
+ def setup_common_files_missing_expectations
+ # Files are not in the cache:
+ expect(file_cache).to receive(:has_key?).
+ with("cookbooks/cookbook_a/recipes/default.rb").
+ and_return(false)
+ expect(file_cache).to receive(:has_key?).
+ with("cookbooks/cookbook_a/attributes/default.rb").
+ and_return(false)
+
+ # Fetch and copy default.rb recipe
+ expect(server_api).to receive(:get_rest).
+ with('http://chef.example.com/abc123', true).
+ and_return(cookbook_a_default_recipe_tempfile)
+ expect(file_cache).to receive(:move_to).
+ with("/tmp/cookbook_a_recipes_default_rb", "cookbooks/cookbook_a/recipes/default.rb")
+ expect(file_cache).to receive(:load).
+ with("cookbooks/cookbook_a/recipes/default.rb", false).
+ and_return("/file-cache/cookbooks/cookbook_a/recipes/default.rb")
+
+ # Fetch and copy default.rb attribute file
+ expect(server_api).to receive(:get_rest).
+ with('http://chef.example.com/abc456', true).
+ and_return(cookbook_a_default_attribute_tempfile)
+ expect(file_cache).to receive(:move_to).
+ with("/tmp/cookbook_a_attributes_default_rb", "cookbooks/cookbook_a/attributes/default.rb")
+ expect(file_cache).to receive(:load).
+ with("cookbooks/cookbook_a/attributes/default.rb", false).
+ and_return("/file-cache/cookbooks/cookbook_a/attributes/default.rb")
+ end
+ def setup_no_lazy_files_and_templates_missing_expectations
+ expect(file_cache).to receive(:has_key?).
+ with("cookbooks/cookbook_a/files/default/megaman.conf").
+ and_return(false)
+ expect(file_cache).to receive(:has_key?).
+ with("cookbooks/cookbook_a/templates/default/apache2.conf.erb").
+ and_return(false)
+
+ expect(server_api).to receive(:get_rest).
+ with('http://chef.example.com/megaman.conf', true).
+ and_return(cookbook_a_file_default_tempfile)
+ expect(file_cache).to receive(:move_to).
+ with("/tmp/cookbook_a_file_default_tempfile", "cookbooks/cookbook_a/files/default/megaman.conf")
+ expect(file_cache).to receive(:load).
+ with("cookbooks/cookbook_a/files/default/megaman.conf", false).
+ and_return("/file-cache/cookbooks/cookbook_a/default/megaman.conf")
+
+ expect(server_api).to receive(:get_rest).
+ with('http://chef.example.com/ffffff', true).
+ and_return(cookbook_a_template_default_tempfile)
+ expect(file_cache).to receive(:move_to).
+ with("/tmp/cookbook_a_template_default_tempfile", "cookbooks/cookbook_a/templates/default/apache2.conf.erb")
+ expect(file_cache).to receive(:load).
+ with("cookbooks/cookbook_a/templates/default/apache2.conf.erb", false).
+ and_return("/file-cache/cookbooks/cookbook_a/templates/default/apache2.conf.erb")
+ end
- @cookbook_a_default_recipe_tempfile = double("Tempfile for cookbook_a default.rb recipe",
- :path => "/tmp/cookbook_a_recipes_default_rb")
+ def setup_common_files_chksum_mismatch_expectations
+ # Files are in the cache:
+ expect(file_cache).to receive(:has_key?).
+ with("cookbooks/cookbook_a/recipes/default.rb").
+ and_return(true)
+ expect(file_cache).to receive(:has_key?).
+ with("cookbooks/cookbook_a/attributes/default.rb").
+ and_return(true)
+
+ # Fetch and copy default.rb recipe
+ expect(server_api).to receive(:get_rest).
+ with('http://chef.example.com/abc123', true).
+ and_return(cookbook_a_default_recipe_tempfile)
+ expect(file_cache).to receive(:move_to).
+ with("/tmp/cookbook_a_recipes_default_rb", "cookbooks/cookbook_a/recipes/default.rb")
+ expect(file_cache).to receive(:load).
+ with("cookbooks/cookbook_a/recipes/default.rb", false).
+ twice.
+ and_return("/file-cache/cookbooks/cookbook_a/recipes/default.rb")
+
+ # Current file has fff000, want abc123
+ expect(Chef::CookbookVersion).to receive(:checksum_cookbook_file).
+ with("/file-cache/cookbooks/cookbook_a/recipes/default.rb").
+ and_return("fff000")
+
+ # Fetch and copy default.rb attribute file
+ expect(server_api).to receive(:get_rest).
+ with('http://chef.example.com/abc456', true).
+ and_return(cookbook_a_default_attribute_tempfile)
+ expect(file_cache).to receive(:move_to).
+ with("/tmp/cookbook_a_attributes_default_rb", "cookbooks/cookbook_a/attributes/default.rb")
+ expect(file_cache).to receive(:load).
+ with("cookbooks/cookbook_a/attributes/default.rb", false).
+ twice.
+ and_return("/file-cache/cookbooks/cookbook_a/attributes/default.rb")
+
+ # Current file has fff000, want abc456
+ expect(Chef::CookbookVersion).to receive(:checksum_cookbook_file).
+ with("/file-cache/cookbooks/cookbook_a/attributes/default.rb").
+ and_return("fff000")
+ end
- @cookbook_a_default_attribute_tempfile = double("Tempfile for cookbook_a default.rb attr file",
- :path => "/tmp/cookbook_a_attributes_default_rb")
+ def setup_no_lazy_files_and_templates_chksum_mismatch_expectations
+ # Files are in the cache:
+ expect(file_cache).to receive(:has_key?).
+ with("cookbooks/cookbook_a/files/default/megaman.conf").
+ and_return(true)
+ expect(file_cache).to receive(:has_key?).
+ with("cookbooks/cookbook_a/templates/default/apache2.conf.erb").
+ and_return(true)
+
+ # Fetch and copy megaman.conf
+ expect(server_api).to receive(:get_rest).
+ with('http://chef.example.com/megaman.conf', true).
+ and_return(cookbook_a_file_default_tempfile)
+ expect(file_cache).to receive(:move_to).
+ with("/tmp/cookbook_a_file_default_tempfile", "cookbooks/cookbook_a/files/default/megaman.conf")
+ expect(file_cache).to receive(:load).
+ with("cookbooks/cookbook_a/files/default/megaman.conf", false).
+ twice.
+ and_return("/file-cache/cookbooks/cookbook_a/default/megaman.conf")
+
+ # Fetch and copy apache2.conf template
+ expect(server_api).to receive(:get_rest).
+ with('http://chef.example.com/ffffff', true).
+ and_return(cookbook_a_template_default_tempfile)
+ expect(file_cache).to receive(:move_to).
+ with("/tmp/cookbook_a_template_default_tempfile", "cookbooks/cookbook_a/templates/default/apache2.conf.erb")
+ expect(file_cache).to receive(:load).
+ with("cookbooks/cookbook_a/templates/default/apache2.conf.erb", false).
+ twice.
+ and_return("/file-cache/cookbooks/cookbook_a/templates/default/apache2.conf.erb")
+
+ # Current file has fff000
+ expect(Chef::CookbookVersion).to receive(:checksum_cookbook_file).
+ with("/file-cache/cookbooks/cookbook_a/default/megaman.conf").
+ and_return("fff000")
+
+ # Current file has fff000
+ expect(Chef::CookbookVersion).to receive(:checksum_cookbook_file).
+ with("/file-cache/cookbooks/cookbook_a/templates/default/apache2.conf.erb").
+ and_return("fff000")
+ end
+ def setup_common_files_present_expectations
+ # Files are in the cache:
+ expect(file_cache).to receive(:has_key?).
+ with("cookbooks/cookbook_a/recipes/default.rb").
+ and_return(true)
+ expect(file_cache).to receive(:has_key?).
+ with("cookbooks/cookbook_a/attributes/default.rb").
+ and_return(true)
+
+ # Current file has abc123, want abc123
+ expect(Chef::CookbookVersion).to receive(:checksum_cookbook_file).
+ with("/file-cache/cookbooks/cookbook_a/recipes/default.rb").
+ and_return("abc123")
+
+ # Current file has abc456, want abc456
+ expect(Chef::CookbookVersion).to receive(:checksum_cookbook_file).
+ with("/file-cache/cookbooks/cookbook_a/attributes/default.rb").
+ and_return("abc456")
+
+ # :load called twice
+ expect(file_cache).to receive(:load).
+ with("cookbooks/cookbook_a/recipes/default.rb", false).
+ twice.
+ and_return("/file-cache/cookbooks/cookbook_a/recipes/default.rb")
+ expect(file_cache).to receive(:load).
+ with("cookbooks/cookbook_a/attributes/default.rb", false).
+ twice.
+ and_return("/file-cache/cookbooks/cookbook_a/attributes/default.rb")
+ end
+
+ def setup_no_lazy_files_and_templates_present_expectations
+ # Files are in the cache:
+ expect(file_cache).to receive(:has_key?).
+ with("cookbooks/cookbook_a/files/default/megaman.conf").
+ and_return(true)
+ expect(file_cache).to receive(:has_key?).
+ with("cookbooks/cookbook_a/templates/default/apache2.conf.erb").
+ and_return(true)
+
+ # Current file has abc124, want abc124
+ expect(Chef::CookbookVersion).to receive(:checksum_cookbook_file).
+ with("/file-cache/cookbooks/cookbook_a/default/megaman.conf").
+ and_return("abc124")
+
+ # Current file has abc125, want abc125
+ expect(Chef::CookbookVersion).to receive(:checksum_cookbook_file).
+ with("/file-cache/cookbooks/cookbook_a/templates/default/apache2.conf.erb").
+ and_return("abc125")
+
+ # :load called twice
+ expect(file_cache).to receive(:load).
+ with("cookbooks/cookbook_a/files/default/megaman.conf", false).
+ twice.
+ and_return("/file-cache/cookbooks/cookbook_a/default/megaman.conf")
+ expect(file_cache).to receive(:load).
+ with("cookbooks/cookbook_a/templates/default/apache2.conf.erb", false).
+ twice.
+ and_return("/file-cache/cookbooks/cookbook_a/templates/default/apache2.conf.erb")
+ end
+
+ describe "when syncing cookbooks with the server" do
+ let(:server_api) { double("Chef::REST (mock)") }
+
+ let(:file_cache) { double("Chef::FileCache (mock)") }
+
+ 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.
+ allow(synchronizer).to receive(:clear_obsoleted_cookbooks)
+ allow(synchronizer).to receive(:server_api).and_return(server_api)
+ allow(synchronizer).to receive(:cache).and_return(file_cache)
end
context "when the cache does not contain the desired files" do
before do
-
- # Files are not in the cache:
- @file_cache.should_receive(:has_key?).
- with("cookbooks/cookbook_a/recipes/default.rb").
- and_return(false)
- @file_cache.should_receive(:has_key?).
- with("cookbooks/cookbook_a/attributes/default.rb").
- and_return(false)
-
- # Fetch and copy default.rb recipe
- @server_api.should_receive(:get_rest).
- with('http://chef.example.com/abc123', true).
- and_return(@cookbook_a_default_recipe_tempfile)
- @file_cache.should_receive(:move_to).
- with("/tmp/cookbook_a_recipes_default_rb", "cookbooks/cookbook_a/recipes/default.rb")
- @file_cache.should_receive(:load).
- with("cookbooks/cookbook_a/recipes/default.rb", false).
- and_return("/file-cache/cookbooks/cookbook_a/recipes/default.rb")
-
- # Fetch and copy default.rb attribute file
- @server_api.should_receive(:get_rest).
- with('http://chef.example.com/abc456', true).
- and_return(@cookbook_a_default_attribute_tempfile)
- @file_cache.should_receive(:move_to).
- with("/tmp/cookbook_a_attributes_default_rb", "cookbooks/cookbook_a/attributes/default.rb")
- @file_cache.should_receive(:load).
- with("cookbooks/cookbook_a/attributes/default.rb", false).
- and_return("/file-cache/cookbooks/cookbook_a/attributes/default.rb")
+ setup_common_files_missing_expectations
end
- it "fetches eagerly loaded files" do
- @synchronizer.sync_cookbooks
- end
+ context "Chef::Config[:no_lazy_load] is false" do
+ let(:no_lazy_load) { false }
+
+ it "fetches eagerly loaded files" do
+ synchronizer.sync_cookbooks
+ end
- it "does not fetch templates or cookbook files" do
- # Implicitly tested in previous test; this test is just for behavior specification.
- @server_api.should_not_receive(:get_rest).
- with('http://chef.example.com/ffffff', true)
+ it "does not fetch templates or cookbook files" do
+ # Implicitly tested in previous test; this test is just for behavior specification.
+ expect(server_api).not_to receive(:get_rest).
+ with('http://chef.example.com/ffffff', true)
- @synchronizer.sync_cookbooks
+ synchronizer.sync_cookbooks
+ end
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 = double("Tempfile for cookbook_a megaman.conf file",
- :path => "/tmp/cookbook_a_file_default_tempfile")
- @cookbook_a_template_default_tempfile = double("Tempfile for cookbook_a apache.conf.erb template",
- :path => "/tmp/cookbook_a_template_default_tempfile")
- end
+ let(:no_lazy_load) { true }
- after do
- Chef::Config[:no_lazy_load] = false
+ before do
+ setup_no_lazy_files_and_templates_missing_expectations
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
+ synchronizer.sync_cookbooks
end
end
end
context "when the cache contains outdated files" do
before do
- # Files are in the cache:
- @file_cache.should_receive(:has_key?).
- with("cookbooks/cookbook_a/recipes/default.rb").
- and_return(true)
- @file_cache.should_receive(:has_key?).
- with("cookbooks/cookbook_a/attributes/default.rb").
- and_return(true)
-
-
- # Fetch and copy default.rb recipe
- @server_api.should_receive(:get_rest).
- with('http://chef.example.com/abc123', true).
- and_return(@cookbook_a_default_recipe_tempfile)
- @file_cache.should_receive(:move_to).
- with("/tmp/cookbook_a_recipes_default_rb", "cookbooks/cookbook_a/recipes/default.rb")
- @file_cache.should_receive(:load).
- with("cookbooks/cookbook_a/recipes/default.rb", false).
- twice.
- and_return("/file-cache/cookbooks/cookbook_a/recipes/default.rb")
-
- # Current file has fff000, want abc123
- Chef::CookbookVersion.should_receive(:checksum_cookbook_file).
- with("/file-cache/cookbooks/cookbook_a/recipes/default.rb").
- and_return("fff000")
-
- # Fetch and copy default.rb attribute file
- @server_api.should_receive(:get_rest).
- with('http://chef.example.com/abc456', true).
- and_return(@cookbook_a_default_attribute_tempfile)
- @file_cache.should_receive(:move_to).
- with("/tmp/cookbook_a_attributes_default_rb", "cookbooks/cookbook_a/attributes/default.rb")
- @file_cache.should_receive(:load).
- with("cookbooks/cookbook_a/attributes/default.rb", false).
- twice.
- and_return("/file-cache/cookbooks/cookbook_a/attributes/default.rb")
-
- # Current file has fff000, want abc456
- Chef::CookbookVersion.should_receive(:checksum_cookbook_file).
- with("/file-cache/cookbooks/cookbook_a/attributes/default.rb").
- and_return("fff000")
+ setup_common_files_chksum_mismatch_expectations
end
- it "updates the outdated files" do
- @synchronizer.sync_cookbooks
+ context "Chef::Config[:no_lazy_load] is true" do
+ let(:no_lazy_load) { true }
+
+ before do
+ setup_no_lazy_files_and_templates_chksum_mismatch_expectations
+ end
+
+ it "updates the outdated files" do
+ synchronizer.sync_cookbooks
+ end
+ end
+
+ context "Chef::Config[:no_lazy_load] is false" do
+ let(:no_lazy_load) { false }
+
+ it "updates the outdated files" do
+ synchronizer.sync_cookbooks
+ end
end
end
context "when the cache is up to date" do
before do
- # Files are in the cache:
- @file_cache.should_receive(:has_key?).
- with("cookbooks/cookbook_a/recipes/default.rb").
- and_return(true)
- @file_cache.should_receive(:has_key?).
- with("cookbooks/cookbook_a/attributes/default.rb").
- and_return(true)
-
- # Current file has abc123, want abc123
- Chef::CookbookVersion.should_receive(:checksum_cookbook_file).
- with("/file-cache/cookbooks/cookbook_a/recipes/default.rb").
- and_return("abc123")
-
- # Current file has abc456, want abc456
- Chef::CookbookVersion.should_receive(:checksum_cookbook_file).
- with("/file-cache/cookbooks/cookbook_a/attributes/default.rb").
- and_return("abc456")
-
- @file_cache.should_receive(:load).
- with("cookbooks/cookbook_a/recipes/default.rb", false).
- twice.
- and_return("/file-cache/cookbooks/cookbook_a/recipes/default.rb")
-
- @file_cache.should_receive(:load).
- with("cookbooks/cookbook_a/attributes/default.rb", false).
- twice.
- and_return("/file-cache/cookbooks/cookbook_a/attributes/default.rb")
+ setup_common_files_present_expectations
end
- it "does not update files" do
- @file_cache.should_not_receive(:move_to)
- @server_api.should_not_receive(:get_rest)
- @synchronizer.sync_cookbooks
+ context "Chef::Config[:no_lazy_load] is true" do
+ let(:no_lazy_load) { true }
+
+ before do
+ setup_no_lazy_files_and_templates_present_expectations
+ end
+
+ it "does not update files" do
+ expect(file_cache).not_to receive(:move_to)
+ expect(server_api).not_to receive(:get_rest)
+ synchronizer.sync_cookbooks
+ end
end
- end
+ context "Chef::Config[:no_lazy_load] is false" do
+ let(:no_lazy_load) { false }
+ it "does not update files" do
+ expect(file_cache).not_to receive(:move_to)
+ expect(server_api).not_to receive(:get_rest)
+ synchronizer.sync_cookbooks
+ end
+ end
+ end
end
-
end
-