Commit ea13a8ce authored by Gabriel Mazetto's avatar Gabriel Mazetto

Improve repository_base_sync_service specs

parent 59947b4d
......@@ -117,7 +117,7 @@ module Geo
def fetch_geo_mirror(repository)
# Fetch the repository, using a JWT header for authentication
repository.fetch_as_mirror(replicator.remote_url, forced: true, http_authorization_header: replicator.jwt_authentication_header)
repository.fetch_as_mirror(replicator.remote_url, forced: true, http_authorization_header: replicator.jwt_authentication_header(repository))
end
# Use snapshotting for redownloads *only* when enabled.
......
......@@ -41,6 +41,10 @@ module Geo
LEASE_TIMEOUT
end
def repository
raise NotImplementedError, 'Define a reference to the repository'
end
private
def fetch_repository
......@@ -57,9 +61,9 @@ module Geo
redownload_repository
@new_repository = true
elsif repository.exists?
fetch_geo_mirror(repository)
fetch_geo_mirror
else
clone_geo_mirror(repository)
clone_geo_mirror
repository.expire_status_cache # after_create
# Because we ensure a repository exists by this point, we need to
......@@ -101,16 +105,20 @@ module Geo
end
# Update an existing repository using special credentials
# @param [Repository] repository
def fetch_geo_mirror(repository)
#
def fetch_geo_mirror
# Fetch the repository, using a JWT header for authentication
repository.fetch_as_mirror(remote_url, forced: true, http_authorization_header: jwt_authentication_header)
repository.fetch_as_mirror(remote_url,
forced: true,
http_authorization_header: jwt_authentication_header)
end
# Clone a new repository using Geo special credentials
# @param [Repository] repository
def clone_geo_mirror(repository)
repository.clone_as_mirror(remote_url, http_authorization_header: jwt_authentication_header)
#
def clone_geo_mirror
# Clone the repository, using a JWT header for authentication
repository.clone_as_mirror(remote_url,
http_authorization_header: jwt_authentication_header)
end
# Build a JWT header for authentication
......
......@@ -3,7 +3,16 @@
require 'spec_helper'
RSpec.describe Geo::RepositoryBaseSyncService do
include ::EE::GeoHelpers
let(:project) { build('project') }
let(:repository) { project.repository }
let_it_be(:geo_primary) { create(:geo_node, :primary) }
let_it_be(:geo_secondary) { create(:geo_node, :secondary) }
before do
stub_current_geo_node(geo_secondary)
end
subject { described_class.new(project) }
......@@ -15,4 +24,38 @@ RSpec.describe Geo::RepositoryBaseSyncService do
expect(subject.lease_key).to eq('geo_sync_service:wiki:999')
end
end
describe '#lease_timeout' do
it 'returns a lease timeout value' do
expect(subject.lease_timeout). to eq(8.hours)
end
end
describe '#repository' do
it 'raises a NotImplementedError' do
expect { subject.repository }.to raise_error(NotImplementedError)
end
end
context 'with a repository defined' do
before do
allow(subject).to receive(:repository) { repository }
end
describe '#fetch_geo_mirror' do
it 'delegates to repository#fetch_as_mirror' do
expect(repository).to receive(:fetch_as_mirror)
subject.send(:fetch_geo_mirror)
end
end
describe '#clone_geo_mirror' do
it 'delegates to repository#clone_as_mirror' do
expect(repository).to receive(:clone_as_mirror)
subject.send(:clone_geo_mirror)
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