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 "GET /runners" do
|
2015-09-14 15:14:17 +00:00
|
|
|
let(:gitlab_url) { GitlabCi.config.gitlab_ci.url }
|
|
|
|
let(:private_token) { create(:user).private_token }
|
2015-09-14 11:37:18 +00:00
|
|
|
let(:options) do
|
2015-08-26 01:42:46 +00:00
|
|
|
{
|
2015-09-14 11:37:18 +00:00
|
|
|
private_token: private_token,
|
|
|
|
url: gitlab_url
|
2015-08-26 01:42:46 +00:00
|
|
|
}
|
2015-09-14 11:37:18 +00:00
|
|
|
end
|
2015-08-26 01:42:46 +00:00
|
|
|
|
|
|
|
before do
|
2015-09-10 14:04:06 +00:00
|
|
|
5.times { FactoryGirl.create(:ci_runner) }
|
2015-08-26 01:42:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should retrieve a list of all runners" do
|
2015-09-14 15:14:17 +00:00
|
|
|
get ci_api("/runners", nil), options
|
2015-09-10 14:04:06 +00:00
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(json_response.count).to eq(5)
|
|
|
|
expect(json_response.last).to have_key("id")
|
|
|
|
expect(json_response.last).to have_key("token")
|
2015-08-26 01:42:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
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-09-10 14:04:06 +00:00
|
|
|
let(:project) { FactoryGirl.create(:ci_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) }
|
|
|
|
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
|