2015-06-03 07:08:17 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2015-12-09 05:55:49 -05:00
|
|
|
describe Projects::DestroyService, services: true do
|
2015-06-03 07:08:17 -04:00
|
|
|
let!(:user) { create(:user) }
|
|
|
|
let!(:project) { create(:project, namespace: user.namespace) }
|
|
|
|
let!(:path) { project.repository.path_to_repo }
|
|
|
|
let!(:remove_path) { path.sub(/\.git\Z/, "+#{project.id}+deleted.git") }
|
2016-10-04 23:53:15 -04:00
|
|
|
let!(:async) { false } # execute or async_execute
|
2015-06-03 07:08:17 -04:00
|
|
|
|
2016-12-01 03:17:20 -05:00
|
|
|
shared_examples 'deleting the project' do
|
|
|
|
it 'deletes the project' do
|
|
|
|
expect(Project.all).not_to include(project)
|
|
|
|
expect(Dir.exist?(path)).to be_falsey
|
|
|
|
expect(Dir.exist?(remove_path)).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-06-03 07:08:17 -04:00
|
|
|
context 'Sidekiq inline' do
|
|
|
|
before do
|
|
|
|
# Run sidekiq immediatly to check that renamed repository will be removed
|
|
|
|
Sidekiq::Testing.inline! { destroy_project(project, user, {}) }
|
|
|
|
end
|
|
|
|
|
2016-12-01 03:17:20 -05:00
|
|
|
it_behaves_like 'deleting the project'
|
2015-06-03 07:08:17 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'Sidekiq fake' do
|
|
|
|
before do
|
|
|
|
# Dont run sidekiq to check if renamed repository exists
|
|
|
|
Sidekiq::Testing.fake! { destroy_project(project, user, {}) }
|
|
|
|
end
|
|
|
|
|
2015-06-13 18:19:24 -04:00
|
|
|
it { expect(Project.all).not_to include(project) }
|
2016-05-08 17:33:34 -04:00
|
|
|
it { expect(Dir.exist?(path)).to be_falsey }
|
|
|
|
it { expect(Dir.exist?(remove_path)).to be_truthy }
|
2015-06-03 07:08:17 -04:00
|
|
|
end
|
|
|
|
|
2016-10-04 23:53:15 -04:00
|
|
|
context 'async delete of project with private issue visibility' do
|
|
|
|
let!(:async) { true }
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.project_feature.update_attribute("issues_access_level", ProjectFeature::PRIVATE)
|
|
|
|
# Run sidekiq immediately to check that renamed repository will be removed
|
|
|
|
Sidekiq::Testing.inline! { destroy_project(project, user, {}) }
|
|
|
|
end
|
|
|
|
|
2016-12-01 03:17:20 -05:00
|
|
|
it_behaves_like 'deleting the project'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'delete with pipeline' do # which has optimistic locking
|
|
|
|
let!(:pipeline) { create(:ci_pipeline, project: project) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
expect(project).to receive(:destroy!).and_call_original
|
|
|
|
|
|
|
|
perform_enqueued_jobs do
|
|
|
|
destroy_project(project, user, {})
|
|
|
|
end
|
2016-10-04 23:53:15 -04:00
|
|
|
end
|
2016-12-01 03:17:20 -05:00
|
|
|
|
|
|
|
it_behaves_like 'deleting the project'
|
2016-10-04 23:53:15 -04:00
|
|
|
end
|
|
|
|
|
2016-05-16 19:03:55 -04:00
|
|
|
context 'container registry' do
|
|
|
|
before do
|
2016-05-16 19:07:49 -04:00
|
|
|
stub_container_registry_config(enabled: true)
|
2016-05-16 19:03:55 -04:00
|
|
|
stub_container_registry_tags('tag')
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'tags deletion succeeds' do
|
|
|
|
it do
|
|
|
|
expect_any_instance_of(ContainerRegistry::Tag).to receive(:delete).and_return(true)
|
|
|
|
|
|
|
|
destroy_project(project, user, {})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'tags deletion fails' do
|
|
|
|
before { expect_any_instance_of(ContainerRegistry::Tag).to receive(:delete).and_return(false) }
|
|
|
|
|
|
|
|
subject { destroy_project(project, user, {}) }
|
|
|
|
|
|
|
|
it { expect{subject}.to raise_error(Projects::DestroyService::DestroyError) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-06-03 07:08:17 -04:00
|
|
|
def destroy_project(project, user, params)
|
2016-10-04 23:53:15 -04:00
|
|
|
if async
|
|
|
|
Projects::DestroyService.new(project, user, params).async_execute
|
|
|
|
else
|
|
|
|
Projects::DestroyService.new(project, user, params).execute
|
|
|
|
end
|
2015-06-03 07:08:17 -04:00
|
|
|
end
|
|
|
|
end
|