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

161 lines
4.2 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'
2020-06-23 00:09:42 +05:30
RSpec.describe Admin::RunnersController do
2020-03-13 15:44:24 +05:30
let_it_be(:runner) { create(:ci_runner) }
2017-08-17 22:00:37 +05:30
before do
sign_in(create(:admin))
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
let_it_be(:project) { create(:project) }
before_all do
create(:ci_build, runner: runner, project: project)
end
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
it 'when runner_read_only_admin_view is off, redirects to the runner edit page' do
stub_feature_flags(runner_read_only_admin_view: false)
get :show, params: { id: runner.id }
expect(response).to have_gitlab_http_status(:redirect)
expect(response).to redirect_to edit_admin_runner_path(runner)
end
end
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) }
before_all do
create(:ci_build, runner: runner, project: project)
create(:ci_build, runner: runner, project: project_two)
end
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
new_project = create(:project)
create(:ci_build, runner: runner, project: new_project)
# 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
it 'updates the runner and ticks the queue' do
new_desc = runner.description.swapcase
expect do
2019-02-15 15:39:39 +05:30
post :update, params: { id: runner.id, runner: { description: new_desc } }
2017-08-17 22:00:37 +05:30
end.to change { runner.ensure_runner_queue_value }
runner.reload
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:found)
2017-08-17 22:00:37 +05:30
expect(runner.description).to eq(new_desc)
end
end
describe '#destroy' do
it 'destroys the runner' do
2019-02-15 15:39:39 +05:30
delete :destroy, 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(:found)
2017-08-17 22:00:37 +05:30
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-04-29 21:17:54 +05:30
runner.update!(active: false)
2017-08-17 22:00:37 +05:30
expect do
2019-02-15 15:39:39 +05:30
post :resume, params: { id: runner.id }
2017-08-17 22:00:37 +05:30
end.to change { runner.ensure_runner_queue_value }
runner.reload
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:found)
2017-08-17 22:00:37 +05:30
expect(runner.active).to eq(true)
end
end
describe '#pause' do
it 'marks the runner as inactive and ticks the queue' do
2021-04-29 21:17:54 +05:30
runner.update!(active: true)
2017-08-17 22:00:37 +05:30
expect do
2019-02-15 15:39:39 +05:30
post :pause, params: { id: runner.id }
2017-08-17 22:00:37 +05:30
end.to change { runner.ensure_runner_queue_value }
runner.reload
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:found)
2017-08-17 22:00:37 +05:30
expect(runner.active).to eq(false)
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