Commit 11aea03f authored by Gabriel Mazetto's avatar Gabriel Mazetto

Use shared examples to test base sync and dependent services

parent a531a2d9
......@@ -4,31 +4,7 @@ describe Geo::BaseSyncService, services: true do
let(:project) { build('project')}
subject { described_class.new(project) }
describe '#execute' do
context 'when can acquire exclusive lease' do
before do
allow_any_instance_of(Gitlab::ExclusiveLease).to receive(:try_obtain) { 12345 }
end
it 'executes the synchronization' do
expect(subject).to receive(:sync_repository)
subject.execute
end
end
context 'when exclusive lease is not acquired' do
before do
allow_any_instance_of(Gitlab::ExclusiveLease).to receive(:try_obtain) { nil }
end
it 'is does not execute synchronization' do
expect(subject).not_to receive(:sync_repository)
subject.execute
end
end
end
it_behaves_like 'geo base sync execution'
describe '#lease_key' do
it 'returns a key in the correct pattern' do
......@@ -49,7 +25,6 @@ describe Geo::BaseSyncService, services: true do
end
it 'returns the prefix defined in the primary node' do
expect { subject.send(:primary_ssh_path_prefix) }.not_to raise_error
expect(subject.send(:primary_ssh_path_prefix)).to eq('git@localhost:')
end
end
......
......@@ -6,20 +6,22 @@ RSpec.describe Geo::RepositorySyncService, services: true do
subject { described_class.new(project) }
before do
allow(Gitlab::ExclusiveLease).to receive(:new)
.with(subject.lease_key, anything)
.and_return(lease)
allow_any_instance_of(Repository).to receive(:fetch_geo_mirror)
.and_return(true)
end
it_behaves_like 'geo base sync execution'
describe '#execute' do
let(:project) { create(:project_empty_repo) }
let(:repository) { project.repository }
let(:url_to_repo) { "#{primary.clone_url_prefix}#{project.path_with_namespace}.git" }
before do
allow(Gitlab::ExclusiveLease).to receive(:new)
.with(subject.lease_key, anything)
.and_return(lease)
allow_any_instance_of(Repository).to receive(:fetch_geo_mirror)
.and_return(true)
end
it 'fetches project repository' do
expect(repository).to receive(:fetch_geo_mirror).with(url_to_repo).once
......
......@@ -6,20 +6,22 @@ RSpec.describe Geo::WikiSyncService, services: true do
subject { described_class.new(project) }
before do
allow(Gitlab::ExclusiveLease).to receive(:new)
.with(subject.lease_key, anything)
.and_return(lease)
allow_any_instance_of(Repository).to receive(:fetch_geo_mirror)
.and_return(true)
end
it_behaves_like 'geo base sync execution'
describe '#execute' do
let(:project) { create(:project_empty_repo) }
let(:repository) { project.wiki.repository }
let(:url_to_repo) { "#{primary.clone_url_prefix}#{project.path_with_namespace}.wiki.git" }
before do
allow(Gitlab::ExclusiveLease).to receive(:new)
.with(subject.lease_key, anything)
.and_return(lease)
allow_any_instance_of(Repository).to receive(:fetch_geo_mirror)
.and_return(true)
end
it 'fetches wiki repository' do
expect(repository).to receive(:fetch_geo_mirror).with(url_to_repo).once
......
shared_examples 'geo base sync execution' do
describe '#execute' do
let(:project) { build('project')}
context 'when can acquire exclusive lease' do
before do
allow_any_instance_of(Gitlab::ExclusiveLease).to receive(:try_obtain) { 12345 }
end
it 'executes the synchronization' do
expect(subject).to receive(:sync_repository)
subject.execute
end
end
context 'when exclusive lease is not acquired' do
before do
allow_any_instance_of(Gitlab::ExclusiveLease).to receive(:try_obtain) { nil }
end
it 'is does not execute synchronization' do
expect(subject).not_to receive(:sync_repository)
subject.execute
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