2019-04-15 06:17:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-04-10 00:29:06 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-03 23:08:05 -04:00
|
|
|
RSpec.describe Groups::RunnersController do
|
2019-08-13 19:03:05 -04:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:group) { create(:group) }
|
2018-05-23 07:23:49 -04:00
|
|
|
let(:runner) { create(:ci_runner, :group, groups: [group]) }
|
2020-07-17 05:09:43 -04:00
|
|
|
let(:project) { create(:project, group: group) }
|
|
|
|
let(:runner_project) { create(:ci_runner, :project, projects: [project]) }
|
|
|
|
let(:params_runner_project) { { group_id: group, id: runner_project } }
|
2019-08-13 19:03:05 -04:00
|
|
|
let(:params) { { group_id: group, id: runner } }
|
2018-04-10 00:29:06 -04:00
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
2019-08-13 19:03:05 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#show' do
|
|
|
|
context 'when user is owner' do
|
|
|
|
before do
|
|
|
|
group.add_owner(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders show with 200 status code' do
|
|
|
|
get :show, params: { group_id: group, id: runner }
|
|
|
|
|
2020-02-06 04:09:06 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-08-13 19:03:05 -04:00
|
|
|
expect(response).to render_template(:show)
|
|
|
|
end
|
2020-07-17 05:09:43 -04:00
|
|
|
|
|
|
|
it 'renders show with 200 status code project runner' do
|
|
|
|
get :show, params: { group_id: group, id: runner_project }
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(response).to render_template(:show)
|
|
|
|
end
|
2019-08-13 19:03:05 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is not owner' do
|
|
|
|
before do
|
|
|
|
group.add_maintainer(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders a 404' do
|
|
|
|
get :show, params: { group_id: group, id: runner }
|
|
|
|
|
2020-02-06 04:09:06 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2019-08-13 19:03:05 -04:00
|
|
|
end
|
2020-07-17 05:09:43 -04:00
|
|
|
|
|
|
|
it 'renders a 404 project runner' do
|
|
|
|
get :show, params: { group_id: group, id: runner_project }
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
|
|
|
end
|
2019-08-13 19:03:05 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#edit' do
|
|
|
|
context 'when user is owner' do
|
|
|
|
before do
|
|
|
|
group.add_owner(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders show with 200 status code' do
|
|
|
|
get :edit, params: { group_id: group, id: runner }
|
|
|
|
|
2020-02-06 04:09:06 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-08-13 19:03:05 -04:00
|
|
|
expect(response).to render_template(:edit)
|
|
|
|
end
|
2020-07-17 05:09:43 -04:00
|
|
|
|
|
|
|
it 'renders show with 200 status code project runner' do
|
|
|
|
get :edit, params: { group_id: group, id: runner_project }
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(response).to render_template(:edit)
|
|
|
|
end
|
2019-08-13 19:03:05 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is not owner' do
|
|
|
|
before do
|
|
|
|
group.add_maintainer(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders a 404' do
|
|
|
|
get :edit, params: { group_id: group, id: runner }
|
|
|
|
|
2020-02-06 04:09:06 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2019-08-13 19:03:05 -04:00
|
|
|
end
|
2020-07-17 05:09:43 -04:00
|
|
|
|
|
|
|
it 'renders a 404 project runner' do
|
|
|
|
get :edit, params: { group_id: group, id: runner_project }
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
|
|
|
end
|
2019-08-13 19:03:05 -04:00
|
|
|
end
|
2018-04-10 00:29:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#update' do
|
2019-08-13 19:03:05 -04:00
|
|
|
context 'when user is an owner' do
|
|
|
|
before do
|
|
|
|
group.add_owner(user)
|
|
|
|
end
|
2018-04-10 00:29:06 -04:00
|
|
|
|
2019-08-13 19:03:05 -04:00
|
|
|
it 'updates the runner, ticks the queue, and redirects' do
|
|
|
|
new_desc = runner.description.swapcase
|
2018-04-10 00:29:06 -04:00
|
|
|
|
2019-08-13 19:03:05 -04:00
|
|
|
expect do
|
|
|
|
post :update, params: params.merge(runner: { description: new_desc } )
|
|
|
|
end.to change { runner.ensure_runner_queue_value }
|
2018-04-10 00:29:06 -04:00
|
|
|
|
2020-02-06 04:09:06 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
2019-08-13 19:03:05 -04:00
|
|
|
expect(runner.reload.description).to eq(new_desc)
|
|
|
|
end
|
2020-07-17 05:09:43 -04:00
|
|
|
|
|
|
|
it 'updates the project runner, ticks the queue, and redirects project runner' do
|
|
|
|
new_desc = runner_project.description.swapcase
|
|
|
|
|
|
|
|
expect do
|
|
|
|
post :update, params: params_runner_project.merge(runner: { description: new_desc } )
|
|
|
|
end.to change { runner_project.ensure_runner_queue_value }
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
|
|
|
expect(runner_project.reload.description).to eq(new_desc)
|
|
|
|
end
|
2019-08-13 19:03:05 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is not an owner' do
|
|
|
|
before do
|
|
|
|
group.add_maintainer(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'rejects the update and responds 404' do
|
|
|
|
old_desc = runner.description
|
|
|
|
|
|
|
|
expect do
|
|
|
|
post :update, params: params.merge(runner: { description: old_desc.swapcase } )
|
|
|
|
end.not_to change { runner.ensure_runner_queue_value }
|
|
|
|
|
2020-02-06 04:09:06 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2019-08-13 19:03:05 -04:00
|
|
|
expect(runner.reload.description).to eq(old_desc)
|
|
|
|
end
|
2020-07-17 05:09:43 -04:00
|
|
|
|
|
|
|
it 'rejects the update and responds 404 project runner' do
|
|
|
|
old_desc = runner_project.description
|
|
|
|
|
|
|
|
expect do
|
|
|
|
post :update, params: params_runner_project.merge(runner: { description: old_desc.swapcase } )
|
|
|
|
end.not_to change { runner_project.ensure_runner_queue_value }
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
|
|
|
expect(runner_project.reload.description).to eq(old_desc)
|
|
|
|
end
|
2018-04-10 00:29:06 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#destroy' do
|
2019-08-13 19:03:05 -04:00
|
|
|
context 'when user is an owner' do
|
|
|
|
before do
|
|
|
|
group.add_owner(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'destroys the runner and redirects' do
|
|
|
|
delete :destroy, params: params
|
|
|
|
|
2020-02-06 04:09:06 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
2019-08-13 19:03:05 -04:00
|
|
|
expect(Ci::Runner.find_by(id: runner.id)).to be_nil
|
|
|
|
end
|
2020-07-17 05:09:43 -04:00
|
|
|
|
|
|
|
it 'destroys the project runner and redirects' do
|
|
|
|
delete :destroy, params: params_runner_project
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
|
|
|
expect(Ci::Runner.find_by(id: runner_project.id)).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is an owner and runner in multiple projects' do
|
|
|
|
let(:project_2) { create(:project, group: group) }
|
|
|
|
let(:runner_project_2) { create(:ci_runner, :project, projects: [project, project_2]) }
|
|
|
|
let(:params_runner_project_2) { { group_id: group, id: runner_project_2 } }
|
|
|
|
|
|
|
|
before do
|
|
|
|
group.add_owner(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not destroy the project runner' do
|
|
|
|
delete :destroy, params: params_runner_project_2
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
|
|
|
expect(flash[:alert]).to eq('Runner was not deleted because it is assigned to multiple projects.')
|
|
|
|
expect(Ci::Runner.find_by(id: runner_project_2.id)).to be_present
|
|
|
|
end
|
2019-08-13 19:03:05 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is not an owner' do
|
|
|
|
before do
|
|
|
|
group.add_maintainer(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'responds 404 and does not destroy the runner' do
|
|
|
|
delete :destroy, params: params
|
2018-04-10 00:29:06 -04:00
|
|
|
|
2020-02-06 04:09:06 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2019-08-13 19:03:05 -04:00
|
|
|
expect(Ci::Runner.find_by(id: runner.id)).to be_present
|
|
|
|
end
|
2020-07-17 05:09:43 -04:00
|
|
|
|
|
|
|
it 'responds 404 and does not destroy the project runner' do
|
|
|
|
delete :destroy, params: params_runner_project
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
|
|
|
expect(Ci::Runner.find_by(id: runner_project.id)).to be_present
|
|
|
|
end
|
2018-04-10 00:29:06 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#resume' do
|
2019-08-13 19:03:05 -04:00
|
|
|
context 'when user is an owner' do
|
|
|
|
before do
|
|
|
|
group.add_owner(user)
|
|
|
|
end
|
2018-04-10 00:29:06 -04:00
|
|
|
|
2019-08-13 19:03:05 -04:00
|
|
|
it 'marks the runner as active, ticks the queue, and redirects' do
|
2021-04-04 02:09:06 -04:00
|
|
|
runner.update!(active: false)
|
2018-04-10 00:29:06 -04:00
|
|
|
|
2019-08-13 19:03:05 -04:00
|
|
|
expect do
|
|
|
|
post :resume, params: params
|
|
|
|
end.to change { runner.ensure_runner_queue_value }
|
2018-04-10 00:29:06 -04:00
|
|
|
|
2020-02-06 04:09:06 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
2019-08-13 19:03:05 -04:00
|
|
|
expect(runner.reload.active).to eq(true)
|
|
|
|
end
|
2020-07-17 05:09:43 -04:00
|
|
|
|
|
|
|
it 'marks the project runner as active, ticks the queue, and redirects' do
|
2021-04-04 02:09:06 -04:00
|
|
|
runner_project.update!(active: false)
|
2020-07-17 05:09:43 -04:00
|
|
|
|
|
|
|
expect do
|
|
|
|
post :resume, params: params_runner_project
|
|
|
|
end.to change { runner_project.ensure_runner_queue_value }
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
|
|
|
expect(runner_project.reload.active).to eq(true)
|
|
|
|
end
|
2019-08-13 19:03:05 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is not an owner' do
|
|
|
|
before do
|
|
|
|
group.add_maintainer(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'responds 404 and does not activate the runner' do
|
2021-04-04 02:09:06 -04:00
|
|
|
runner.update!(active: false)
|
2019-08-13 19:03:05 -04:00
|
|
|
|
|
|
|
expect do
|
|
|
|
post :resume, params: params
|
|
|
|
end.not_to change { runner.ensure_runner_queue_value }
|
|
|
|
|
2020-02-06 04:09:06 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2019-08-13 19:03:05 -04:00
|
|
|
expect(runner.reload.active).to eq(false)
|
|
|
|
end
|
2020-07-17 05:09:43 -04:00
|
|
|
|
|
|
|
it 'responds 404 and does not activate the project runner' do
|
2021-04-04 02:09:06 -04:00
|
|
|
runner_project.update!(active: false)
|
2020-07-17 05:09:43 -04:00
|
|
|
|
|
|
|
expect do
|
|
|
|
post :resume, params: params_runner_project
|
|
|
|
end.not_to change { runner_project.ensure_runner_queue_value }
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
|
|
|
expect(runner_project.reload.active).to eq(false)
|
|
|
|
end
|
2018-04-10 00:29:06 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#pause' do
|
2019-08-13 19:03:05 -04:00
|
|
|
context 'when user is an owner' do
|
|
|
|
before do
|
|
|
|
group.add_owner(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'marks the runner as inactive, ticks the queue, and redirects' do
|
2021-04-04 02:09:06 -04:00
|
|
|
runner.update!(active: true)
|
2019-08-13 19:03:05 -04:00
|
|
|
|
|
|
|
expect do
|
|
|
|
post :pause, params: params
|
|
|
|
end.to change { runner.ensure_runner_queue_value }
|
|
|
|
|
2020-02-06 04:09:06 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
2019-08-13 19:03:05 -04:00
|
|
|
expect(runner.reload.active).to eq(false)
|
|
|
|
end
|
2020-07-17 05:09:43 -04:00
|
|
|
|
|
|
|
it 'marks the project runner as inactive, ticks the queue, and redirects' do
|
2021-04-04 02:09:06 -04:00
|
|
|
runner_project.update!(active: true)
|
2020-07-17 05:09:43 -04:00
|
|
|
|
|
|
|
expect do
|
|
|
|
post :pause, params: params_runner_project
|
|
|
|
end.to change { runner_project.ensure_runner_queue_value }
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
|
|
|
expect(runner_project.reload.active).to eq(false)
|
|
|
|
end
|
2019-08-13 19:03:05 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is not an owner' do
|
|
|
|
before do
|
2021-05-05 17:09:59 -04:00
|
|
|
# Disable limit checking
|
|
|
|
allow(runner).to receive(:runner_scope).and_return(nil)
|
|
|
|
|
2019-08-13 19:03:05 -04:00
|
|
|
group.add_maintainer(user)
|
|
|
|
end
|
2018-04-10 00:29:06 -04:00
|
|
|
|
2019-08-13 19:03:05 -04:00
|
|
|
it 'responds 404 and does not update the runner or queue' do
|
2021-04-04 02:09:06 -04:00
|
|
|
runner.update!(active: true)
|
2018-04-10 00:29:06 -04:00
|
|
|
|
2019-08-13 19:03:05 -04:00
|
|
|
expect do
|
|
|
|
post :pause, params: params
|
|
|
|
end.not_to change { runner.ensure_runner_queue_value }
|
2018-04-10 00:29:06 -04:00
|
|
|
|
2020-02-06 04:09:06 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2019-08-13 19:03:05 -04:00
|
|
|
expect(runner.reload.active).to eq(true)
|
|
|
|
end
|
2020-07-17 05:09:43 -04:00
|
|
|
|
|
|
|
it 'responds 404 and does not update the project runner or queue' do
|
2021-04-04 02:09:06 -04:00
|
|
|
runner_project.update!(active: true)
|
2020-07-17 05:09:43 -04:00
|
|
|
|
|
|
|
expect do
|
|
|
|
post :pause, params: params
|
|
|
|
end.not_to change { runner_project.ensure_runner_queue_value }
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
|
|
|
expect(runner_project.reload.active).to eq(true)
|
|
|
|
end
|
2018-04-10 00:29:06 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|