2015-09-25 12:07:36 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
describe Ci::Runner do
|
2016-06-02 11:05:42 +05:30
|
|
|
describe 'validation' do
|
2018-03-17 18:26:18 +05:30
|
|
|
it { is_expected.to validate_presence_of(:access_level) }
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
context 'when runner is not allowed to pick untagged jobs' do
|
|
|
|
context 'when runner does not have tags' do
|
|
|
|
it 'is not valid' do
|
|
|
|
runner = build(:ci_runner, tag_list: [], run_untagged: false)
|
|
|
|
expect(runner).to be_invalid
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when runner has tags' do
|
|
|
|
it 'is valid' do
|
|
|
|
runner = build(:ci_runner, tag_list: ['tag'], run_untagged: false)
|
|
|
|
expect(runner).to be_valid
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
describe '#access_level' do
|
|
|
|
context 'when creating new runner and access_level is nil' do
|
|
|
|
let(:runner) do
|
|
|
|
build(:ci_runner, access_level: nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "object is invalid" do
|
|
|
|
expect(runner).not_to be_valid
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when creating new runner and access_level is defined in enum' do
|
|
|
|
let(:runner) do
|
|
|
|
build(:ci_runner, access_level: :not_protected)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "object is valid" do
|
|
|
|
expect(runner).to be_valid
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when creating new runner and access_level is not defined in enum' do
|
|
|
|
it "raises an error" do
|
|
|
|
expect { build(:ci_runner, access_level: :this_is_not_defined) }.to raise_error(ArgumentError)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-09-25 12:07:36 +05:30
|
|
|
describe '#display_name' do
|
2016-06-22 15:30:34 +05:30
|
|
|
it 'returns the description if it has a value' do
|
2018-03-17 18:26:18 +05:30
|
|
|
runner = FactoryBot.build(:ci_runner, description: 'Linux/Ruby-1.9.3-p448')
|
2015-09-25 12:07:36 +05:30
|
|
|
expect(runner.display_name).to eq 'Linux/Ruby-1.9.3-p448'
|
|
|
|
end
|
|
|
|
|
2016-06-22 15:30:34 +05:30
|
|
|
it 'returns the token if it does not have a description' do
|
2018-03-17 18:26:18 +05:30
|
|
|
runner = FactoryBot.create(:ci_runner)
|
2015-09-25 12:07:36 +05:30
|
|
|
expect(runner.display_name).to eq runner.description
|
|
|
|
end
|
|
|
|
|
2016-06-22 15:30:34 +05:30
|
|
|
it 'returns the token if the description is an empty string' do
|
2018-03-17 18:26:18 +05:30
|
|
|
runner = FactoryBot.build(:ci_runner, description: '', token: 'token')
|
2015-09-25 12:07:36 +05:30
|
|
|
expect(runner.display_name).to eq runner.token
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-22 15:30:34 +05:30
|
|
|
describe '#assign_to' do
|
2018-03-17 18:26:18 +05:30
|
|
|
let!(:project) { FactoryBot.create :project }
|
|
|
|
let!(:shared_runner) { FactoryBot.create(:ci_runner, :shared) }
|
2015-09-25 12:07:36 +05:30
|
|
|
|
2016-06-22 15:30:34 +05:30
|
|
|
before do
|
|
|
|
shared_runner.assign_to(project)
|
|
|
|
end
|
2015-09-25 12:07:36 +05:30
|
|
|
|
|
|
|
it { expect(shared_runner).to be_specific }
|
|
|
|
it { expect(shared_runner.projects).to eq([project]) }
|
|
|
|
it { expect(shared_runner.only_for?(project)).to be_truthy }
|
|
|
|
end
|
|
|
|
|
2016-06-22 15:30:34 +05:30
|
|
|
describe '.online' do
|
2017-09-10 17:25:29 +05:30
|
|
|
subject { described_class.online }
|
2015-10-24 18:46:33 +05:30
|
|
|
|
|
|
|
before do
|
2018-03-17 18:26:18 +05:30
|
|
|
@runner1 = FactoryBot.create(:ci_runner, :shared, contacted_at: 1.year.ago)
|
|
|
|
@runner2 = FactoryBot.create(:ci_runner, :shared, contacted_at: 1.second.ago)
|
2015-10-24 18:46:33 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to eq([@runner2])}
|
|
|
|
end
|
|
|
|
|
2016-06-22 15:30:34 +05:30
|
|
|
describe '#online?' do
|
2018-03-17 18:26:18 +05:30
|
|
|
let(:runner) { FactoryBot.create(:ci_runner, :shared) }
|
2015-10-24 18:46:33 +05:30
|
|
|
|
|
|
|
subject { runner.online? }
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
before do
|
|
|
|
allow_any_instance_of(described_class).to receive(:cached_attribute).and_call_original
|
|
|
|
allow_any_instance_of(described_class).to receive(:cached_attribute)
|
|
|
|
.with(:platform).and_return("darwin")
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'no cache value' do
|
2016-06-22 15:30:34 +05:30
|
|
|
before do
|
2018-03-17 18:26:18 +05:30
|
|
|
stub_redis_runner_contacted_at(nil)
|
2016-06-22 15:30:34 +05:30
|
|
|
end
|
2015-10-24 18:46:33 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
context 'never contacted' do
|
|
|
|
before do
|
|
|
|
runner.contacted_at = nil
|
|
|
|
end
|
2015-10-24 18:46:33 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it { is_expected.to be_falsey }
|
2016-06-22 15:30:34 +05:30
|
|
|
end
|
2015-10-24 18:46:33 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
context 'contacted long time ago time' do
|
|
|
|
before do
|
|
|
|
runner.contacted_at = 1.year.ago
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to be_falsey }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'contacted 1s ago' do
|
|
|
|
before do
|
|
|
|
runner.contacted_at = 1.second.ago
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
end
|
2015-10-24 18:46:33 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
context 'with cache value' do
|
|
|
|
context 'contacted long time ago time' do
|
|
|
|
before do
|
|
|
|
runner.contacted_at = 1.year.ago
|
|
|
|
stub_redis_runner_contacted_at(1.year.ago.to_s)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to be_falsey }
|
2016-06-22 15:30:34 +05:30
|
|
|
end
|
2015-10-24 18:46:33 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
context 'contacted 1s ago' do
|
|
|
|
before do
|
|
|
|
runner.contacted_at = 50.minutes.ago
|
|
|
|
stub_redis_runner_contacted_at(1.second.ago.to_s)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def stub_redis_runner_contacted_at(value)
|
|
|
|
Gitlab::Redis::SharedState.with do |redis|
|
|
|
|
cache_key = runner.send(:cache_attribute_key)
|
|
|
|
expect(redis).to receive(:get).with(cache_key)
|
|
|
|
.and_return({ contacted_at: value }.to_json).at_least(:once)
|
|
|
|
end
|
2015-10-24 18:46:33 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-22 15:30:34 +05:30
|
|
|
describe '#can_pick?' do
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:pipeline) { create(:ci_pipeline) }
|
2016-06-22 15:30:34 +05:30
|
|
|
let(:build) { create(:ci_build, pipeline: pipeline) }
|
|
|
|
let(:runner) { create(:ci_runner) }
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
subject { runner.can_pick?(build) }
|
|
|
|
|
2016-06-22 15:30:34 +05:30
|
|
|
before do
|
|
|
|
build.project.runners << runner
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when runner does not have tags' do
|
|
|
|
it 'can handle builds without tags' do
|
|
|
|
expect(runner.can_pick?(build)).to be_truthy
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'cannot handle build with tags' do
|
|
|
|
build.tag_list = ['aa']
|
|
|
|
|
|
|
|
expect(runner.can_pick?(build)).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when runner has tags' do
|
|
|
|
before do
|
2017-08-17 22:00:37 +05:30
|
|
|
runner.tag_list = %w(bb cc)
|
2016-06-22 15:30:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'tagged build picker' do
|
|
|
|
it 'can handle build with matching tags' do
|
|
|
|
build.tag_list = ['bb']
|
|
|
|
|
|
|
|
expect(runner.can_pick?(build)).to be_truthy
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'cannot handle build without matching tags' do
|
|
|
|
build.tag_list = ['aa']
|
|
|
|
|
|
|
|
expect(runner.can_pick?(build)).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when runner can pick untagged jobs' do
|
|
|
|
it 'can handle builds without tags' do
|
|
|
|
expect(runner.can_pick?(build)).to be_truthy
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'tagged build picker'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when runner cannot pick untagged jobs' do
|
|
|
|
before do
|
|
|
|
runner.run_untagged = false
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'cannot handle builds without tags' do
|
|
|
|
expect(runner.can_pick?(build)).to be_falsey
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'tagged build picker'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
context 'when runner is shared' do
|
2016-06-22 15:30:34 +05:30
|
|
|
before do
|
2018-03-17 18:26:18 +05:30
|
|
|
runner.is_shared = true
|
|
|
|
build.project.runners = []
|
2016-06-22 15:30:34 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it 'can handle builds' do
|
|
|
|
expect(runner.can_pick?(build)).to be_truthy
|
|
|
|
end
|
2016-06-22 15:30:34 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
context 'when runner is locked' do
|
|
|
|
before do
|
|
|
|
runner.locked = true
|
2016-06-22 15:30:34 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it 'can handle builds' do
|
|
|
|
expect(runner.can_pick?(build)).to be_truthy
|
2016-06-22 15:30:34 +05:30
|
|
|
end
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
2016-06-22 15:30:34 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
context 'when runner is not shared' do
|
|
|
|
context 'when runner is assigned to a project' do
|
|
|
|
it 'can handle builds' do
|
2016-06-22 15:30:34 +05:30
|
|
|
expect(runner.can_pick?(build)).to be_truthy
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
2016-06-22 15:30:34 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
context 'when runner is not assigned to a project' do
|
|
|
|
before do
|
|
|
|
build.project.runners = []
|
|
|
|
end
|
2016-06-22 15:30:34 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it 'cannot handle builds' do
|
|
|
|
expect(runner.can_pick?(build)).to be_falsey
|
2016-06-22 15:30:34 +05:30
|
|
|
end
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'when access_level of runner is not_protected' do
|
|
|
|
before do
|
|
|
|
runner.not_protected!
|
|
|
|
end
|
2016-06-22 15:30:34 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
context 'when build is protected' do
|
2016-06-22 15:30:34 +05:30
|
|
|
before do
|
2018-03-17 18:26:18 +05:30
|
|
|
build.protected = true
|
2016-06-22 15:30:34 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when build is unprotected' do
|
|
|
|
before do
|
|
|
|
build.protected = false
|
2016-06-22 15:30:34 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
end
|
|
|
|
end
|
2016-06-22 15:30:34 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
context 'when access_level of runner is ref_protected' do
|
|
|
|
before do
|
|
|
|
runner.ref_protected!
|
|
|
|
end
|
2016-06-22 15:30:34 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
context 'when build is protected' do
|
|
|
|
before do
|
|
|
|
build.protected = true
|
2016-06-22 15:30:34 +05:30
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when build is unprotected' do
|
|
|
|
before do
|
|
|
|
build.protected = false
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to be_falsey }
|
2016-06-22 15:30:34 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#status' do
|
2018-03-17 18:26:18 +05:30
|
|
|
let(:runner) { FactoryBot.create(:ci_runner, :shared, contacted_at: 1.second.ago) }
|
2015-10-24 18:46:33 +05:30
|
|
|
|
|
|
|
subject { runner.status }
|
|
|
|
|
|
|
|
context 'never connected' do
|
2016-06-22 15:30:34 +05:30
|
|
|
before do
|
|
|
|
runner.contacted_at = nil
|
|
|
|
end
|
2015-10-24 18:46:33 +05:30
|
|
|
|
|
|
|
it { is_expected.to eq(:not_connected) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'contacted 1s ago' do
|
2016-06-22 15:30:34 +05:30
|
|
|
before do
|
|
|
|
runner.contacted_at = 1.second.ago
|
|
|
|
end
|
2015-10-24 18:46:33 +05:30
|
|
|
|
|
|
|
it { is_expected.to eq(:online) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'contacted long time ago' do
|
2016-06-22 15:30:34 +05:30
|
|
|
before do
|
|
|
|
runner.contacted_at = 1.year.ago
|
|
|
|
end
|
2015-10-24 18:46:33 +05:30
|
|
|
|
|
|
|
it { is_expected.to eq(:offline) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'inactive' do
|
2016-06-22 15:30:34 +05:30
|
|
|
before do
|
|
|
|
runner.active = false
|
|
|
|
end
|
2015-10-24 18:46:33 +05:30
|
|
|
|
|
|
|
it { is_expected.to eq(:paused) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
describe '#tick_runner_queue' do
|
|
|
|
let(:runner) { create(:ci_runner) }
|
|
|
|
|
|
|
|
it 'returns a new last_update value' do
|
|
|
|
expect(runner.tick_runner_queue).not_to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#ensure_runner_queue_value' do
|
|
|
|
let(:runner) { create(:ci_runner) }
|
|
|
|
|
|
|
|
it 'sets a new last_update value when it is called the first time' do
|
|
|
|
last_update = runner.ensure_runner_queue_value
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
expect_value_in_queues.to eq(last_update)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not change if it is not expired and called again' do
|
|
|
|
last_update = runner.ensure_runner_queue_value
|
|
|
|
|
|
|
|
expect(runner.ensure_runner_queue_value).to eq(last_update)
|
2017-09-10 17:25:29 +05:30
|
|
|
expect_value_in_queues.to eq(last_update)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'updates runner queue after changing editable value' do
|
|
|
|
let!(:last_update) { runner.ensure_runner_queue_value }
|
|
|
|
|
|
|
|
before do
|
|
|
|
Ci::UpdateRunnerService.new(runner).update(description: 'new runner')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sets a new last_update value' do
|
2017-09-10 17:25:29 +05:30
|
|
|
expect_value_in_queues.not_to eq(last_update)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'does not update runner value after save' do
|
|
|
|
let!(:last_update) { runner.ensure_runner_queue_value }
|
|
|
|
|
|
|
|
before do
|
|
|
|
runner.touch
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has an old last_update value' do
|
2017-09-10 17:25:29 +05:30
|
|
|
expect_value_in_queues.to eq(last_update)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
def expect_value_in_queues
|
|
|
|
Gitlab::Redis::Queues.with do |redis|
|
2017-08-17 22:00:37 +05:30
|
|
|
runner_queue_key = runner.send(:runner_queue_key)
|
|
|
|
expect(redis.get(runner_queue_key))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
describe '#update_cached_info' do
|
|
|
|
let(:runner) { create(:ci_runner) }
|
|
|
|
|
|
|
|
subject { runner.update_cached_info(architecture: '18-bit') }
|
|
|
|
|
|
|
|
context 'when database was updated recently' do
|
|
|
|
before do
|
|
|
|
runner.contacted_at = Time.now
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'updates cache' do
|
|
|
|
expect_redis_update
|
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when database was not updated recently' do
|
|
|
|
before do
|
|
|
|
runner.contacted_at = 2.hours.ago
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'updates database' do
|
|
|
|
expect_redis_update
|
|
|
|
|
|
|
|
expect { subject }.to change { runner.reload.read_attribute(:contacted_at) }
|
|
|
|
.and change { runner.reload.read_attribute(:architecture) }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'updates cache' do
|
|
|
|
expect_redis_update
|
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def expect_redis_update
|
|
|
|
Gitlab::Redis::SharedState.with do |redis|
|
|
|
|
redis_key = runner.send(:cache_attribute_key)
|
|
|
|
expect(redis).to receive(:set).with(redis_key, anything, any_args)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
describe '#destroy' do
|
|
|
|
let(:runner) { create(:ci_runner) }
|
|
|
|
|
|
|
|
context 'when there is a tick in the queue' do
|
|
|
|
let!(:queue_key) { runner.send(:runner_queue_key) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
runner.tick_runner_queue
|
|
|
|
runner.destroy
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'cleans up the queue' do
|
2017-09-10 17:25:29 +05:30
|
|
|
Gitlab::Redis::Queues.with do |redis|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(redis.get(queue_key)).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-22 15:30:34 +05:30
|
|
|
describe '.assignable_for' do
|
|
|
|
let(:runner) { create(:ci_runner) }
|
2017-09-10 17:25:29 +05:30
|
|
|
let(:project) { create(:project) }
|
|
|
|
let(:another_project) { create(:project) }
|
2016-06-22 15:30:34 +05:30
|
|
|
|
|
|
|
before do
|
|
|
|
project.runners << runner
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with shared runners' do
|
|
|
|
before do
|
|
|
|
runner.update(is_shared: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'does not give owned runner' do
|
2017-09-10 17:25:29 +05:30
|
|
|
subject { described_class.assignable_for(project) }
|
2016-06-22 15:30:34 +05:30
|
|
|
|
|
|
|
it { is_expected.to be_empty }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'does not give shared runner' do
|
2017-09-10 17:25:29 +05:30
|
|
|
subject { described_class.assignable_for(another_project) }
|
2016-06-22 15:30:34 +05:30
|
|
|
|
|
|
|
it { is_expected.to be_empty }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with unlocked runner' do
|
|
|
|
context 'does not give owned runner' do
|
2017-09-10 17:25:29 +05:30
|
|
|
subject { described_class.assignable_for(project) }
|
2016-06-22 15:30:34 +05:30
|
|
|
|
|
|
|
it { is_expected.to be_empty }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'does give a specific runner' do
|
2017-09-10 17:25:29 +05:30
|
|
|
subject { described_class.assignable_for(another_project) }
|
2016-06-22 15:30:34 +05:30
|
|
|
|
|
|
|
it { is_expected.to contain_exactly(runner) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with locked runner' do
|
|
|
|
before do
|
|
|
|
runner.update(locked: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'does not give owned runner' do
|
2017-09-10 17:25:29 +05:30
|
|
|
subject { described_class.assignable_for(project) }
|
2016-06-22 15:30:34 +05:30
|
|
|
|
|
|
|
it { is_expected.to be_empty }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'does not give a locked runner' do
|
2017-09-10 17:25:29 +05:30
|
|
|
subject { described_class.assignable_for(another_project) }
|
2016-06-22 15:30:34 +05:30
|
|
|
|
|
|
|
it { is_expected.to be_empty }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-09-25 12:07:36 +05:30
|
|
|
describe "belongs_to_one_project?" do
|
|
|
|
it "returns false if there are two projects runner assigned to" do
|
2018-03-17 18:26:18 +05:30
|
|
|
runner = FactoryBot.create(:ci_runner)
|
|
|
|
project = FactoryBot.create(:project)
|
|
|
|
project1 = FactoryBot.create(:project)
|
2015-09-25 12:07:36 +05:30
|
|
|
project.runners << runner
|
|
|
|
project1.runners << runner
|
|
|
|
|
|
|
|
expect(runner.belongs_to_one_project?).to be_falsey
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns true" do
|
2018-03-17 18:26:18 +05:30
|
|
|
runner = FactoryBot.create(:ci_runner)
|
|
|
|
project = FactoryBot.create(:project)
|
2015-09-25 12:07:36 +05:30
|
|
|
project.runners << runner
|
|
|
|
|
|
|
|
expect(runner.belongs_to_one_project?).to be_truthy
|
|
|
|
end
|
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
|
|
|
|
describe '#has_tags?' do
|
|
|
|
context 'when runner has tags' do
|
|
|
|
subject { create(:ci_runner, tag_list: ['tag']) }
|
|
|
|
it { is_expected.to have_tags }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when runner does not have tags' do
|
|
|
|
subject { create(:ci_runner, tag_list: []) }
|
2016-06-16 23:09:34 +05:30
|
|
|
it { is_expected.not_to have_tags }
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.search' do
|
2018-03-17 18:26:18 +05:30
|
|
|
let(:runner) { create(:ci_runner, token: '123abc', description: 'test runner') }
|
2016-06-02 11:05:42 +05:30
|
|
|
|
|
|
|
it 'returns runners with a matching token' do
|
|
|
|
expect(described_class.search(runner.token)).to eq([runner])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns runners with a partially matching token' do
|
|
|
|
expect(described_class.search(runner.token[0..2])).to eq([runner])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns runners with a matching token regardless of the casing' do
|
|
|
|
expect(described_class.search(runner.token.upcase)).to eq([runner])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns runners with a matching description' do
|
|
|
|
expect(described_class.search(runner.description)).to eq([runner])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns runners with a partially matching description' do
|
|
|
|
expect(described_class.search(runner.description[0..2])).to eq([runner])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns runners with a matching description regardless of the casing' do
|
|
|
|
expect(described_class.search(runner.description.upcase)).to eq([runner])
|
|
|
|
end
|
|
|
|
end
|
2015-09-25 12:07:36 +05:30
|
|
|
end
|