2019-04-15 06:17:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-02-15 06:16:12 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-03 14:08:28 -04:00
|
|
|
RSpec.describe Projects::RunnersController do
|
2017-02-15 06:16:12 -05:00
|
|
|
let(:user) { create(:user) }
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project) }
|
2018-05-23 07:23:49 -04:00
|
|
|
let(:runner) { create(:ci_runner, :project, projects: [project]) }
|
2017-02-15 06:16:12 -05:00
|
|
|
|
|
|
|
let(:params) do
|
|
|
|
{
|
|
|
|
namespace_id: project.namespace,
|
|
|
|
project_id: project,
|
|
|
|
id: runner
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
2017-02-15 06:16:12 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#update' do
|
|
|
|
it 'updates the runner and ticks the queue' do
|
|
|
|
new_desc = runner.description.swapcase
|
|
|
|
|
2017-02-15 07:21:51 -05:00
|
|
|
expect do
|
2018-12-17 17:52:17 -05:00
|
|
|
post :update, params: params.merge(runner: { description: new_desc } )
|
2017-02-15 07:21:51 -05:00
|
|
|
end.to change { runner.ensure_runner_queue_value }
|
2017-02-15 06:16:12 -05:00
|
|
|
|
|
|
|
runner.reload
|
|
|
|
|
2020-01-28 07:08:44 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
2017-02-15 06:16:12 -05:00
|
|
|
expect(runner.description).to eq(new_desc)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#destroy' do
|
|
|
|
it 'destroys the runner' do
|
2022-02-24 04:14:06 -05:00
|
|
|
expect_next_instance_of(Ci::Runners::UnregisterRunnerService, runner, user) do |service|
|
2022-02-14 07:14:02 -05:00
|
|
|
expect(service).to receive(:execute).once.and_call_original
|
|
|
|
end
|
|
|
|
|
2018-12-17 17:52:17 -05:00
|
|
|
delete :destroy, params: params
|
2017-02-15 06:16:12 -05:00
|
|
|
|
2020-01-28 07:08:44 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
2017-02-15 06:16:12 -05:00
|
|
|
expect(Ci::Runner.find_by(id: runner.id)).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#resume' do
|
|
|
|
it 'marks the runner as active and ticks the queue' do
|
2021-03-30 08:10:51 -04:00
|
|
|
runner.update!(active: false)
|
2017-02-15 06:16:12 -05:00
|
|
|
|
2017-02-15 07:21:51 -05:00
|
|
|
expect do
|
2018-12-17 17:52:17 -05:00
|
|
|
post :resume, params: params
|
2017-02-15 07:21:51 -05:00
|
|
|
end.to change { runner.ensure_runner_queue_value }
|
2017-02-15 06:16:12 -05:00
|
|
|
|
|
|
|
runner.reload
|
|
|
|
|
2020-01-28 07:08:44 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
2017-02-15 06:16:12 -05:00
|
|
|
expect(runner.active).to eq(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#pause' do
|
|
|
|
it 'marks the runner as inactive and ticks the queue' do
|
2021-03-30 08:10:51 -04:00
|
|
|
runner.update!(active: true)
|
2017-02-15 06:16:12 -05:00
|
|
|
|
2017-02-15 07:21:51 -05:00
|
|
|
expect do
|
2018-12-17 17:52:17 -05:00
|
|
|
post :pause, params: params
|
2017-02-15 07:21:51 -05:00
|
|
|
end.to change { runner.ensure_runner_queue_value }
|
2017-02-15 06:16:12 -05:00
|
|
|
|
|
|
|
runner.reload
|
|
|
|
|
2020-01-28 07:08:44 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
2017-02-15 06:16:12 -05:00
|
|
|
expect(runner.active).to eq(false)
|
|
|
|
end
|
|
|
|
end
|
2020-09-30 11:09:46 -04:00
|
|
|
|
|
|
|
describe '#toggle_shared_runners' do
|
|
|
|
let(:group) { create(:group) }
|
|
|
|
let(:project) { create(:project, group: group) }
|
|
|
|
|
2021-05-10 23:10:35 -04:00
|
|
|
it 'toggles shared_runners_enabled when the group allows shared runners' do
|
|
|
|
project.update!(shared_runners_enabled: true)
|
2020-09-30 11:09:46 -04:00
|
|
|
|
2021-05-10 23:10:35 -04:00
|
|
|
post :toggle_shared_runners, params: params
|
2020-09-30 11:09:46 -04:00
|
|
|
|
2021-05-10 23:10:35 -04:00
|
|
|
project.reload
|
2020-09-30 11:09:46 -04:00
|
|
|
|
2021-05-10 23:10:35 -04:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(project.shared_runners_enabled).to eq(false)
|
2020-09-30 11:09:46 -04:00
|
|
|
end
|
|
|
|
|
2021-05-10 23:10:35 -04:00
|
|
|
it 'toggles shared_runners_enabled when the group disallows shared runners but allows overrides' do
|
|
|
|
group.update!(shared_runners_enabled: false, allow_descendants_override_disabled_shared_runners: true)
|
|
|
|
project.update!(shared_runners_enabled: false)
|
2020-09-30 11:09:46 -04:00
|
|
|
|
2021-05-10 23:10:35 -04:00
|
|
|
post :toggle_shared_runners, params: params
|
2020-12-11 04:09:48 -05:00
|
|
|
|
2021-05-10 23:10:35 -04:00
|
|
|
project.reload
|
2020-12-11 04:09:48 -05:00
|
|
|
|
2021-05-10 23:10:35 -04:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(project.shared_runners_enabled).to eq(true)
|
|
|
|
end
|
2020-12-11 04:09:48 -05:00
|
|
|
|
2021-05-10 23:10:35 -04:00
|
|
|
it 'does not enable if the group disallows shared runners' do
|
|
|
|
group.update!(shared_runners_enabled: false, allow_descendants_override_disabled_shared_runners: false)
|
|
|
|
project.update!(shared_runners_enabled: false)
|
2020-12-11 04:09:48 -05:00
|
|
|
|
2021-05-10 23:10:35 -04:00
|
|
|
post :toggle_shared_runners, params: params
|
2020-12-11 04:09:48 -05:00
|
|
|
|
2021-05-10 23:10:35 -04:00
|
|
|
project.reload
|
2020-12-11 04:09:48 -05:00
|
|
|
|
2021-05-10 23:10:35 -04:00
|
|
|
expect(response).to have_gitlab_http_status(:unauthorized)
|
|
|
|
expect(project.shared_runners_enabled).to eq(false)
|
2021-06-18 11:10:16 -04:00
|
|
|
expect(json_response['error']).to eq('Shared runners enabled cannot be enabled because parent group does not allow it')
|
2020-09-30 11:09:46 -04:00
|
|
|
end
|
|
|
|
end
|
2017-02-15 06:16:12 -05:00
|
|
|
end
|