2020-03-13 15:44:24 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Ci::ResourceGroups::AssignResourceFromResourceGroupWorker do
|
2020-03-13 15:44:24 +05:30
|
|
|
let(:worker) { described_class.new }
|
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
it 'has the `until_executed` deduplicate strategy' do
|
|
|
|
expect(described_class.get_deduplicate_strategy).to eq(:until_executed)
|
|
|
|
end
|
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
it 'has an option to reschedule once if deduplicated' do
|
|
|
|
expect(described_class.get_deduplication_options).to include({ if_deduplicated: :reschedule_once })
|
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
describe '#perform' do
|
|
|
|
subject { worker.perform(resource_group_id) }
|
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
let(:resource_group) { create(:ci_resource_group) }
|
|
|
|
let(:resource_group_id) { resource_group.id }
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
include_examples 'an idempotent worker' do
|
|
|
|
let(:job_args) { [resource_group_id] }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when resource group exists' do
|
2020-03-13 15:44:24 +05:30
|
|
|
it 'executes AssignResourceFromResourceGroupService' do
|
2021-09-30 23:02:18 +05:30
|
|
|
expect_next_instances_of(Ci::ResourceGroups::AssignResourceFromResourceGroupService, 2, resource_group.project, nil) do |service|
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(service).to receive(:execute).with(resource_group)
|
|
|
|
end
|
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when build does not exist' do
|
2021-09-30 23:02:18 +05:30
|
|
|
let(:resource_group_id) { non_existing_record_id }
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
it 'does not execute AssignResourceFromResourceGroupService' do
|
|
|
|
expect(Ci::ResourceGroups::AssignResourceFromResourceGroupService).not_to receive(:new)
|
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|