Remove duplicated code in Geo event store specs

This introduces a shared example that encapsulates the common
behavior present in the parent class removing the duplicated
code in the specs.
parent 611ef60f
# frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
describe Geo::HashedStorageAttachmentsEventStore do describe Geo::HashedStorageAttachmentsEventStore do
include EE::GeoHelpers
set(:secondary_node) { create(:geo_node) }
let(:project) { create(:project, path: 'bar') } let(:project) { create(:project, path: 'bar') }
let(:attachments_event) { build(:geo_hashed_storage_attachments_event, project: project) } let(:attachments_event) { build(:geo_hashed_storage_attachments_event, project: project) }
set(:secondary_node) { create(:geo_node) }
let(:old_attachments_path) { attachments_event.old_attachments_path } let(:old_attachments_path) { attachments_event.old_attachments_path }
let(:new_attachments_path) {attachments_event.new_attachments_path } let(:new_attachments_path) {attachments_event.new_attachments_path }
subject(:event_store) { described_class.new(project, old_storage_version: 1, new_storage_version: 2, old_attachments_path: old_attachments_path, new_attachments_path: new_attachments_path) } subject { described_class.new(project, old_storage_version: 1, new_storage_version: 2, old_attachments_path: old_attachments_path, new_attachments_path: new_attachments_path) }
before do before do
TestEnv.clean_test_path TestEnv.clean_test_path
end end
describe '#create' do describe '#create' do
it 'does not create an event when not running on a primary node' do it_behaves_like 'a Geo event store', Geo::HashedStorageAttachmentsEvent
allow(Gitlab::Geo).to receive(:primary?) { false }
expect { event_store.create }.not_to change(Geo::HashedStorageAttachmentsEvent, :count)
end
context 'when running on a primary node' do context 'when running on a primary node' do
before do before do
allow(Gitlab::Geo).to receive(:primary?) { true } stub_primary_node
end
it 'does not create an event when there are no secondary nodes' do
allow(Gitlab::Geo).to receive(:secondary_nodes) { [] }
expect { event_store.create }.not_to change(Geo::HashedStorageAttachmentsEvent, :count)
end
it 'creates a attachment migration event' do
expect { event_store.create }.to change(Geo::HashedStorageAttachmentsEvent, :count).by(1)
end end
it 'tracks project attributes' do it 'tracks project attributes' do
event_store.create subject.create
event = Geo::HashedStorageAttachmentsEvent.last
expect(event).to have_attributes( expect(Geo::HashedStorageAttachmentsEvent.last).to have_attributes(
old_attachments_path: old_attachments_path, old_attachments_path: old_attachments_path,
new_attachments_path: new_attachments_path new_attachments_path: new_attachments_path
) )
......
# frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
describe Geo::HashedStorageMigratedEventStore do describe Geo::HashedStorageMigratedEventStore do
let(:project) { create(:project, path: 'bar') } include EE::GeoHelpers
set(:secondary_node) { create(:geo_node) } set(:secondary_node) { create(:geo_node) }
let(:project) { create(:project, path: 'bar') }
let(:old_disk_path) { "#{project.namespace.full_path}/foo" } let(:old_disk_path) { "#{project.namespace.full_path}/foo" }
let(:old_wiki_disk_path) { "#{old_disk_path}.wiki" } let(:old_wiki_disk_path) { "#{old_disk_path}.wiki" }
subject(:event_store) { described_class.new(project, old_storage_version: nil, old_disk_path: old_disk_path, old_wiki_disk_path: old_wiki_disk_path) } subject { described_class.new(project, old_storage_version: nil, old_disk_path: old_disk_path, old_wiki_disk_path: old_wiki_disk_path) }
describe '#create' do before do
before do TestEnv.clean_test_path
TestEnv.clean_test_path end
end
it 'does not create an event when not running on a primary node' do
allow(Gitlab::Geo).to receive(:primary?) { false }
expect { event_store.create }.not_to change(Geo::HashedStorageMigratedEvent, :count) describe '#create' do
end it_behaves_like 'a Geo event store', Geo::HashedStorageMigratedEvent
context 'when running on a primary node' do context 'when running on a primary node' do
before do before do
allow(Gitlab::Geo).to receive(:primary?) { true } stub_primary_node
end
it 'does not create an event when there are no secondary nodes' do
allow(Gitlab::Geo).to receive(:secondary_nodes) { [] }
expect { subject.create }.not_to change(Geo::HashedStorageMigratedEvent, :count)
end
it 'creates a hashed migration event' do
expect { event_store.create }.to change(Geo::HashedStorageMigratedEvent, :count).by(1)
end end
it 'tracks project attributes' do it 'tracks project attributes' do
event_store.create subject.create
event = Geo::HashedStorageMigratedEvent.last
expect(event).to have_attributes( expect(Geo::HashedStorageMigratedEvent.last).to have_attributes(
repository_storage_name: project.repository_storage, repository_storage_name: project.repository_storage,
old_storage_version: nil, old_storage_version: nil,
new_storage_version: project.storage_version, new_storage_version: project.storage_version,
......
# frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
describe Geo::JobArtifactDeletedEventStore do describe Geo::JobArtifactDeletedEventStore do
include EE::GeoHelpers
set(:secondary_node) { create(:geo_node) } set(:secondary_node) { create(:geo_node) }
let(:job_artifact) { create(:ci_job_artifact, :archive) } let(:job_artifact) { create(:ci_job_artifact, :archive) }
subject(:event_store) { described_class.new(job_artifact) } subject { described_class.new(job_artifact) }
describe '#create' do describe '#create' do
it 'does not create an event when not running on a primary node' do it_behaves_like 'a Geo event store', Geo::JobArtifactDeletedEvent
allow(Gitlab::Geo).to receive(:primary?) { false }
expect { event_store.create }.not_to change(Geo::JobArtifactDeletedEvent, :count)
end
context 'when running on a primary node' do context 'when running on a primary node' do
before do before do
allow(Gitlab::Geo).to receive(:primary?) { true } stub_primary_node
end end
it 'does not create an event when LFS object is not on a local store' do it 'does not create an event when LFS object is not on a local store' do
allow(job_artifact).to receive(:local_store?).and_return(false) allow(job_artifact).to receive(:local_store?).and_return(false)
expect { event_store.create }.not_to change(Geo::JobArtifactDeletedEvent, :count) expect { subject.create }.not_to change(Geo::JobArtifactDeletedEvent, :count)
end
it 'does not create an event when there are no secondary nodes' do
allow(Gitlab::Geo).to receive(:secondary_nodes) { [] }
expect { event_store.create }.not_to change(Geo::JobArtifactDeletedEvent, :count)
end
it 'creates a LFS object deleted event' do
expect { event_store.create }.to change(Geo::JobArtifactDeletedEvent, :count).by(1)
end end
it 'tracks LFS object attributes' do it 'tracks LFS object attributes' do
event_store.create subject.create
event = Geo::JobArtifactDeletedEvent.last
expect(event.job_artifact_id).to eq(job_artifact.id) expect(Geo::JobArtifactDeletedEvent.last).to have_attributes(
expect(event.file_path).to match(%r{\A\h+/\h+/\h+/[\d_]+/\d+/\d+/ci_build_artifacts.zip\z}) job_artifact_id: job_artifact.id,
file_path: match(%r{\A\h+/\h+/\h+/[\d_]+/\d+/\d+/ci_build_artifacts.zip\z})
)
end end
it 'logs an error message when event creation fail' do it 'logs an error message when event creation fail' do
invalid_job_artifact = create(:ci_job_artifact) invalid_job_artifact = create(:ci_job_artifact)
event_store = described_class.new(invalid_job_artifact) subject = described_class.new(invalid_job_artifact)
expected_message = { expected_message = {
class: "Geo::JobArtifactDeletedEventStore", class: "Geo::JobArtifactDeletedEventStore",
...@@ -58,7 +49,7 @@ describe Geo::JobArtifactDeletedEventStore do ...@@ -58,7 +49,7 @@ describe Geo::JobArtifactDeletedEventStore do
expect(Gitlab::Geo::Logger).to receive(:error) expect(Gitlab::Geo::Logger).to receive(:error)
.with(expected_message).and_call_original .with(expected_message).and_call_original
event_store.create subject.create
end end
end end
end end
......
# frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
describe Geo::LfsObjectDeletedEventStore do describe Geo::LfsObjectDeletedEventStore do
include EE::GeoHelpers
set(:secondary_node) { create(:geo_node) } set(:secondary_node) { create(:geo_node) }
let(:lfs_object) { create(:lfs_object, :with_file, oid: 'b68143e6463773b1b6c6fd009a76c32aeec041faff32ba2ed42fd7f708a00004') } let(:lfs_object) { create(:lfs_object, :with_file, oid: 'b68143e6463773b1b6c6fd009a76c32aeec041faff32ba2ed42fd7f708a00004') }
subject(:event_store) { described_class.new(lfs_object) } subject { described_class.new(lfs_object) }
describe '#create' do describe '#create' do
it 'does not create an event when not running on a primary node' do it_behaves_like 'a Geo event store', Geo::LfsObjectDeletedEvent
allow(Gitlab::Geo).to receive(:primary?) { false }
expect { event_store.create }.not_to change(Geo::LfsObjectDeletedEvent, :count)
end
context 'when running on a primary node' do context 'when running on a primary node' do
before do before do
allow(Gitlab::Geo).to receive(:primary?) { true } stub_primary_node
end end
it 'does not create an event when LFS object is not on a local store' do it 'does not create an event when LFS object is not on a local store' do
allow(lfs_object).to receive(:local_store?).and_return(false) allow(lfs_object).to receive(:local_store?).and_return(false)
expect { event_store.create }.not_to change(Geo::LfsObjectDeletedEvent, :count) expect { subject.create }.not_to change(Geo::LfsObjectDeletedEvent, :count)
end
it 'does not create an event when there are no secondary nodes' do
allow(Gitlab::Geo).to receive(:secondary_nodes) { [] }
expect { event_store.create }.not_to change(Geo::LfsObjectDeletedEvent, :count)
end
it 'creates a LFS object deleted event' do
expect { event_store.create }.to change(Geo::LfsObjectDeletedEvent, :count).by(1)
end end
it 'tracks LFS object attributes' do it 'tracks LFS object attributes' do
event_store.create subject.create
event = Geo::LfsObjectDeletedEvent.last
expect(event).to have_attributes( expect(Geo::LfsObjectDeletedEvent.last).to have_attributes(
lfs_object_id: lfs_object.id, lfs_object_id: lfs_object.id,
oid: lfs_object.oid, oid: lfs_object.oid,
file_path: 'b6/81/43e6463773b1b6c6fd009a76c32aeec041faff32ba2ed42fd7f708a00004' file_path: 'b6/81/43e6463773b1b6c6fd009a76c32aeec041faff32ba2ed42fd7f708a00004'
...@@ -48,7 +37,7 @@ describe Geo::LfsObjectDeletedEventStore do ...@@ -48,7 +37,7 @@ describe Geo::LfsObjectDeletedEventStore do
it 'logs an error message when event creation fail' do it 'logs an error message when event creation fail' do
invalid_lfs_object = create(:lfs_object) invalid_lfs_object = create(:lfs_object)
event_store = described_class.new(invalid_lfs_object) subject = described_class.new(invalid_lfs_object)
expected_message = { expected_message = {
class: "Geo::LfsObjectDeletedEventStore", class: "Geo::LfsObjectDeletedEventStore",
...@@ -61,7 +50,7 @@ describe Geo::LfsObjectDeletedEventStore do ...@@ -61,7 +50,7 @@ describe Geo::LfsObjectDeletedEventStore do
expect(Gitlab::Geo::Logger).to receive(:error) expect(Gitlab::Geo::Logger).to receive(:error)
.with(expected_message).and_call_original .with(expected_message).and_call_original
event_store.create subject.create
end end
end end
end end
......
# frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
describe Geo::RepositoriesChangedEventStore do describe Geo::RepositoriesChangedEventStore do
include EE::GeoHelpers
let(:geo_node) { create(:geo_node) } let(:geo_node) { create(:geo_node) }
subject { described_class.new(geo_node) } subject { described_class.new(geo_node) }
describe '#create' do describe '#create' do
it 'does not create an event when not running on a primary node' do it_behaves_like 'a Geo event store', Geo::RepositoriesChangedEvent
allow(Gitlab::Geo).to receive(:primary?) { false }
expect { subject.create }.not_to change(Geo::RepositoriesChangedEvent, :count)
end
it 'creates a repositories changed event when running on a primary node' do
allow(Gitlab::Geo).to receive(:primary?) { true }
expect { subject.create }.to change(Geo::RepositoriesChangedEvent, :count).by(1)
end
end end
end end
# frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
describe Geo::RepositoryCreatedEventStore do describe Geo::RepositoryCreatedEventStore do
include EE::GeoHelpers
set(:project) { create(:project) } set(:project) { create(:project) }
set(:secondary_node) { create(:geo_node) } set(:secondary_node) { create(:geo_node) }
subject(:create!) { described_class.new(project).create } subject { described_class.new(project) }
describe '#create' do describe '#create' do
it 'does not create an event when not running on a primary node' do it_behaves_like 'a Geo event store', Geo::RepositoryCreatedEvent
allow(Gitlab::Geo).to receive(:primary?) { false }
expect { create! }.not_to change(Geo::RepositoryCreatedEvent, :count)
end
context 'running on a primary node' do context 'running on a primary node' do
before do before do
allow(Gitlab::Geo).to receive(:primary?) { true } stub_primary_node
end
it 'does not create an event when there are no secondary nodes' do
allow(Gitlab::Geo).to receive(:secondary_nodes) { [] }
expect { create! }.not_to change(Geo::RepositoryCreatedEvent, :count)
end
it 'creates a created event' do
expect { create! }.to change(Geo::RepositoryCreatedEvent, :count).by(1)
end end
it 'tracks information for the created project' do it 'tracks information for the created project' do
create! subject.create
event = Geo::RepositoryCreatedEvent.last
expect(event).to have_attributes( expect(Geo::RepositoryCreatedEvent.last).to have_attributes(
project_id: project.id, project_id: project.id,
repo_path: project.disk_path, repo_path: project.disk_path,
wiki_path: project.wiki.disk_path, wiki_path: project.wiki.disk_path,
...@@ -45,10 +33,9 @@ describe Geo::RepositoryCreatedEventStore do ...@@ -45,10 +33,9 @@ describe Geo::RepositoryCreatedEventStore do
it 'does not set a wiki path if the wiki is disabled' do it 'does not set a wiki path if the wiki is disabled' do
project.update!(wiki_enabled: false) project.update!(wiki_enabled: false)
create! subject.create
event = Geo::RepositoryCreatedEvent.last expect(Geo::RepositoryCreatedEvent.last.wiki_path).to be_nil
expect(event.wiki_path).to be_nil
end end
end end
end end
......
# frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
describe Geo::RepositoryDeletedEventStore do describe Geo::RepositoryDeletedEventStore do
include EE::GeoHelpers
set(:project) { create(:project, path: 'bar') } set(:project) { create(:project, path: 'bar') }
set(:secondary_node) { create(:geo_node) } set(:secondary_node) { create(:geo_node) }
let(:project_id) { project.id } let(:project_id) { project.id }
let(:project_name) { project.name } let(:project_name) { project.name }
let(:repo_path) { project.full_path } let(:repo_path) { project.full_path }
...@@ -12,37 +17,23 @@ describe Geo::RepositoryDeletedEventStore do ...@@ -12,37 +17,23 @@ describe Geo::RepositoryDeletedEventStore do
subject { described_class.new(project, repo_path: repo_path, wiki_path: wiki_path) } subject { described_class.new(project, repo_path: repo_path, wiki_path: wiki_path) }
describe '#create' do describe '#create' do
it 'does not create an event when not running on a primary node' do it_behaves_like 'a Geo event store', Geo::RepositoryDeletedEvent
allow(Gitlab::Geo).to receive(:primary?) { false }
expect { subject.create }.not_to change(Geo::RepositoryDeletedEvent, :count)
end
context 'when running on a primary node' do context 'when running on a primary node' do
before do before do
allow(Gitlab::Geo).to receive(:primary?) { true } stub_primary_node
end
it 'does not create an event when there are no secondary nodes' do
allow(Gitlab::Geo).to receive(:secondary_nodes) { [] }
expect { subject.create }.not_to change(Geo::RepositoryDeletedEvent, :count)
end
it 'creates a deleted event' do
expect { subject.create }.to change(Geo::RepositoryDeletedEvent, :count).by(1)
end end
it 'tracks information for the deleted project' do it 'tracks information for the deleted project' do
subject.create subject.create
event = Geo::RepositoryDeletedEvent.last expect(Geo::RepositoryDeletedEvent.last).to have_attributes(
project_id: project_id,
expect(event.project_id).to eq(project_id) deleted_path: repo_path,
expect(event.deleted_path).to eq(repo_path) deleted_wiki_path: wiki_path,
expect(event.deleted_wiki_path).to eq(wiki_path) deleted_project_name: project_name,
expect(event.deleted_project_name).to eq(project_name) repository_storage_name: storage_name
expect(event.repository_storage_name).to eq(storage_name) )
end end
end end
end end
......
# frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
describe Geo::RepositoryRenamedEventStore do describe Geo::RepositoryRenamedEventStore do
include EE::GeoHelpers
set(:project) { create(:project, path: 'bar') } set(:project) { create(:project, path: 'bar') }
set(:secondary_node) { create(:geo_node) } set(:secondary_node) { create(:geo_node) }
let(:old_path) { 'foo' } let(:old_path) { 'foo' }
let(:old_path_with_namespace) { "#{project.namespace.full_path}/foo" } let(:old_path_with_namespace) { "#{project.namespace.full_path}/foo" }
subject(:event_store) { described_class.new(project, old_path: old_path, old_path_with_namespace: old_path_with_namespace) } subject { described_class.new(project, old_path: old_path, old_path_with_namespace: old_path_with_namespace) }
describe '#create' do describe '#create' do
it 'does not create an event when not running on a primary node' do it_behaves_like 'a Geo event store', Geo::RepositoryRenamedEvent
allow(Gitlab::Geo).to receive(:primary?) { false }
expect { event_store.create }.not_to change(Geo::RepositoryRenamedEvent, :count)
end
context 'when running on a primary node' do context 'when running on a primary node' do
before do before do
allow(Gitlab::Geo).to receive(:primary?) { true } stub_primary_node
end
it 'does not create an event when there are no secondary nodes' do
allow(Gitlab::Geo).to receive(:secondary_nodes) { [] }
expect { subject.create }.not_to change(Geo::RepositoryRenamedEvent, :count)
end
it 'creates a renamed event' do
expect { event_store.create }.to change(Geo::RepositoryRenamedEvent, :count).by(1)
end end
it 'tracks old and new paths for project repositories' do it 'tracks old and new paths for project repositories' do
event_store.create subject.create
event = Geo::RepositoryRenamedEvent.last expect(Geo::RepositoryRenamedEvent.last).to have_attributes(
repository_storage_name: project.repository_storage,
expect(event.repository_storage_name).to eq(project.repository_storage) old_path_with_namespace: old_path_with_namespace,
expect(event.old_path_with_namespace).to eq(old_path_with_namespace) new_path_with_namespace: project.disk_path,
expect(event.new_path_with_namespace).to eq(project.disk_path) old_wiki_path_with_namespace: "#{old_path_with_namespace}.wiki",
expect(event.old_wiki_path_with_namespace).to eq("#{old_path_with_namespace}.wiki") new_wiki_path_with_namespace: project.wiki.disk_path,
expect(event.new_wiki_path_with_namespace).to eq(project.wiki.disk_path) old_path: old_path,
expect(event.old_path).to eq(old_path) new_path: project.path
expect(event.new_path).to eq(project.path) )
end end
end end
end end
......
# frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
describe Geo::RepositoryUpdatedEventStore do describe Geo::RepositoryUpdatedEventStore do
include EE::GeoHelpers
set(:project) { create(:project, :repository) } set(:project) { create(:project, :repository) }
set(:secondary_node) { create(:geo_node) } set(:secondary_node) { create(:geo_node) }
let(:blankrev) { Gitlab::Git::BLANK_SHA } let(:blankrev) { Gitlab::Git::BLANK_SHA }
let(:refs) { ['refs/heads/tést', 'refs/tags/tag'] } let(:refs) { ['refs/heads/tést', 'refs/tags/tag'] }
...@@ -13,38 +18,18 @@ describe Geo::RepositoryUpdatedEventStore do ...@@ -13,38 +18,18 @@ describe Geo::RepositoryUpdatedEventStore do
] ]
end end
describe '#create' do subject { described_class.new(project, refs: refs, changes: changes) }
it 'does not create a push event when not running on a primary node' do
allow(Gitlab::Geo).to receive(:primary?) { false }
subject = described_class.new(project, refs: refs, changes: changes)
expect { subject.create }.not_to change(Geo::RepositoryUpdatedEvent, :count) describe '#create' do
end it_behaves_like 'a Geo event store', Geo::RepositoryUpdatedEvent
context 'when running on a primary node' do context 'when running on a primary node' do
before do before do
allow(Gitlab::Geo).to receive(:primary?) { true } stub_primary_node
end
it 'does not create an event when there are no secondary nodes' do
allow(Gitlab::Geo).to receive(:secondary_nodes) { [] }
subject = described_class.new(project, refs: refs, changes: changes)
expect { subject.create }.not_to change(Geo::RepositoryUpdatedEvent, :count)
end
it 'creates a push event' do
subject = described_class.new(project, refs: refs, changes: changes)
expect { subject.create }.to change(Geo::RepositoryUpdatedEvent, :count).by(1)
end end
context 'when repository is being updated' do context 'when repository is being updated' do
it 'does not track ref name when post-receive event affect multiple refs' do it 'does not track ref name when post-receive event affect multiple refs' do
subject = described_class.new(project, refs: refs, changes: changes)
subject.create subject.create
expect(Geo::RepositoryUpdatedEvent.last.ref).to be_nil expect(Geo::RepositoryUpdatedEvent.last.ref).to be_nil
...@@ -61,16 +46,12 @@ describe Geo::RepositoryUpdatedEventStore do ...@@ -61,16 +46,12 @@ describe Geo::RepositoryUpdatedEventStore do
end end
it 'tracks number of branches post-receive event affects' do it 'tracks number of branches post-receive event affects' do
subject = described_class.new(project, refs: refs, changes: changes)
subject.create subject.create
expect(Geo::RepositoryUpdatedEvent.last.branches_affected).to eq 1 expect(Geo::RepositoryUpdatedEvent.last.branches_affected).to eq 1
end end
it 'tracks number of tags post-receive event affects' do it 'tracks number of tags post-receive event affects' do
subject = described_class.new(project, refs: refs, changes: changes)
subject.create subject.create
expect(Geo::RepositoryUpdatedEvent.last.tags_affected).to eq 1 expect(Geo::RepositoryUpdatedEvent.last.tags_affected).to eq 1
...@@ -82,7 +63,6 @@ describe Geo::RepositoryUpdatedEventStore do ...@@ -82,7 +63,6 @@ describe Geo::RepositoryUpdatedEventStore do
{ before: '123456', after: '789012', ref: 'refs/heads/tést' }, { before: '123456', after: '789012', ref: 'refs/heads/tést' },
{ before: blankrev, after: '210987', ref: 'refs/heads/feature' } { before: blankrev, after: '210987', ref: 'refs/heads/feature' }
] ]
subject = described_class.new(project, refs: refs, changes: changes) subject = described_class.new(project, refs: refs, changes: changes)
subject.create subject.create
...@@ -110,13 +90,13 @@ describe Geo::RepositoryUpdatedEventStore do ...@@ -110,13 +90,13 @@ describe Geo::RepositoryUpdatedEventStore do
subject.create subject.create
push_event = Geo::RepositoryUpdatedEvent.last expect(Geo::RepositoryUpdatedEvent.last).to have_attributes(
ref: be_nil,
expect(push_event.ref).to be_nil branches_affected: be_zero,
expect(push_event.branches_affected).to be_zero tags_affected: be_zero,
expect(push_event.tags_affected).to be_zero new_branch: false,
expect(push_event.new_branch).to eq false remove_branch: false
expect(push_event.remove_branch).to eq false )
end end
end end
end end
......
# frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
describe Geo::UploadDeletedEventStore do describe Geo::UploadDeletedEventStore do
include EE::GeoHelpers
set(:secondary_node) { create(:geo_node) } set(:secondary_node) { create(:geo_node) }
let(:upload) { create(:upload) } let(:upload) { create(:upload) }
subject(:event_store) { described_class.new(upload) } subject { described_class.new(upload) }
describe '#create' do describe '#create' do
it 'does not create an event when not running on a primary node' do it_behaves_like 'a Geo event store', Geo::UploadDeletedEvent
allow(Gitlab::Geo).to receive(:primary?) { false }
expect { event_store.create }.not_to change(Geo::UploadDeletedEvent, :count)
end
context 'when running on a primary node' do context 'when running on a primary node' do
before do before do
allow(Gitlab::Geo).to receive(:primary?) { true } stub_primary_node
end
it 'does not create an event when there are no secondary nodes' do
allow(Gitlab::Geo).to receive(:secondary_nodes) { [] }
expect { event_store.create }.not_to change(Geo::UploadDeletedEvent, :count)
end
it 'creates an upload deleted event' do
expect { event_store.create }.to change(Geo::UploadDeletedEvent, :count).by(1)
end end
it 'does not create an event when the upload does not use local storage' do it 'does not create an event when the upload does not use local storage' do
allow(upload).to receive(:local?).and_return(false) allow(upload).to receive(:local?).and_return(false)
expect { event_store.create }.not_to change(Geo::UploadDeletedEvent, :count) expect { subject.create }.not_to change(Geo::UploadDeletedEvent, :count)
end end
it 'tracks upload attributes' do it 'tracks upload attributes' do
event_store.create subject.create
event = Geo::UploadDeletedEvent.last
expect(event).to have_attributes( expect(Geo::UploadDeletedEvent.last).to have_attributes(
upload_id: upload.id, upload_id: upload.id,
file_path: upload.path, file_path: upload.path,
model_id: upload.model_id, model_id: upload.model_id,
......
# frozen_string_literal: true
shared_examples_for 'a Geo event store' do |event_class|
context 'running on a secondary node' do
before do
stub_secondary_node
end
it 'does not create an event ' do
expect { subject.create }.not_to change(event_class, :count)
end
end
context 'when running on a primary node' do
before do
stub_primary_node
end
it 'does not create an event if there are no secondary nodes' do
allow(Gitlab::Geo).to receive(:secondary_nodes) { [] }
expect { subject.create }.not_to change(event_class, :count)
end
it 'creates an event' do
expect { subject.create }.to change(event_class, :count).by(1)
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