spec/unit/provider/deploy_spec.rb in chef-10.14.2 vs spec/unit/provider/deploy_spec.rb in chef-10.14.4.rc.0
- old
+ new
@@ -41,24 +41,36 @@
it "supports :deploy and :rollback actions" do
@provider.should respond_to(:action_deploy)
@provider.should respond_to(:action_rollback)
end
- it "creates deploy_to dir if it does not exist yet" do
- FileUtils.should_receive(:mkdir_p).with(@resource.deploy_to)
- FileUtils.should_receive(:mkdir_p).with(@resource.shared_path)
- ::File.stub!(:directory?).and_return(false)
- @provider.stub(:copy_cached_repo)
- @provider.stub(:update_cached_repo)
- @provider.stub(:symlink)
- @provider.stub(:migrate)
- @provider.deploy
- @provider.converge
+ context "when the deploy_to dir does not exist yet" do
+ before do
+ FileUtils.should_receive(:mkdir_p).with(@resource.deploy_to).ordered
+ FileUtils.should_receive(:mkdir_p).with(@resource.shared_path).ordered
+ ::Dir.should_receive(:chdir).with(@expected_release_dir).exactly(4).times
+ ::File.stub!(:directory?).and_return(false)
+ @provider.stub(:symlink)
+ @provider.stub(:migrate)
+ @provider.stub(:copy_cached_repo)
+ end
+
+ it "creates deploy_to dir" do
+ @provider.stub(:update_cached_repo)
+ @provider.deploy
+ end
+
+ it "creates deploy_to dir before calling update_cached_repo (CHEF-3435)" do
+ @provider.send(:converge_actions).should_receive(:empty?).and_return(false)
+ @provider.should_receive(:update_cached_repo).ordered
+ @provider.deploy
+ end
end
it "does not create deploy_to dir if it exists" do
::File.stub!(:directory?).and_return(true)
+ ::Dir.should_receive(:chdir).with(@expected_release_dir).exactly(4).times
FileUtils.should_not_receive(:mkdir_p).with(@resource.deploy_to)
FileUtils.should_not_receive(:mkdir_p).with(@resource.shared_path)
@provider.stub(:copy_cached_repo)
@provider.stub(:update_cached_repo)
@provider.stub(:symlink)
@@ -66,10 +78,11 @@
@provider.deploy
@provider.converge
end
it "ensures the deploy_to dir ownership after the verfication that it exists" do
+ ::Dir.should_receive(:chdir).with(@expected_release_dir).exactly(4).times
@provider.should_receive(:verify_directories_exist).ordered
@provider.should_receive(:enforce_ownership).ordered
@provider.stub(:copy_cached_repo)
@provider.stub(:update_cached_repo)
@provider.stub(:install_gems)
@@ -279,12 +292,34 @@
end
it "skips an eval callback if the file doesn't exist" do
barbaz_callback = @expected_release_dir + "/deploy/barbaz.rb"
::File.should_receive(:exist?).with(barbaz_callback).and_return(false)
+ ::Dir.should_receive(:chdir).with(@expected_release_dir).and_yield
@provider.should_not_receive(:from_file)
@provider.callback(:barbaz, nil)
@provider.converge
+ end
+
+ # CHEF-3449 #converge_by is called in #recipe_eval and must happen in sequence
+ # with the other calls to #converge_by to keep the train on the tracks
+ it "evaluates a callback file before the corresponding step" do
+ ::Dir.should_receive(:chdir).with(@expected_release_dir).exactly(4).times.and_yield
+ @provider.should_receive(:verify_directories_exist)
+ @provider.should_receive(:update_cached_repo)
+ @provider.should_receive(:enforce_ownership)
+ @provider.should_receive(:copy_cached_repo)
+ @provider.should_receive(:install_gems)
+ @provider.should_receive(:enforce_ownership)
+ @provider.should_receive(:converge_by).ordered # before_migrate
+ @provider.should_receive(:migrate).ordered
+ @provider.should_receive(:converge_by).ordered # before_symlink
+ @provider.should_receive(:symlink).ordered
+ @provider.should_receive(:converge_by).ordered # before_restart
+ @provider.should_receive(:restart).ordered
+ @provider.should_receive(:converge_by).ordered # after_restart
+ @provider.should_receive(:cleanup!)
+ @provider.deploy
end
it "gets a SCM provider as specified by its resource" do
@provider.scm_provider.should be_an_instance_of(Chef::Provider::Git)
@provider.scm_provider.new_resource.destination.should eql("/my/deploy/dir/shared/cached-copy")