2015-08-25 21:42:46 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2016-11-23 15:14:08 -05:00
|
|
|
describe Ci::API::Runners do
|
2015-08-25 21:42:46 -04:00
|
|
|
include ApiHelpers
|
|
|
|
include StubGitlabCalls
|
|
|
|
|
2015-12-10 07:50:00 -05:00
|
|
|
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
|
2015-12-10 07:50:00 -05:00
|
|
|
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
|
2016-05-06 07:56:22 -04:00
|
|
|
context 'when runner token is provided' do
|
2015-12-10 07:50:00 -05:00
|
|
|
before { post ci_api("/runners/register"), token: registration_token }
|
2015-08-25 21:42:46 -04:00
|
|
|
|
2016-05-06 08:06:57 -04:00
|
|
|
it 'creates runner with default values' do
|
2016-05-19 15:27:52 -04:00
|
|
|
expect(response).to have_http_status 201
|
2016-05-06 08:06:57 -04:00
|
|
|
expect(Ci::Runner.first.run_untagged).to be true
|
2016-05-06 07:56:22 -04:00
|
|
|
end
|
2015-08-25 21:42:46 -04:00
|
|
|
end
|
|
|
|
|
2016-05-06 07:56:22 -04:00
|
|
|
context 'when runner description is provided' do
|
2016-05-06 08:06:57 -04:00
|
|
|
before do
|
|
|
|
post ci_api("/runners/register"), token: registration_token,
|
|
|
|
description: "server.hostname"
|
|
|
|
end
|
2015-08-25 21:42:46 -04:00
|
|
|
|
2016-05-06 07:56:22 -04:00
|
|
|
it 'creates runner' do
|
2016-05-19 15:27:52 -04:00
|
|
|
expect(response).to have_http_status 201
|
2016-05-06 07:56:22 -04:00
|
|
|
expect(Ci::Runner.first.description).to eq("server.hostname")
|
|
|
|
end
|
2015-08-25 21:42:46 -04:00
|
|
|
end
|
|
|
|
|
2016-05-06 07:56:22 -04:00
|
|
|
context 'when runner tags are provided' do
|
2016-05-06 08:06:57 -04:00
|
|
|
before do
|
|
|
|
post ci_api("/runners/register"), token: registration_token,
|
|
|
|
tag_list: "tag1, tag2"
|
|
|
|
end
|
2015-08-25 21:42:46 -04:00
|
|
|
|
2016-05-06 07:56:22 -04:00
|
|
|
it 'creates runner' do
|
2016-05-19 15:27:52 -04:00
|
|
|
expect(response).to have_http_status 201
|
2016-05-06 07:56:22 -04:00
|
|
|
expect(Ci::Runner.first.tag_list.sort).to eq(["tag1", "tag2"])
|
|
|
|
end
|
2015-08-25 21:42:46 -04:00
|
|
|
end
|
|
|
|
|
2016-05-06 08:06:57 -04:00
|
|
|
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
|
2016-05-06 08:06:57 -04:00
|
|
|
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
|
2016-05-06 08:06:57 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-05-06 07:56:22 -04:00
|
|
|
context 'when project token is provided' do
|
2015-12-04 06:55:23 -05:00
|
|
|
let(:project) { FactoryGirl.create(:empty_project) }
|
2015-12-11 07:39:43 -05:00
|
|
|
before { post ci_api("/runners/register"), token: project.runners_token }
|
2015-08-25 21:42:46 -04:00
|
|
|
|
2016-05-06 07:56:22 -04:00
|
|
|
it 'creates runner' do
|
2016-05-19 15:27:52 -04:00
|
|
|
expect(response).to have_http_status 201
|
2016-05-06 07:56:22 -04:00
|
|
|
expect(project.runners.size).to eq(1)
|
|
|
|
end
|
2015-08-25 21:42:46 -04:00
|
|
|
end
|
|
|
|
|
2016-05-06 07:56:22 -04:00
|
|
|
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
|
2016-05-06 07:56:22 -04:00
|
|
|
end
|
2015-08-25 21:42:46 -04:00
|
|
|
end
|
|
|
|
|
2016-05-06 07:56:22 -04:00
|
|
|
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
|
2016-05-06 07:56:22 -04:00
|
|
|
end
|
2015-08-25 21:42:46 -04:00
|
|
|
end
|
2016-01-26 13:25:48 -05:00
|
|
|
|
|
|
|
%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
|
2016-01-26 13:25:48 -05:00
|
|
|
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
|