gitlab-org--gitlab-foss/spec/requests/ci/api/runners_spec.rb

128 lines
3.7 KiB
Ruby
Raw Normal View History

2015-08-25 21:42:46 -04:00
require 'spec_helper'
describe Ci::API::Runners do
2015-08-25 21:42:46 -04:00
include StubGitlabCalls
let(:registration_token) { 'abcdefg123456' }
2015-09-14 07:37:18 -04:00
before do
2015-08-25 21:42:46 -04:00
stub_gitlab_calls
stub_application_setting(runners_registration_token: registration_token)
2015-09-14 07:37:18 -04:00
end
2015-08-25 21:42:46 -04:00
describe "POST /runners/register" do
context 'when runner token is provided' do
before do
post ci_api("/runners/register"), token: registration_token
end
2015-08-25 21:42:46 -04:00
it 'creates runner with default values' do
2016-05-19 15:27:52 -04:00
expect(response).to have_http_status 201
expect(Ci::Runner.first.run_untagged).to be true
expect(Ci::Runner.first.token).not_to eq(registration_token)
end
2015-08-25 21:42:46 -04:00
end
context 'when runner description is provided' do
before do
post ci_api("/runners/register"), token: registration_token,
description: "server.hostname"
end
2015-08-25 21:42:46 -04:00
it 'creates runner' do
2016-05-19 15:27:52 -04:00
expect(response).to have_http_status 201
expect(Ci::Runner.first.description).to eq("server.hostname")
end
2015-08-25 21:42:46 -04:00
end
context 'when runner tags are provided' do
before do
post ci_api("/runners/register"), token: registration_token,
tag_list: "tag1, tag2"
end
2015-08-25 21:42:46 -04:00
it 'creates runner' do
2016-05-19 15:27:52 -04:00
expect(response).to have_http_status 201
2017-02-22 12:46:57 -05:00
expect(Ci::Runner.first.tag_list.sort).to eq(%w(tag1 tag2))
end
2015-08-25 21:42:46 -04:00
end
context 'when option for running untagged jobs is provided' do
context 'when tags are provided' do
it 'creates runner' do
post ci_api("/runners/register"), token: registration_token,
run_untagged: false,
tag_list: ['tag']
2016-05-19 15:27:52 -04:00
expect(response).to have_http_status 201
expect(Ci::Runner.first.run_untagged).to be false
end
end
context 'when tags are not provided' do
it 'does not create runner' do
post ci_api("/runners/register"), token: registration_token,
run_untagged: false
2016-05-19 15:27:52 -04:00
expect(response).to have_http_status 404
end
end
end
context 'when project token is provided' do
let(:project) { FactoryGirl.create(:project) }
before do
post ci_api("/runners/register"), token: project.runners_token
end
2015-08-25 21:42:46 -04:00
it 'creates runner' do
2016-05-19 15:27:52 -04:00
expect(response).to have_http_status 201
expect(project.runners.size).to eq(1)
expect(Ci::Runner.first.token).not_to eq(registration_token)
expect(Ci::Runner.first.token).not_to eq(project.runners_token)
end
2015-08-25 21:42:46 -04:00
end
context 'when token is invalid' do
it 'returns 403 error' do
post ci_api("/runners/register"), token: 'invalid'
2015-08-25 21:42:46 -04:00
2016-05-19 15:27:52 -04:00
expect(response).to have_http_status 403
end
2015-08-25 21:42:46 -04:00
end
context 'when no token provided' do
it 'returns 400 error' do
post ci_api("/runners/register")
2015-08-25 21:42:46 -04:00
2016-05-19 15:27:52 -04:00
expect(response).to have_http_status 400
end
2015-08-25 21:42:46 -04:00
end
%w(name version revision platform architecture).each do |param|
context "creates runner with #{param} saved" do
let(:value) { "#{param}_value" }
subject { Ci::Runner.first.read_attribute(param.to_sym) }
it do
post ci_api("/runners/register"), token: registration_token, info: { param => value }
2016-05-19 15:27:52 -04:00
expect(response).to have_http_status 201
is_expected.to eq(value)
end
end
end
2015-08-25 21:42:46 -04:00
end
describe "DELETE /runners/delete" do
2016-10-19 08:25:37 -04:00
it 'returns 200' do
runner = FactoryGirl.create(:ci_runner)
delete ci_api("/runners/delete"), token: runner.token
2015-08-25 21:42:46 -04:00
2016-10-19 08:25:37 -04:00
expect(response).to have_http_status 200
expect(Ci::Runner.count).to eq(0)
end
2015-08-25 21:42:46 -04:00
end
end