debian-mirror-gitlab/spec/requests/ci/api/runners_spec.rb

119 lines
3.5 KiB
Ruby
Raw Normal View History

2015-09-25 12:07:36 +05:30
require 'spec_helper'
describe Ci::API::API do
include ApiHelpers
include StubGitlabCalls
2015-12-23 02:04:40 +05:30
let(:registration_token) { 'abcdefg123456' }
2015-09-25 12:07:36 +05:30
before do
stub_gitlab_calls
2015-12-23 02:04:40 +05:30
stub_application_setting(runners_registration_token: registration_token)
2015-09-25 12:07:36 +05:30
end
describe "POST /runners/register" do
2016-06-02 11:05:42 +05:30
context 'when runner token is provided' do
2015-12-23 02:04:40 +05:30
before { post ci_api("/runners/register"), token: registration_token }
2015-09-25 12:07:36 +05:30
2016-06-02 11:05:42 +05:30
it 'creates runner with default values' do
expect(response).to have_http_status 201
expect(Ci::Runner.first.run_untagged).to be true
end
2015-09-25 12:07:36 +05:30
end
2016-06-02 11:05:42 +05:30
context 'when runner description is provided' do
before do
post ci_api("/runners/register"), token: registration_token,
description: "server.hostname"
end
2015-09-25 12:07:36 +05:30
2016-06-02 11:05:42 +05:30
it 'creates runner' do
expect(response).to have_http_status 201
expect(Ci::Runner.first.description).to eq("server.hostname")
end
2015-09-25 12:07:36 +05:30
end
2016-06-02 11:05:42 +05:30
context 'when runner tags are provided' do
before do
post ci_api("/runners/register"), token: registration_token,
tag_list: "tag1, tag2"
end
2015-09-25 12:07:36 +05:30
2016-06-02 11:05:42 +05:30
it 'creates runner' do
expect(response).to have_http_status 201
expect(Ci::Runner.first.tag_list.sort).to eq(["tag1", "tag2"])
end
2015-09-25 12:07:36 +05:30
end
2016-06-02 11:05:42 +05:30
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']
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
expect(response).to have_http_status 404
end
end
end
context 'when project token is provided' do
2015-12-23 02:04:40 +05:30
let(:project) { FactoryGirl.create(:empty_project) }
before { post ci_api("/runners/register"), token: project.runners_token }
2015-09-25 12:07:36 +05:30
2016-06-02 11:05:42 +05:30
it 'creates runner' do
expect(response).to have_http_status 201
expect(project.runners.size).to eq(1)
end
2015-09-25 12:07:36 +05:30
end
2016-06-02 11:05:42 +05:30
context 'when token is invalid' do
it 'returns 403 error' do
post ci_api("/runners/register"), token: 'invalid'
2015-09-25 12:07:36 +05:30
2016-06-02 11:05:42 +05:30
expect(response).to have_http_status 403
end
2015-09-25 12:07:36 +05:30
end
2016-06-02 11:05:42 +05:30
context 'when no token provided' do
it 'returns 400 error' do
post ci_api("/runners/register")
2015-09-25 12:07:36 +05:30
2016-06-02 11:05:42 +05:30
expect(response).to have_http_status 400
end
2015-09-25 12:07:36 +05:30
end
2016-02-05 20:25:01 +05:30
%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-06-02 11:05:42 +05:30
expect(response).to have_http_status 201
2016-02-05 20:25:01 +05:30
is_expected.to eq(value)
end
end
end
2015-09-25 12:07:36 +05:30
end
describe "DELETE /runners/delete" do
let!(:runner) { FactoryGirl.create(:ci_runner) }
before { delete ci_api("/runners/delete"), token: runner.token }
2016-06-02 11:05:42 +05:30
it { expect(response).to have_http_status 200 }
2015-09-25 12:07:36 +05:30
it { expect(Ci::Runner.count).to eq(0) }
end
end