Commit ea13a8ce authored by Gabriel Mazetto's avatar Gabriel Mazetto

Improve repository_base_sync_service specs

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