2015-09-15 20:23:43 +00:00
|
|
|
require 'spec_helper'
|
2015-09-15 13:00:45 +00:00
|
|
|
|
|
|
|
module Ci
|
2015-12-09 10:55:49 +00:00
|
|
|
describe RegisterBuildService, services: true do
|
2015-09-15 13:00:45 +00:00
|
|
|
let!(:service) { RegisterBuildService.new }
|
2015-09-28 12:44:07 +00:00
|
|
|
let!(:gl_project) { FactoryGirl.create :empty_project }
|
2015-09-28 11:35:26 +00:00
|
|
|
let!(:commit) { FactoryGirl.create :ci_commit, gl_project: gl_project }
|
2015-09-28 11:14:34 +00:00
|
|
|
let!(:pending_build) { FactoryGirl.create :ci_build, commit: commit }
|
2015-09-15 13:00:45 +00:00
|
|
|
let!(:shared_runner) { FactoryGirl.create(:ci_runner, is_shared: true) }
|
|
|
|
let!(:specific_runner) { FactoryGirl.create(:ci_runner, is_shared: false) }
|
|
|
|
|
|
|
|
before do
|
2015-09-29 08:44:53 +00:00
|
|
|
specific_runner.assign_to(gl_project.ensure_gitlab_ci_project)
|
2015-08-26 01:42:46 +00:00
|
|
|
end
|
|
|
|
|
2015-09-15 13:00:45 +00:00
|
|
|
describe :execute do
|
|
|
|
context 'runner follow tag list' do
|
|
|
|
it "picks build with the same tag" do
|
|
|
|
pending_build.tag_list = ["linux"]
|
|
|
|
pending_build.save
|
|
|
|
specific_runner.tag_list = ["linux"]
|
|
|
|
expect(service.execute(specific_runner)).to eq(pending_build)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does not pick build with different tag" do
|
|
|
|
pending_build.tag_list = ["linux"]
|
|
|
|
pending_build.save
|
|
|
|
specific_runner.tag_list = ["win32"]
|
|
|
|
expect(service.execute(specific_runner)).to be_falsey
|
|
|
|
end
|
|
|
|
|
|
|
|
it "picks build without tag" do
|
|
|
|
expect(service.execute(specific_runner)).to eq(pending_build)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does not pick build with tag" do
|
|
|
|
pending_build.tag_list = ["linux"]
|
|
|
|
pending_build.save
|
|
|
|
expect(service.execute(specific_runner)).to be_falsey
|
|
|
|
end
|
|
|
|
|
|
|
|
it "pick build without tag" do
|
|
|
|
specific_runner.tag_list = ["win32"]
|
|
|
|
expect(service.execute(specific_runner)).to eq(pending_build)
|
|
|
|
end
|
2015-08-26 01:42:46 +00:00
|
|
|
end
|
|
|
|
|
2015-09-15 13:00:45 +00:00
|
|
|
context 'allow shared runners' do
|
|
|
|
before do
|
2015-09-28 12:44:07 +00:00
|
|
|
gl_project.gitlab_ci_project.update(shared_runners_enabled: true)
|
2015-09-15 13:00:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'shared runner' do
|
|
|
|
let(:build) { service.execute(shared_runner) }
|
|
|
|
|
|
|
|
it { expect(build).to be_kind_of(Build) }
|
|
|
|
it { expect(build).to be_valid }
|
|
|
|
it { expect(build).to be_running }
|
|
|
|
it { expect(build.runner).to eq(shared_runner) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'specific runner' do
|
|
|
|
let(:build) { service.execute(specific_runner) }
|
|
|
|
|
|
|
|
it { expect(build).to be_kind_of(Build) }
|
|
|
|
it { expect(build).to be_valid }
|
|
|
|
it { expect(build).to be_running }
|
|
|
|
it { expect(build.runner).to eq(specific_runner) }
|
|
|
|
end
|
2015-08-26 01:42:46 +00:00
|
|
|
end
|
|
|
|
|
2015-09-15 13:00:45 +00:00
|
|
|
context 'disallow shared runners' do
|
2015-11-05 15:22:37 +00:00
|
|
|
before do
|
|
|
|
gl_project.gitlab_ci_project.update(shared_runners_enabled: false)
|
|
|
|
end
|
|
|
|
|
2015-09-15 13:00:45 +00:00
|
|
|
context 'shared runner' do
|
|
|
|
let(:build) { service.execute(shared_runner) }
|
2015-08-26 01:42:46 +00:00
|
|
|
|
2015-09-15 13:00:45 +00:00
|
|
|
it { expect(build).to be_nil }
|
|
|
|
end
|
2015-08-26 01:42:46 +00:00
|
|
|
|
2015-09-15 13:00:45 +00:00
|
|
|
context 'specific runner' do
|
|
|
|
let(:build) { service.execute(specific_runner) }
|
2015-08-26 01:42:46 +00:00
|
|
|
|
2015-09-15 13:00:45 +00:00
|
|
|
it { expect(build).to be_kind_of(Build) }
|
|
|
|
it { expect(build).to be_valid }
|
|
|
|
it { expect(build).to be_running }
|
|
|
|
it { expect(build.runner).to eq(specific_runner) }
|
|
|
|
end
|
2015-08-26 01:42:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|