2015-08-26 01:42:46 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2015-09-09 12:17:16 +00:00
|
|
|
describe Ci::API::API do
|
2015-08-26 01:42:46 +00:00
|
|
|
include ApiHelpers
|
|
|
|
include StubGitlabCalls
|
|
|
|
|
2015-09-14 11:37:18 +00:00
|
|
|
before do
|
2015-08-26 01:42:46 +00:00
|
|
|
stub_gitlab_calls
|
2015-09-14 11:37:18 +00:00
|
|
|
end
|
2015-08-26 01:42:46 +00:00
|
|
|
|
|
|
|
describe "POST /runners/register" do
|
|
|
|
describe "should create a runner if token provided" do
|
2015-09-14 15:14:17 +00:00
|
|
|
before { post ci_api("/runners/register"), token: GitlabCi::REGISTRATION_TOKEN }
|
2015-08-26 01:42:46 +00:00
|
|
|
|
2015-09-10 14:04:06 +00:00
|
|
|
it { expect(response.status).to eq(201) }
|
2015-08-26 01:42:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "should create a runner with description" do
|
2015-09-14 15:14:17 +00:00
|
|
|
before { post ci_api("/runners/register"), token: GitlabCi::REGISTRATION_TOKEN, description: "server.hostname" }
|
2015-08-26 01:42:46 +00:00
|
|
|
|
2015-09-10 14:04:06 +00:00
|
|
|
it { expect(response.status).to eq(201) }
|
2015-09-14 15:14:17 +00:00
|
|
|
it { expect(Ci::Runner.first.description).to eq("server.hostname") }
|
2015-08-26 01:42:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "should create a runner with tags" do
|
2015-09-14 15:14:17 +00:00
|
|
|
before { post ci_api("/runners/register"), token: GitlabCi::REGISTRATION_TOKEN, tag_list: "tag1, tag2" }
|
2015-08-26 01:42:46 +00:00
|
|
|
|
2015-09-10 14:04:06 +00:00
|
|
|
it { expect(response.status).to eq(201) }
|
2015-09-14 15:14:17 +00:00
|
|
|
it { expect(Ci::Runner.first.tag_list.sort).to eq(["tag1", "tag2"]) }
|
2015-08-26 01:42:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "should create a runner if project token provided" do
|
2015-12-04 11:55:23 +00:00
|
|
|
let(:project) { FactoryGirl.create(:empty_project) }
|
2015-09-14 15:14:17 +00:00
|
|
|
before { post ci_api("/runners/register"), token: project.token }
|
2015-08-26 01:42:46 +00:00
|
|
|
|
2015-09-10 14:04:06 +00:00
|
|
|
it { expect(response.status).to eq(201) }
|
2015-12-10 16:44:06 +00:00
|
|
|
it { expect(project.runners.size).to eq(1) }
|
2015-08-26 01:42:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should return 403 error if token is invalid" do
|
2015-09-14 15:14:17 +00:00
|
|
|
post ci_api("/runners/register"), token: 'invalid'
|
2015-08-26 01:42:46 +00:00
|
|
|
|
2015-09-10 14:04:06 +00:00
|
|
|
expect(response.status).to eq(403)
|
2015-08-26 01:42:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should return 400 error if no token" do
|
2015-09-14 15:14:17 +00:00
|
|
|
post ci_api("/runners/register")
|
2015-08-26 01:42:46 +00:00
|
|
|
|
2015-09-10 14:04:06 +00:00
|
|
|
expect(response.status).to eq(400)
|
2015-08-26 01:42:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "DELETE /runners/delete" do
|
2015-09-10 14:04:06 +00:00
|
|
|
let!(:runner) { FactoryGirl.create(:ci_runner) }
|
2015-09-14 15:14:17 +00:00
|
|
|
before { delete ci_api("/runners/delete"), token: runner.token }
|
2015-08-26 01:42:46 +00:00
|
|
|
|
2015-09-10 14:04:06 +00:00
|
|
|
it { expect(response.status).to eq(200) }
|
2015-09-14 15:14:17 +00:00
|
|
|
it { expect(Ci::Runner.count).to eq(0) }
|
2015-08-26 01:42:46 +00:00
|
|
|
end
|
|
|
|
end
|