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

185 lines
5 KiB
Ruby
Raw Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require 'spec_helper'
2023-03-04 22:38:38 +05:30
RSpec.describe Admin::RunnersController, feature_category: :runner_fleet do
2020-03-13 15:44:24 +05:30
let_it_be(:runner) { create(:ci_runner) }
2022-04-04 11:22:00 +05:30
let_it_be(:user) { create(:admin) }
2017-08-17 22:00:37 +05:30
before do
2022-04-04 11:22:00 +05:30
sign_in(user)
2017-08-17 22:00:37 +05:30
end
describe '#index' do
2019-07-07 11:18:12 +05:30
render_views
2021-12-11 22:18:48 +05:30
before do
2017-08-17 22:00:37 +05:30
get :index
2021-12-11 22:18:48 +05:30
end
2017-08-17 22:00:37 +05:30
2021-12-11 22:18:48 +05:30
it 'renders index template' do
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:ok)
2021-10-27 15:23:28 +05:30
expect(response).to render_template(:index)
2021-06-08 01:23:25 +05:30
end
2017-08-17 22:00:37 +05:30
end
describe '#show' do
2020-03-13 15:44:24 +05:30
render_views
2022-03-02 08:16:31 +05:30
it 'shows a runner show page' do
get :show, params: { id: runner.id }
expect(response).to have_gitlab_http_status(:ok)
expect(response).to render_template(:show)
end
end
2023-04-23 21:23:45 +05:30
describe '#new' do
2023-05-27 22:25:52 +05:30
it 'renders a :new template' do
get :new
expect(response).to have_gitlab_http_status(:ok)
expect(response).to render_template(:new)
end
context 'when create_runner_workflow_for_admin is disabled' do
2023-04-23 21:23:45 +05:30
before do
2023-05-27 22:25:52 +05:30
stub_feature_flags(create_runner_workflow_for_admin: false)
2023-04-23 21:23:45 +05:30
end
2023-05-27 22:25:52 +05:30
it 'returns :not_found' do
2023-04-23 21:23:45 +05:30
get :new
2023-05-27 22:25:52 +05:30
expect(response).to have_gitlab_http_status(:not_found)
end
end
end
describe '#register' do
subject(:register) { get :register, params: { id: new_runner.id } }
context 'when runner can be registered after creation' do
let_it_be(:new_runner) { create(:ci_runner, registration_type: :authenticated_user) }
it 'renders a :register template' do
register
2023-04-23 21:23:45 +05:30
expect(response).to have_gitlab_http_status(:ok)
2023-05-27 22:25:52 +05:30
expect(response).to render_template(:register)
2023-04-23 21:23:45 +05:30
end
end
2023-05-27 22:25:52 +05:30
context 'when runner cannot be registered after creation' do
let_it_be(:new_runner) { runner }
it 'returns :not_found' do
register
expect(response).to have_gitlab_http_status(:not_found)
end
end
context 'when create_runner_workflow_for_admin is disabled' do
let_it_be(:new_runner) { create(:ci_runner, registration_type: :authenticated_user) }
2023-04-23 21:23:45 +05:30
before do
2023-05-27 22:25:52 +05:30
stub_feature_flags(create_runner_workflow_for_admin: false)
2023-04-23 21:23:45 +05:30
end
it 'returns :not_found' do
2023-05-27 22:25:52 +05:30
register
2023-04-23 21:23:45 +05:30
expect(response).to have_gitlab_http_status(:not_found)
end
end
end
2022-03-02 08:16:31 +05:30
describe '#edit' do
render_views
2020-03-13 15:44:24 +05:30
let_it_be(:project) { create(:project) }
let_it_be(:project_two) { create(:project) }
2022-03-02 08:16:31 +05:30
it 'shows a runner edit page' do
get :edit, params: { id: runner.id }
2017-08-17 22:00:37 +05:30
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:ok)
2017-08-17 22:00:37 +05:30
end
it 'shows 404 for unknown runner' do
2022-03-02 08:16:31 +05:30
get :edit, params: { id: 0 }
2017-08-17 22:00:37 +05:30
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:not_found)
end
it 'avoids N+1 queries', :request_store do
2022-03-02 08:16:31 +05:30
get :edit, params: { id: runner.id }
2020-03-13 15:44:24 +05:30
2022-03-02 08:16:31 +05:30
control_count = ActiveRecord::QueryRecorder.new { get :edit, params: { id: runner.id } }.count
2020-03-13 15:44:24 +05:30
# There is one additional query looking up subject.group in ProjectPolicy for the
# needs_new_sso_session permission
2022-03-02 08:16:31 +05:30
expect { get :edit, params: { id: runner.id } }.not_to exceed_query_limit(control_count + 1)
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:ok)
2017-08-17 22:00:37 +05:30
end
end
describe '#update' do
2022-07-16 23:28:13 +05:30
let(:new_desc) { runner.description.swapcase }
let(:runner_params) { { id: runner.id, runner: { description: new_desc } } }
2017-08-17 22:00:37 +05:30
2022-07-16 23:28:13 +05:30
subject(:request) { post :update, params: runner_params }
2017-08-17 22:00:37 +05:30
2022-07-16 23:28:13 +05:30
context 'with update succeeding' do
before do
expect_next_instance_of(Ci::Runners::UpdateRunnerService, runner) do |service|
2022-10-11 01:57:18 +05:30
expect(service).to receive(:execute).with(anything).and_call_original
2022-07-16 23:28:13 +05:30
end
end
2017-08-17 22:00:37 +05:30
2022-07-16 23:28:13 +05:30
it 'updates the runner and ticks the queue' do
expect { request }.to change { runner.ensure_runner_queue_value }
runner.reload
expect(response).to have_gitlab_http_status(:found)
expect(runner.description).to eq(new_desc)
end
end
context 'with update failing' do
before do
expect_next_instance_of(Ci::Runners::UpdateRunnerService, runner) do |service|
2022-10-11 01:57:18 +05:30
expect(service).to receive(:execute).with(anything).and_return(ServiceResponse.error(message: 'failure'))
2022-07-16 23:28:13 +05:30
end
end
it 'does not update runner or tick the queue' do
expect { request }.not_to change { runner.ensure_runner_queue_value }
expect { request }.not_to change { runner.reload.description }
expect(response).to have_gitlab_http_status(:ok)
expect(response).to render_template(:show)
end
2017-08-17 22:00:37 +05:30
end
end
2021-01-03 14:25:43 +05:30
describe 'GET #runner_setup_scripts' do
it 'renders the setup scripts' do
get :runner_setup_scripts, params: { os: 'linux', arch: 'amd64' }
expect(response).to have_gitlab_http_status(:ok)
expect(json_response).to have_key("install")
expect(json_response).to have_key("register")
end
it 'renders errors if they occur' do
get :runner_setup_scripts, params: { os: 'foo', arch: 'bar' }
expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response).to have_key("errors")
end
end
2017-08-17 22:00:37 +05:30
end