2019-03-30 07:15:48 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-08-29 07:56:52 +00:00
|
|
|
require 'spec_helper'
|
2018-05-03 12:55:14 +00:00
|
|
|
|
2020-06-26 09:08:59 +00:00
|
|
|
RSpec.describe RepositoryRemoveRemoteWorker do
|
2018-06-28 18:51:36 +00:00
|
|
|
include ExclusiveLeaseHelpers
|
2018-10-02 03:21:46 +00:00
|
|
|
include GitHelpers
|
2018-05-03 12:55:14 +00:00
|
|
|
|
|
|
|
describe '#perform' do
|
|
|
|
let!(:project) { create(:project, :repository) }
|
2018-06-28 18:51:36 +00:00
|
|
|
let(:remote_name) { 'joe'}
|
|
|
|
let(:lease_key) { "remove_remote_#{project.id}_#{remote_name}" }
|
|
|
|
let(:lease_timeout) { RepositoryRemoveRemoteWorker::LEASE_TIMEOUT }
|
2018-05-03 12:55:14 +00:00
|
|
|
|
2018-06-28 18:51:36 +00:00
|
|
|
it 'returns nil when project does not exist' do
|
|
|
|
expect(subject.perform(-1, 'remote_name')).to be_nil
|
2018-05-03 12:55:14 +00:00
|
|
|
end
|
|
|
|
|
2018-06-28 18:51:36 +00:00
|
|
|
context 'when project exists' do
|
2018-05-03 12:55:14 +00:00
|
|
|
before do
|
2018-06-28 18:51:36 +00:00
|
|
|
allow(Project)
|
|
|
|
.to receive(:find_by)
|
|
|
|
.with(id: project.id)
|
|
|
|
.and_return(project)
|
2018-05-03 12:55:14 +00:00
|
|
|
end
|
|
|
|
|
2021-07-26 09:09:00 +00:00
|
|
|
it 'does nothing when cannot obtain lease' do
|
2018-06-28 18:51:36 +00:00
|
|
|
stub_exclusive_lease_taken(lease_key, timeout: lease_timeout)
|
|
|
|
|
|
|
|
expect(project.repository)
|
|
|
|
.not_to receive(:remove_remote)
|
|
|
|
expect(subject)
|
2021-07-26 09:09:00 +00:00
|
|
|
.not_to receive(:log_error)
|
2018-05-03 12:55:14 +00:00
|
|
|
|
2018-06-28 18:51:36 +00:00
|
|
|
subject.perform(project.id, remote_name)
|
|
|
|
end
|
2018-05-03 12:55:14 +00:00
|
|
|
|
2021-07-26 09:09:00 +00:00
|
|
|
it 'does nothing when obtain a lease' do
|
2018-06-28 18:51:36 +00:00
|
|
|
stub_exclusive_lease(lease_key, timeout: lease_timeout)
|
2018-05-03 12:55:14 +00:00
|
|
|
|
2018-06-28 18:51:36 +00:00
|
|
|
expect(project.repository)
|
2021-07-26 09:09:00 +00:00
|
|
|
.not_to receive(:remove_remote)
|
2018-06-28 18:51:36 +00:00
|
|
|
|
|
|
|
subject.perform(project.id, remote_name)
|
2018-05-03 12:55:14 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|