2020-03-13 15:44:24 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Repositories::DestroyService do
|
2020-03-13 15:44:24 +05:30
|
|
|
let_it_be(:user) { create(:user) }
|
2021-09-30 23:02:18 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
let!(:project) { create(:project, :repository, namespace: user.namespace) }
|
|
|
|
let(:repository) { project.repository }
|
|
|
|
let(:path) { repository.disk_path }
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
subject { described_class.new(repository).execute }
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2022-07-23 23:45:48 +05:30
|
|
|
it 'removes the repository' do
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(project.gitlab_shell.repository_exists?(project.repository_storage, path + '.git')).to be_truthy
|
|
|
|
|
|
|
|
subject
|
|
|
|
|
2022-07-23 23:45:48 +05:30
|
|
|
# Because the removal happens inside a run_after_commit callback we need to
|
2020-03-13 15:44:24 +05:30
|
|
|
# trigger the callback
|
|
|
|
project.touch
|
2022-07-23 23:45:48 +05:30
|
|
|
|
|
|
|
expect(project.gitlab_shell.repository_exists?(project.repository_storage, path + '.git')).to be_falsey
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
context 'on a read-only instance' do
|
|
|
|
before do
|
|
|
|
allow(Gitlab::Database).to receive(:read_only?).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'schedules the repository deletion' do
|
2022-07-23 23:45:48 +05:30
|
|
|
expect(project.gitlab_shell.repository_exists?(project.repository_storage, path + '.git')).to be_truthy
|
2020-07-28 23:09:34 +05:30
|
|
|
|
|
|
|
subject
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2022-07-23 23:45:48 +05:30
|
|
|
expect(project.gitlab_shell.repository_exists?(project.repository_storage, path + '.git')).to be_falsey
|
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'flushes the repository cache' do
|
|
|
|
expect(repository).to receive(:before_delete)
|
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not perform any action if repository path does not exist and returns success' do
|
|
|
|
expect(repository).to receive(:disk_path).and_return('foo')
|
|
|
|
expect(repository).not_to receive(:before_delete)
|
|
|
|
|
2022-05-07 20:08:51 +05:30
|
|
|
expect(subject[:status]).to eq :success
|
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2022-05-07 20:08:51 +05:30
|
|
|
it 'gracefully handles exception if the repository does not exist on disk' do
|
|
|
|
expect(repository).to receive(:before_delete).and_raise(Gitlab::Git::Repository::NoRepository)
|
|
|
|
expect(subject[:status]).to eq :success
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
context 'with a project wiki repository' do
|
|
|
|
let(:project) { create(:project, :wiki_repo) }
|
|
|
|
let(:repository) { project.wiki.repository }
|
|
|
|
|
|
|
|
it 'schedules the repository deletion' do
|
2022-07-23 23:45:48 +05:30
|
|
|
expect(project.gitlab_shell.repository_exists?(project.repository_storage, path + '.git')).to be_truthy
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2022-07-23 23:45:48 +05:30
|
|
|
subject
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2022-07-23 23:45:48 +05:30
|
|
|
# Because the removal happens inside a run_after_commit callback we need to
|
2021-01-03 14:25:43 +05:30
|
|
|
# trigger the callback
|
|
|
|
project.touch
|
2022-07-23 23:45:48 +05:30
|
|
|
|
|
|
|
expect(project.gitlab_shell.repository_exists?(project.repository_storage, path + '.git')).to be_falsey
|
2021-01-03 14:25:43 +05:30
|
|
|
end
|
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|