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

168 lines
4.6 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) }
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
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
describe '#destroy' do
it 'destroys the runner' do
2022-05-07 20:08:51 +05:30
expect_next_instance_of(Ci::Runners::UnregisterRunnerService, runner, user) do |service|
2022-04-04 11:22:00 +05:30
expect(service).to receive(:execute).once.and_call_original
end
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