2019-04-15 10:17:05 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-02-15 11:16:12 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-03 18:08:28 +00:00
|
|
|
RSpec.describe Projects::RunnersController do
|
2017-02-15 11:16:12 +00:00
|
|
|
let(:user) { create(:user) }
|
2017-08-02 19:55:11 +00:00
|
|
|
let(:project) { create(:project) }
|
2018-05-23 11:23:49 +00:00
|
|
|
let(:runner) { create(:ci_runner, :project, projects: [project]) }
|
2017-02-15 11:16:12 +00:00
|
|
|
|
|
|
|
let(:params) do
|
|
|
|
{
|
|
|
|
namespace_id: project.namespace,
|
|
|
|
project_id: project,
|
|
|
|
id: runner
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
2018-07-11 14:36:08 +00:00
|
|
|
project.add_maintainer(user)
|
2017-02-15 11:16:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#update' do
|
|
|
|
it 'updates the runner and ticks the queue' do
|
|
|
|
new_desc = runner.description.swapcase
|
|
|
|
|
2017-02-15 12:21:51 +00:00
|
|
|
expect do
|
2018-12-17 22:52:17 +00:00
|
|
|
post :update, params: params.merge(runner: { description: new_desc } )
|
2017-02-15 12:21:51 +00:00
|
|
|
end.to change { runner.ensure_runner_queue_value }
|
2017-02-15 11:16:12 +00:00
|
|
|
|
|
|
|
runner.reload
|
|
|
|
|
2020-01-28 12:08:44 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
2017-02-15 11:16:12 +00:00
|
|
|
expect(runner.description).to eq(new_desc)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#destroy' do
|
|
|
|
it 'destroys the runner' do
|
2018-12-17 22:52:17 +00:00
|
|
|
delete :destroy, params: params
|
2017-02-15 11:16:12 +00:00
|
|
|
|
2020-01-28 12:08:44 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
2017-02-15 11:16:12 +00: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 12:10:51 +00:00
|
|
|
runner.update!(active: false)
|
2017-02-15 11:16:12 +00:00
|
|
|
|
2017-02-15 12:21:51 +00:00
|
|
|
expect do
|
2018-12-17 22:52:17 +00:00
|
|
|
post :resume, params: params
|
2017-02-15 12:21:51 +00:00
|
|
|
end.to change { runner.ensure_runner_queue_value }
|
2017-02-15 11:16:12 +00:00
|
|
|
|
|
|
|
runner.reload
|
|
|
|
|
2020-01-28 12:08:44 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
2017-02-15 11:16:12 +00: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 12:10:51 +00:00
|
|
|
runner.update!(active: true)
|
2017-02-15 11:16:12 +00:00
|
|
|
|
2017-02-15 12:21:51 +00:00
|
|
|
expect do
|
2018-12-17 22:52:17 +00:00
|
|
|
post :pause, params: params
|
2017-02-15 12:21:51 +00:00
|
|
|
end.to change { runner.ensure_runner_queue_value }
|
2017-02-15 11:16:12 +00:00
|
|
|
|
|
|
|
runner.reload
|
|
|
|
|
2020-01-28 12:08:44 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
2017-02-15 11:16:12 +00:00
|
|
|
expect(runner.active).to eq(false)
|
|
|
|
end
|
|
|
|
end
|
2020-09-30 15:09:46 +00:00
|
|
|
|
|
|
|
describe '#toggle_shared_runners' do
|
|
|
|
let(:group) { create(:group) }
|
|
|
|
let(:project) { create(:project, group: group) }
|
|
|
|
|
2021-05-11 03:10:35 +00:00
|
|
|
it 'toggles shared_runners_enabled when the group allows shared runners' do
|
|
|
|
project.update!(shared_runners_enabled: true)
|
2020-09-30 15:09:46 +00:00
|
|
|
|
2021-05-11 03:10:35 +00:00
|
|
|
post :toggle_shared_runners, params: params
|
2020-09-30 15:09:46 +00:00
|
|
|
|
2021-05-11 03:10:35 +00:00
|
|
|
project.reload
|
2020-09-30 15:09:46 +00:00
|
|
|
|
2021-05-11 03:10:35 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(project.shared_runners_enabled).to eq(false)
|
2020-09-30 15:09:46 +00:00
|
|
|
end
|
|
|
|
|
2021-05-11 03:10:35 +00: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 15:09:46 +00:00
|
|
|
|
2021-05-11 03:10:35 +00:00
|
|
|
post :toggle_shared_runners, params: params
|
2020-12-11 09:09:48 +00:00
|
|
|
|
2021-05-11 03:10:35 +00:00
|
|
|
project.reload
|
2020-12-11 09:09:48 +00:00
|
|
|
|
2021-05-11 03:10:35 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(project.shared_runners_enabled).to eq(true)
|
|
|
|
end
|
2020-12-11 09:09:48 +00:00
|
|
|
|
2021-05-11 03:10:35 +00: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 09:09:48 +00:00
|
|
|
|
2021-05-11 03:10:35 +00:00
|
|
|
post :toggle_shared_runners, params: params
|
2020-12-11 09:09:48 +00:00
|
|
|
|
2021-05-11 03:10:35 +00:00
|
|
|
project.reload
|
2020-12-11 09:09:48 +00:00
|
|
|
|
2021-05-11 03:10:35 +00:00
|
|
|
expect(response).to have_gitlab_http_status(:unauthorized)
|
|
|
|
expect(project.shared_runners_enabled).to eq(false)
|
2021-06-18 15:10:16 +00:00
|
|
|
expect(json_response['error']).to eq('Shared runners enabled cannot be enabled because parent group does not allow it')
|
2020-09-30 15:09:46 +00:00
|
|
|
end
|
|
|
|
end
|
2017-02-15 11:16:12 +00:00
|
|
|
end
|