Commit 997952df authored by Gabriel Mazetto's avatar Gabriel Mazetto Committed by Mayra Cabrera

Refactor Geo-finders specs to remove duplication

The way Shared Examples were being used (in reverse) were
causing issues and forcing multiple `let` blocks to be replicated
at each context.
parent 516ef2ea
......@@ -20,7 +20,7 @@ describe Geo::JobArtifactRegistryFinder, :geo_fdw do
stub_artifacts_object_storage
end
shared_examples 'counts all the things' do
context 'counts all the things' do
describe '#count_syncable' do
let!(:job_artifact_1) { create(:ci_job_artifact, project: synced_project) }
let!(:job_artifact_2) { create(:ci_job_artifact, project: unsynced_project) }
......@@ -399,7 +399,7 @@ describe Geo::JobArtifactRegistryFinder, :geo_fdw do
end
end
shared_examples 'finds all the things' do
context 'finds all the things' do
describe '#find_unsynced' do
let!(:job_artifact_1) { create(:ci_job_artifact, project: synced_project) }
let!(:job_artifact_2) { create(:ci_job_artifact, project: unsynced_project) }
......
......@@ -31,7 +31,7 @@ describe Geo::LfsObjectRegistryFinder, :geo_fdw do
stub_lfs_object_storage
end
shared_examples 'counts all the things' do
context 'counts all the things' do
describe '#count_syncable' do
before do
allow_any_instance_of(LfsObjectsProject).to receive(:update_project_statistics).and_return(nil)
......@@ -361,7 +361,7 @@ describe Geo::LfsObjectRegistryFinder, :geo_fdw do
end
end
shared_examples 'finds all the things' do
context 'finds all the things' do
describe '#find_unsynced' do
it 'returns LFS objects without an entry on the tracking database' do
create(:geo_file_registry, :lfs, file_id: lfs_object_1.id)
......
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::Geo::FileDownloader, :geo do
include EE::GeoHelpers
set(:primary_node) { create(:geo_node, :primary) }
set(:secondary_node) { create(:geo_node) }
subject { downloader.execute }
let(:upload) { create(:upload, :issuable_upload, :with_file) }
let(:downloader) { described_class.new(:file, upload.id) }
context 'when in primary geo node' do
before do
stub_current_geo_node(primary_node)
end
it 'fails to download the file' do
expect(subject.success).to be_falsey
expect(subject.primary_missing_file).to be_falsey
end
end
context 'when in a secondary geo node' do
before do
stub_current_geo_node(secondary_node)
stub_geo_file_transfer(:file, upload)
end
it 'downloads the file' do
expect(subject.success).to be_truthy
expect(subject.primary_missing_file).to be_falsey
end
end
def stub_geo_file_transfer(file_type, upload)
url = primary_node.geo_transfers_url(file_type, upload.id.to_s)
stub_request(:get, url).to_return(status: 200, body: upload.build_uploader.file.read, headers: {})
end
end
......@@ -17,7 +17,4 @@ shared_examples_for 'a file registry finder' do
expect(subject).to respond_to(method)
end
end
include_examples 'counts all the things'
include_examples 'finds all the things'
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