2021-11-11 11:23:49 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
RSpec.describe Ci::UpdatePendingBuildService, feature_category: :continuous_integration do
|
2021-11-18 22:05:49 +05:30
|
|
|
let_it_be(:group) { create(:group) }
|
|
|
|
let_it_be(:project) { create(:project, namespace: group) }
|
|
|
|
let_it_be_with_reload(:pending_build_1) { create(:ci_pending_build, project: project, instance_runners_enabled: false) }
|
|
|
|
let_it_be_with_reload(:pending_build_2) { create(:ci_pending_build, project: project, instance_runners_enabled: true) }
|
|
|
|
let_it_be(:update_params) { { instance_runners_enabled: true } }
|
|
|
|
|
|
|
|
let(:service) { described_class.new(model, update_params) }
|
2021-11-11 11:23:49 +05:30
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
describe '#execute' do
|
|
|
|
subject(:update_pending_builds) { service.execute }
|
2021-11-11 11:23:49 +05:30
|
|
|
|
|
|
|
context 'validations' do
|
|
|
|
context 'when model is invalid' do
|
|
|
|
let(:model) { pending_build_1 }
|
|
|
|
|
|
|
|
it 'raises an error' do
|
2021-11-18 22:05:49 +05:30
|
|
|
expect { update_pending_builds }.to raise_error(described_class::InvalidModelError)
|
2021-11-11 11:23:49 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when params is invalid' do
|
|
|
|
let(:model) { group }
|
|
|
|
let(:update_params) { { minutes_exceeded: true } }
|
|
|
|
|
|
|
|
it 'raises an error' do
|
2021-11-18 22:05:49 +05:30
|
|
|
expect { update_pending_builds }.to raise_error(described_class::InvalidParamsError)
|
2021-11-11 11:23:49 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when model is a group with pending builds' do
|
|
|
|
let(:model) { group }
|
|
|
|
|
|
|
|
it 'updates all pending builds', :aggregate_failures do
|
2021-11-18 22:05:49 +05:30
|
|
|
update_pending_builds
|
2021-11-11 11:23:49 +05:30
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
expect(pending_build_1.instance_runners_enabled).to be_truthy
|
|
|
|
expect(pending_build_2.instance_runners_enabled).to be_truthy
|
2021-11-11 11:23:49 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when model is a project with pending builds' do
|
|
|
|
let(:model) { project }
|
|
|
|
|
|
|
|
it 'updates all pending builds', :aggregate_failures do
|
2021-11-18 22:05:49 +05:30
|
|
|
update_pending_builds
|
2021-11-11 11:23:49 +05:30
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
expect(pending_build_1.instance_runners_enabled).to be_truthy
|
|
|
|
expect(pending_build_2.instance_runners_enabled).to be_truthy
|
2021-11-11 11:23:49 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|