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

78 lines
2.4 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
describe "should create a runner if token 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
it { expect(response.status).to eq(201) }
end
describe "should create a runner with description" do
2015-12-23 02:04:40 +05:30
before { post ci_api("/runners/register"), token: registration_token, description: "server.hostname" }
2015-09-25 12:07:36 +05:30
it { expect(response.status).to eq(201) }
it { expect(Ci::Runner.first.description).to eq("server.hostname") }
end
describe "should create a runner with tags" do
2015-12-23 02:04:40 +05:30
before { post ci_api("/runners/register"), token: registration_token, tag_list: "tag1, tag2" }
2015-09-25 12:07:36 +05:30
it { expect(response.status).to eq(201) }
it { expect(Ci::Runner.first.tag_list.sort).to eq(["tag1", "tag2"]) }
end
describe "should create a runner if project token 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
it { expect(response.status).to eq(201) }
it { expect(project.runners.size).to eq(1) }
end
it "should return 403 error if token is invalid" do
post ci_api("/runners/register"), token: 'invalid'
expect(response.status).to eq(403)
end
it "should return 400 error if no token" do
post ci_api("/runners/register")
expect(response.status).to eq(400)
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 }
expect(response.status).to eq(201)
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 }
it { expect(response.status).to eq(200) }
it { expect(Ci::Runner.count).to eq(0) }
end
end