Commit d67553d3 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Add tests and improve pending builds and project update

parent d321f552
......@@ -2,7 +2,7 @@
module Ci
class UpdatePendingBuildService
VALID_PARAMS = %i[instance_runners_enabled].freeze
VALID_PARAMS = %i[instance_runners_enabled namespace_traversal_ids].freeze
InvalidParamsError = Class.new(StandardError)
InvalidModelError = Class.new(StandardError)
......
......@@ -191,13 +191,23 @@ module Projects
.execute
end
def shared_runners_settings_toggled?
project.previous_changes.include?(:shared_runners_enabled)
end
def group_runners_settings_toggled?
return false unless project.ci_cd_settings.present?
project.ci_cd_settings.previous_changes.include?(:group_runners_enabled)
end
def runners_settings_toggled?
(%w[shared_runners_enabled group_runners_enabled] & project.previous_changes).any?
shared_runners_settings_toggled? || group_runners_settings_toggled?
end
def group_runner_traversal_ids
if project.group_runners_enabled?
project.namespace.traversal_ids
project.namespace.reset.traversal_ids
else
[]
end
......
......@@ -443,41 +443,61 @@ RSpec.describe Projects::UpdateService do
context 'when updating runners settings' do
let(:settings) do
{ instance_runners_enabled: true, namespace_traversal_ids: [] }
{ instance_runners_enabled: true, namespace_traversal_ids: [123] }
end
let!(:pending_build) do
create(:ci_pending_build, project: project, **settings)
end
context 'when project has shared runners enabled' do
let(:project) { create(:project, shared_runners_enabled: true) }
it 'updates builds queue when shared runners get disabled' do
expect { update_project(shared_runners_enabled: false) }
expect { update_project(project, admin, shared_runners_enabled: false) }
.to change { pending_build.reload.instance_runners_enabled }.to(false)
expect(pending_build.reload.instance_runners_enabled).to be false
end
end
context 'when project has shared runners disabled' do
let(:project) { create(:project, shared_runners_enabled: false) }
it 'updates builds queue when shared runners get enabled' do
expect { update_project(shared_runners_enabled: true) }
expect { update_project(project, admin, shared_runners_enabled: true) }
.to not_change { pending_build.reload.instance_runners_enabled }
expect(pending_build.reload.instance_runners_enabled).to be true
end
end
context 'when project has group runners enabled' do
let(:project) { create(:project, group_runners_enabled: true) }
before do
project.ci_cd_settings.update!(group_runners_enabled: true)
end
it 'updates builds queue when group runners get disabled' do
update_project(group_runners_enabled: false)
update_project(project, admin, group_runners_enabled: false)
expect(pending_build.reload.namespace_traversal_ids).to be_empty
end
end
it 'updates builds queue when group runners get enabled' do
update_project(group_runners_enabled: true)
context 'when project has group runners disabled' do
let(:project) { create(:project, :in_subgroup, group_runners_enabled: false) }
expect(pending_build.reload.namespace_traversal_ids).not_to be_empty
before do
project.ci_cd_settings.update!(group_runners_enabled: false)
end
def update_project(**params)
update_project(project, admin, **params)
it 'updates builds queue when group runners get enabled' do
update_project(project, admin, group_runners_enabled: true)
expect(pending_build.reload.namespace_traversal_ids).to include(project.namespace.id)
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