2017-02-15 06:16:12 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Admin::RunnersController do
|
2019-02-26 14:30:43 -05:00
|
|
|
let!(:runner) { create(:ci_runner) }
|
2017-02-15 06:16:12 -05:00
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(create(:admin))
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#index' do
|
2019-02-26 14:30:43 -05:00
|
|
|
render_views
|
|
|
|
|
2017-02-15 06:16:12 -05:00
|
|
|
it 'lists all runners' do
|
|
|
|
get :index
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2017-02-15 06:16:12 -05:00
|
|
|
end
|
2019-02-26 14:30:43 -05:00
|
|
|
|
|
|
|
it 'avoids N+1 queries', :request_store do
|
|
|
|
get :index
|
|
|
|
|
|
|
|
control_count = ActiveRecord::QueryRecorder.new { get :index }.count
|
|
|
|
|
|
|
|
create(:ci_runner, :tagged_only)
|
|
|
|
|
|
|
|
# There is still an N+1 query for `runner.builds.count`
|
|
|
|
expect { get :index }.not_to exceed_query_limit(control_count + 1)
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(200)
|
|
|
|
expect(response.body).to have_content('tag1')
|
|
|
|
expect(response.body).to have_content('tag2')
|
|
|
|
end
|
2017-02-15 06:16:12 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#show' do
|
|
|
|
it 'shows a particular runner' do
|
2018-12-17 17:52:17 -05:00
|
|
|
get :show, params: { id: runner.id }
|
2017-02-15 06:16:12 -05:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2017-02-15 06:16:12 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows 404 for unknown runner' do
|
2018-12-17 17:52:17 -05:00
|
|
|
get :show, params: { id: 0 }
|
2017-02-15 06:16:12 -05:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2017-02-15 06:16:12 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#update' do
|
|
|
|
it 'updates the runner and ticks the queue' do
|
|
|
|
new_desc = runner.description.swapcase
|
|
|
|
|
2017-02-15 07:21:51 -05:00
|
|
|
expect do
|
2018-12-17 17:52:17 -05:00
|
|
|
post :update, params: { id: runner.id, runner: { description: new_desc } }
|
2017-02-15 07:21:51 -05:00
|
|
|
end.to change { runner.ensure_runner_queue_value }
|
2017-02-15 06:16:12 -05:00
|
|
|
|
|
|
|
runner.reload
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(302)
|
2017-02-15 06:16:12 -05:00
|
|
|
expect(runner.description).to eq(new_desc)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#destroy' do
|
|
|
|
it 'destroys the runner' do
|
2018-12-17 17:52:17 -05:00
|
|
|
delete :destroy, params: { id: runner.id }
|
2017-02-15 06:16:12 -05:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(302)
|
2017-02-15 06:16:12 -05:00
|
|
|
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
|
|
|
|
runner.update(active: false)
|
|
|
|
|
2017-02-15 07:21:51 -05:00
|
|
|
expect do
|
2018-12-17 17:52:17 -05:00
|
|
|
post :resume, params: { id: runner.id }
|
2017-02-15 07:21:51 -05:00
|
|
|
end.to change { runner.ensure_runner_queue_value }
|
2017-02-15 06:16:12 -05:00
|
|
|
|
|
|
|
runner.reload
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(302)
|
2017-02-15 06:16:12 -05:00
|
|
|
expect(runner.active).to eq(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#pause' do
|
|
|
|
it 'marks the runner as inactive and ticks the queue' do
|
|
|
|
runner.update(active: true)
|
|
|
|
|
2017-02-15 07:21:51 -05:00
|
|
|
expect do
|
2018-12-17 17:52:17 -05:00
|
|
|
post :pause, params: { id: runner.id }
|
2017-02-15 07:21:51 -05:00
|
|
|
end.to change { runner.ensure_runner_queue_value }
|
2017-02-15 06:16:12 -05:00
|
|
|
|
|
|
|
runner.reload
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(302)
|
2017-02-15 06:16:12 -05:00
|
|
|
expect(runner.active).to eq(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|