debian-mirror-gitlab/spec/controllers/groups/runners_controller_spec.rb

240 lines
7.1 KiB
Ruby
Raw Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
2018-10-15 14:42:47 +05:30
require 'spec_helper'
2023-03-04 22:38:38 +05:30
RSpec.describe Groups::RunnersController, feature_category: :runner_fleet do
2021-11-11 11:23:49 +05:30
let_it_be(:user) { create(:user) }
let_it_be(:group) { create(:group) }
let_it_be(:project) { create(:project, group: group) }
let!(:runner) { create(:ci_runner, :group, groups: [group]) }
2022-11-25 23:54:43 +05:30
let!(:project_runner) { create(:ci_runner, :project, projects: [project]) }
let!(:instance_runner) { create(:ci_runner, :instance) }
2021-11-11 11:23:49 +05:30
2022-11-25 23:54:43 +05:30
let(:params_runner_project) { { group_id: group, id: project_runner } }
let(:params_runner_instance) { { group_id: group, id: instance_runner } }
2019-09-04 21:01:54 +05:30
let(:params) { { group_id: group, id: runner } }
2018-10-15 14:42:47 +05:30
before do
sign_in(user)
2019-09-04 21:01:54 +05:30
end
2022-06-21 17:19:12 +05:30
describe '#index', :snowplow do
2021-10-27 15:23:28 +05:30
context 'when user is owner' do
before do
group.add_owner(user)
end
it 'renders show with 200 status code' do
get :index, params: { group_id: group }
expect(response).to have_gitlab_http_status(:ok)
expect(response).to render_template(:index)
end
2022-06-21 17:19:12 +05:30
it 'tracks the event' do
get :index, params: { group_id: group }
expect_snowplow_event(category: described_class.name, action: 'index', user: user, namespace: group)
end
2021-10-27 15:23:28 +05:30
end
context 'when user is not owner' do
before do
group.add_maintainer(user)
end
it 'renders a 404' do
get :index, params: { group_id: group }
expect(response).to have_gitlab_http_status(:not_found)
end
2022-06-21 17:19:12 +05:30
it 'does not track the event' do
get :index, params: { group_id: group }
expect_no_snowplow_event
end
2021-10-27 15:23:28 +05:30
end
end
2019-09-04 21:01:54 +05:30
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-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:ok)
2019-09-04 21:01:54 +05:30
expect(response).to render_template(:show)
end
2020-07-28 23:09:34 +05:30
2022-11-25 23:54:43 +05:30
it 'renders show with 200 status code instance runner' do
get :show, params: { group_id: group, id: instance_runner }
expect(response).to have_gitlab_http_status(:ok)
expect(response).to render_template(:show)
end
2020-07-28 23:09:34 +05:30
it 'renders show with 200 status code project runner' do
2022-11-25 23:54:43 +05:30
get :show, params: { group_id: group, id: project_runner }
2020-07-28 23:09:34 +05:30
expect(response).to have_gitlab_http_status(:ok)
expect(response).to render_template(:show)
end
2019-09-04 21:01:54 +05:30
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-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:not_found)
2019-09-04 21:01:54 +05:30
end
2020-07-28 23:09:34 +05:30
2022-11-25 23:54:43 +05:30
it 'renders a 404 instance runner' do
get :show, params: { group_id: group, id: instance_runner }
expect(response).to have_gitlab_http_status(:not_found)
end
2020-07-28 23:09:34 +05:30
it 'renders a 404 project runner' do
2022-11-25 23:54:43 +05:30
get :show, params: { group_id: group, id: project_runner }
2020-07-28 23:09:34 +05:30
expect(response).to have_gitlab_http_status(:not_found)
end
2019-09-04 21:01:54 +05:30
end
end
describe '#edit' do
context 'when user is owner' do
before do
group.add_owner(user)
end
2022-11-25 23:54:43 +05:30
it 'renders edit with 200 status code' do
2019-09-04 21:01:54 +05:30
get :edit, params: { group_id: group, id: runner }
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:ok)
2019-09-04 21:01:54 +05:30
expect(response).to render_template(:edit)
end
2020-07-28 23:09:34 +05:30
2022-11-25 23:54:43 +05:30
it 'renders a 404 instance runner' do
get :edit, params: { group_id: group, id: instance_runner }
expect(response).to have_gitlab_http_status(:not_found)
end
it 'renders edit with 200 status code project runner' do
get :edit, params: { group_id: group, id: project_runner }
2020-07-28 23:09:34 +05:30
expect(response).to have_gitlab_http_status(:ok)
expect(response).to render_template(:edit)
end
2019-09-04 21:01:54 +05:30
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-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:not_found)
2019-09-04 21:01:54 +05:30
end
2020-07-28 23:09:34 +05:30
it 'renders a 404 project runner' do
2022-11-25 23:54:43 +05:30
get :edit, params: { group_id: group, id: project_runner }
2020-07-28 23:09:34 +05:30
expect(response).to have_gitlab_http_status(:not_found)
end
2019-09-04 21:01:54 +05:30
end
2018-10-15 14:42:47 +05:30
end
describe '#update' do
2019-09-04 21:01:54 +05:30
context 'when user is an owner' do
before do
group.add_owner(user)
end
2018-10-15 14:42:47 +05:30
2019-09-04 21:01:54 +05:30
it 'updates the runner, ticks the queue, and redirects' do
new_desc = runner.description.swapcase
2018-10-15 14:42:47 +05:30
2019-09-04 21:01:54 +05:30
expect do
2023-01-13 00:05:48 +05:30
post :update, params: params.merge(runner: { description: new_desc })
2019-09-04 21:01:54 +05:30
end.to change { runner.ensure_runner_queue_value }
2018-10-15 14:42:47 +05:30
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:found)
2019-09-04 21:01:54 +05:30
expect(runner.reload.description).to eq(new_desc)
end
2020-07-28 23:09:34 +05:30
2022-11-25 23:54:43 +05:30
it 'does not update the instance runner' do
new_desc = instance_runner.description.swapcase
expect do
2023-01-13 00:05:48 +05:30
post :update, params: params_runner_instance.merge(runner: { description: new_desc })
2022-11-25 23:54:43 +05:30
end.to not_change { instance_runner.ensure_runner_queue_value }
.and not_change { instance_runner.description }
expect(response).to have_gitlab_http_status(:not_found)
end
2020-07-28 23:09:34 +05:30
it 'updates the project runner, ticks the queue, and redirects project runner' do
2022-11-25 23:54:43 +05:30
new_desc = project_runner.description.swapcase
2020-07-28 23:09:34 +05:30
expect do
2023-01-13 00:05:48 +05:30
post :update, params: params_runner_project.merge(runner: { description: new_desc })
2022-11-25 23:54:43 +05:30
end.to change { project_runner.ensure_runner_queue_value }
2020-07-28 23:09:34 +05:30
expect(response).to have_gitlab_http_status(:found)
2022-11-25 23:54:43 +05:30
expect(project_runner.reload.description).to eq(new_desc)
2020-07-28 23:09:34 +05:30
end
2019-09-04 21:01:54 +05:30
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
2023-01-13 00:05:48 +05:30
post :update, params: params.merge(runner: { description: old_desc.swapcase })
2019-09-04 21:01:54 +05:30
end.not_to change { runner.ensure_runner_queue_value }
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:not_found)
2019-09-04 21:01:54 +05:30
expect(runner.reload.description).to eq(old_desc)
end
2020-07-28 23:09:34 +05:30
2022-11-25 23:54:43 +05:30
it 'rejects the update and responds 404 instance runner' do
old_desc = instance_runner.description
expect do
2023-01-13 00:05:48 +05:30
post :update, params: params_runner_instance.merge(runner: { description: old_desc.swapcase })
2022-11-25 23:54:43 +05:30
end.not_to change { instance_runner.ensure_runner_queue_value }
expect(response).to have_gitlab_http_status(:not_found)
expect(instance_runner.reload.description).to eq(old_desc)
end
2020-07-28 23:09:34 +05:30
it 'rejects the update and responds 404 project runner' do
2022-11-25 23:54:43 +05:30
old_desc = project_runner.description
2020-07-28 23:09:34 +05:30
expect do
2023-01-13 00:05:48 +05:30
post :update, params: params_runner_project.merge(runner: { description: old_desc.swapcase })
2022-11-25 23:54:43 +05:30
end.not_to change { project_runner.ensure_runner_queue_value }
2020-07-28 23:09:34 +05:30
expect(response).to have_gitlab_http_status(:not_found)
2022-11-25 23:54:43 +05:30
expect(project_runner.reload.description).to eq(old_desc)
2020-07-28 23:09:34 +05:30
end
2018-10-15 14:42:47 +05:30
end
end
end