Refactoring spec for Geo::RepositoriesCleanUpWorker

parent 3d953e3a
require 'spec_helper'
describe Geo::RepositoriesCleanUpWorker do
let!(:geo_node) { create(:geo_node) }
let(:synced_group) { create(:group) }
let!(:project_in_synced_group) { create(:project, group: synced_group) }
let!(:unsynced_project) { create(:project, :repository) }
describe '#perform' do
let(:geo_node) { create(:geo_node) }
before do
allow_any_instance_of(Gitlab::ExclusiveLease).to receive(:try_obtain) { true }
end
context 'when node has namespace restrictions' do
let(:synced_group) { create(:group) }
let(:geo_node) { create(:geo_node, namespaces: [synced_group]) }
it 'performs GeoRepositoryDestroyWorker for each project that does not belong to selected namespaces to replicate' do
geo_node.update_attribute(:namespaces, [synced_group])
project_in_synced_group = create(:project, group: synced_group)
unsynced_project = create(:project, :repository)
expect(GeoRepositoryDestroyWorker).to receive(:perform_async)
.with(unsynced_project.id, unsynced_project.name, unsynced_project.full_path)
.once.and_return(1)
expect(GeoRepositoryDestroyWorker).not_to receive(:perform_async)
.with(project_in_synced_group.id, project_in_synced_group.name, project_in_synced_group.full_path)
subject.perform(geo_node.id)
end
it 'does not perform GeoRepositoryDestroyWorker when repository does not exist' do
allow_any_instance_of(Gitlab::Shell).to receive(:exists?)
.with(unsynced_project.repository_storage_path, "#{unsynced_project.disk_path}.git")
.and_return(false)
create(:project)
expect(GeoRepositoryDestroyWorker).not_to receive(:perform_async)
......@@ -33,28 +35,22 @@ describe Geo::RepositoriesCleanUpWorker do
end
end
context 'when does not node have namespace restrictions' do
it 'does not perform GeoRepositoryDestroyWorker' do
it 'does not perform GeoRepositoryDestroyWorker when does not node have namespace restrictions' do
expect(GeoRepositoryDestroyWorker).not_to receive(:perform_async)
subject.perform(geo_node.id)
end
end
context 'when cannnot obtain a lease' do
it 'does not perform GeoRepositoryDestroyWorker' do
it 'does not perform GeoRepositoryDestroyWorker when cannnot obtain a lease' do
allow_any_instance_of(Gitlab::ExclusiveLease).to receive(:try_obtain) { false }
expect(GeoRepositoryDestroyWorker).not_to receive(:perform_async)
subject.perform(geo_node.id)
end
end
context 'when Geo node could not be found' do
it 'does not raise an error' do
it 'does not raise an error when node could not be found' do
expect { subject.perform(-1) }.not_to raise_error
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment