Add spec for Geo::RepositoryDeletedEventStore

parent e94e8216
......@@ -10,32 +10,22 @@ describe Projects::DestroyService, services: true do
let!(:wiki_path) { project.path_with_namespace + '.wiki' }
let!(:storage_name) { project.repository_storage }
let!(:storage_path) { project.repository_storage_path }
let!(:geo_node) { create(:geo_node, :primary, :current) }
subject { described_class.new(project, user, {}) }
before do
stub_container_registry_config(enabled: true)
stub_container_registry_tags(repository: :any, tags: [])
end
context 'Geo primary' do
it 'logs the event' do
# Run sidekiq immediatly to check that renamed repository will be removed
Sidekiq::Testing.inline! { destroy_project(project, user, {}) }
event = Geo::RepositoryDeletedEvent.first
context 'when running on a primary node' do
let!(:geo_node) { create(:geo_node, :primary, :current) }
expect(Geo::EventLog.count).to eq(1)
expect(Geo::RepositoryDeletedEvent.count).to eq(1)
expect(event.project_id).to eq(project_id)
expect(event.deleted_path).to eq(project_path)
expect(event.deleted_wiki_path).to eq(wiki_path)
expect(event.deleted_project_name).to eq(project_name)
expect(event.repository_storage_name).to eq(storage_name)
expect(event.repository_storage_path).to eq(storage_path)
it 'logs an event to the Geo event log' do
# Run sidekiq immediatly to check that renamed repository will be removed
Sidekiq::Testing.inline! do
expect { subject.execute }.to change(Geo::RepositoryDeletedEvent, :count).by(1)
end
end
def destroy_project(project, user, params = {})
described_class.new(project, user, params).execute
end
end
require 'spec_helper'
describe Geo::RepositoryDeletedEventStore, services: true do
let(:project) { create(:empty_project, path: 'bar') }
let!(:project_id) { project.id }
let!(:project_name) { project.name }
let!(:repo_path) { project.full_path }
let!(:wiki_path) { "#{project.full_path}.wiki" }
let!(:storage_name) { project.repository_storage }
let!(:storage_path) { project.repository_storage_path }
subject { described_class.new(project, repo_path: repo_path, wiki_path: wiki_path) }
describe '#create' do
it 'does not create an event when not running on a primary node' do
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
before do
allow(Gitlab::Geo).to receive(:primary?) { true }
end
it 'creates a deleted event' do
expect { subject.create }.to change(Geo::RepositoryDeletedEvent, :count).by(1)
end
it 'tracks information for the deleted project' do
subject.create
event = Geo::RepositoryDeletedEvent.last
expect(event.project_id).to eq(project_id)
expect(event.deleted_path).to eq(repo_path)
expect(event.deleted_wiki_path).to eq(wiki_path)
expect(event.deleted_project_name).to eq(project_name)
expect(event.repository_storage_name).to eq(storage_name)
expect(event.repository_storage_path).to eq(storage_path)
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