2018-12-13 13:39:08 +05:30
|
|
|
require 'spec_helper'
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
describe Gitlab::Ci::Config::Entry::Job do
|
2016-09-13 17:45:13 +05:30
|
|
|
let(:entry) { described_class.new(config, name: :rspec) }
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
describe '.nodes' do
|
|
|
|
context 'when filtering all the entry/node names' do
|
|
|
|
subject { described_class.nodes.keys }
|
|
|
|
|
|
|
|
let(:result) do
|
|
|
|
%i[before_script script stage type after_script cache
|
|
|
|
image services only except variables artifacts
|
2018-12-13 13:39:08 +05:30
|
|
|
environment coverage retry]
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to match_array result }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
describe 'validations' do
|
2017-09-10 17:25:29 +05:30
|
|
|
before do
|
|
|
|
entry.compose!
|
|
|
|
end
|
2016-09-29 09:46:39 +05:30
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
context 'when entry config value is correct' do
|
|
|
|
let(:config) { { script: 'rspec' } }
|
|
|
|
|
|
|
|
describe '#valid?' do
|
|
|
|
it 'is valid' do
|
|
|
|
expect(entry).to be_valid
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when job name is empty' do
|
|
|
|
let(:entry) { described_class.new(config, name: ''.to_sym) }
|
|
|
|
|
|
|
|
it 'reports error' do
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(entry.errors).to include "job name can't be blank"
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
end
|
2018-12-05 23:21:45 +05:30
|
|
|
|
|
|
|
context 'when delayed job' do
|
|
|
|
context 'when start_in is specified' do
|
|
|
|
let(:config) { { script: 'echo', when: 'delayed', start_in: '1 day' } }
|
|
|
|
|
|
|
|
it { expect(entry).to be_valid }
|
|
|
|
end
|
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'when entry value is not correct' do
|
|
|
|
context 'incorrect config value type' do
|
|
|
|
let(:config) { ['incorrect'] }
|
|
|
|
|
|
|
|
describe '#errors' do
|
|
|
|
it 'reports error about a config type' do
|
|
|
|
expect(entry.errors)
|
|
|
|
.to include 'job config should be a hash'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when config is empty' do
|
|
|
|
let(:config) { {} }
|
|
|
|
|
|
|
|
describe '#valid' do
|
|
|
|
it 'is invalid' do
|
|
|
|
expect(entry).not_to be_valid
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when unknown keys detected' do
|
|
|
|
let(:config) { { unknown: true } }
|
|
|
|
|
|
|
|
describe '#valid' do
|
|
|
|
it 'is not valid' do
|
|
|
|
expect(entry).not_to be_valid
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
context 'when script is not provided' do
|
|
|
|
let(:config) { { stage: 'test' } }
|
|
|
|
|
|
|
|
it 'returns error about missing script entry' do
|
|
|
|
expect(entry).not_to be_valid
|
|
|
|
expect(entry.errors).to include "job script can't be blank"
|
|
|
|
end
|
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
context 'when extends key is not a string' do
|
|
|
|
let(:config) { { extends: 123 } }
|
|
|
|
|
|
|
|
it 'returns error about wrong value type' do
|
|
|
|
expect(entry).not_to be_valid
|
|
|
|
expect(entry.errors).to include "job extends should be a string"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
context 'when parallel value is not correct' do
|
2017-09-10 17:25:29 +05:30
|
|
|
context 'when it is not a numeric value' do
|
2018-12-13 13:39:08 +05:30
|
|
|
let(:config) { { parallel: true } }
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
it 'returns error about invalid type' do
|
|
|
|
expect(entry).not_to be_valid
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(entry.errors).to include 'job parallel is not a number'
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
context 'when it is lower than two' do
|
|
|
|
let(:config) { { parallel: 1 } }
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
it 'returns error about value too low' do
|
|
|
|
expect(entry).not_to be_valid
|
|
|
|
expect(entry.errors)
|
2018-12-13 13:39:08 +05:30
|
|
|
.to include 'job parallel must be greater than or equal to 2'
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
context 'when it is bigger than 50' do
|
|
|
|
let(:config) { { parallel: 51 } }
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it 'returns error about value too high' do
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(entry).not_to be_valid
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(entry.errors)
|
|
|
|
.to include 'job parallel must be less than or equal to 50'
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
context 'when it is not an integer' do
|
|
|
|
let(:config) { { parallel: 1.5 } }
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
it 'returns error about wrong value' do
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(entry).not_to be_valid
|
2018-12-13 13:39:08 +05:30
|
|
|
expect(entry.errors).to include 'job parallel must be an integer'
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-12-05 23:21:45 +05:30
|
|
|
|
|
|
|
context 'when delayed job' do
|
|
|
|
context 'when start_in is specified' do
|
|
|
|
let(:config) { { script: 'echo', when: 'delayed', start_in: '1 day' } }
|
|
|
|
|
|
|
|
it 'returns error about invalid type' do
|
|
|
|
expect(entry).to be_valid
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when start_in is empty' do
|
|
|
|
let(:config) { { when: 'delayed', start_in: nil } }
|
|
|
|
|
|
|
|
it 'returns error about invalid type' do
|
|
|
|
expect(entry).not_to be_valid
|
|
|
|
expect(entry.errors).to include 'job start in should be a duration'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when start_in is not formatted as a duration' do
|
|
|
|
let(:config) { { when: 'delayed', start_in: 'test' } }
|
|
|
|
|
|
|
|
it 'returns error about invalid type' do
|
|
|
|
expect(entry).not_to be_valid
|
|
|
|
expect(entry.errors).to include 'job start in should be a duration'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when start_in is longer than one day' do
|
|
|
|
let(:config) { { when: 'delayed', start_in: '2 days' } }
|
|
|
|
|
|
|
|
it 'returns error about exceeding the limit' do
|
|
|
|
expect(entry).not_to be_valid
|
|
|
|
expect(entry.errors).to include 'job start in should not exceed the limit'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when start_in specified without delayed specification' do
|
|
|
|
let(:config) { { start_in: '1 day' } }
|
|
|
|
|
|
|
|
it 'returns error about invalid type' do
|
|
|
|
expect(entry).not_to be_valid
|
|
|
|
expect(entry.errors).to include 'job start in must be blank'
|
|
|
|
end
|
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-29 09:46:39 +05:30
|
|
|
describe '#relevant?' do
|
|
|
|
it 'is a relevant entry' do
|
2018-11-20 20:47:30 +05:30
|
|
|
entry = described_class.new({ script: 'rspec' }, name: :rspec)
|
|
|
|
|
2016-09-29 09:46:39 +05:30
|
|
|
expect(entry).to be_relevant
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#compose!' do
|
|
|
|
let(:unspecified) { double('unspecified', 'specified?' => false) }
|
|
|
|
|
|
|
|
let(:specified) do
|
|
|
|
double('specified', 'specified?' => true, value: 'specified')
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:deps) { double('deps', '[]' => unspecified) }
|
|
|
|
|
|
|
|
context 'when job config overrides global config' do
|
2017-09-10 17:25:29 +05:30
|
|
|
before do
|
|
|
|
entry.compose!(deps)
|
|
|
|
end
|
2016-09-29 09:46:39 +05:30
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
let(:config) do
|
2017-08-17 22:00:37 +05:30
|
|
|
{ script: 'rspec', image: 'some_image', cache: { key: 'test' } }
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'overrides global config' do
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(entry[:image].value).to eq(name: 'some_image')
|
|
|
|
expect(entry[:cache].value).to eq(key: 'test', policy: 'pull-push')
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when job config does not override global config' do
|
|
|
|
before do
|
|
|
|
allow(deps).to receive('[]').with(:image).and_return(specified)
|
|
|
|
entry.compose!(deps)
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
|
2016-09-29 09:46:39 +05:30
|
|
|
let(:config) { { script: 'ls', cache: { key: 'test' } } }
|
|
|
|
|
|
|
|
it 'uses config from global entry' do
|
|
|
|
expect(entry[:image].value).to eq 'specified'
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(entry[:cache].value).to eq(key: 'test', policy: 'pull-push')
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-29 09:46:39 +05:30
|
|
|
context 'when composed' do
|
2017-09-10 17:25:29 +05:30
|
|
|
before do
|
|
|
|
entry.compose!
|
|
|
|
end
|
2016-09-29 09:46:39 +05:30
|
|
|
|
|
|
|
describe '#value' do
|
2017-09-10 17:25:29 +05:30
|
|
|
before do
|
|
|
|
entry.compose!
|
|
|
|
end
|
2016-09-29 09:46:39 +05:30
|
|
|
|
|
|
|
context 'when entry is correct' do
|
|
|
|
let(:config) do
|
|
|
|
{ before_script: %w[ls pwd],
|
|
|
|
script: 'rspec',
|
|
|
|
after_script: %w[cleanup] }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns correct value' do
|
|
|
|
expect(entry.value)
|
|
|
|
.to eq(name: :rspec,
|
|
|
|
before_script: %w[ls pwd],
|
|
|
|
script: %w[rspec],
|
|
|
|
stage: 'test',
|
2017-08-17 22:00:37 +05:30
|
|
|
ignore: false,
|
2019-02-13 22:33:31 +05:30
|
|
|
after_script: %w[cleanup],
|
|
|
|
only: { refs: %w[branches tags] },
|
|
|
|
except: {})
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
describe '#manual_action?' do
|
|
|
|
context 'when job is a manual action' do
|
|
|
|
let(:config) { { script: 'deploy', when: 'manual' } }
|
|
|
|
|
|
|
|
it 'is a manual action' do
|
|
|
|
expect(entry).to be_manual_action
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when job is not a manual action' do
|
|
|
|
let(:config) { { script: 'deploy' } }
|
|
|
|
|
|
|
|
it 'is not a manual action' do
|
|
|
|
expect(entry).not_to be_manual_action
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
describe '#delayed?' do
|
|
|
|
context 'when job is a delayed' do
|
|
|
|
let(:config) { { script: 'deploy', when: 'delayed' } }
|
|
|
|
|
|
|
|
it 'is a delayed' do
|
|
|
|
expect(entry).to be_delayed
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when job is not a delayed' do
|
|
|
|
let(:config) { { script: 'deploy' } }
|
|
|
|
|
|
|
|
it 'is not a delayed' do
|
|
|
|
expect(entry).not_to be_delayed
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
describe '#ignored?' do
|
|
|
|
context 'when job is a manual action' do
|
|
|
|
context 'when it is not specified if job is allowed to fail' do
|
|
|
|
let(:config) do
|
|
|
|
{ script: 'deploy', when: 'manual' }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is an ignored job' do
|
|
|
|
expect(entry).to be_ignored
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when job is allowed to fail' do
|
|
|
|
let(:config) do
|
|
|
|
{ script: 'deploy', when: 'manual', allow_failure: true }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is an ignored job' do
|
|
|
|
expect(entry).to be_ignored
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when job is not allowed to fail' do
|
|
|
|
let(:config) do
|
|
|
|
{ script: 'deploy', when: 'manual', allow_failure: false }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is not an ignored job' do
|
|
|
|
expect(entry).not_to be_ignored
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when job is not a manual action' do
|
|
|
|
context 'when it is not specified if job is allowed to fail' do
|
|
|
|
let(:config) { { script: 'deploy' } }
|
|
|
|
|
|
|
|
it 'is not an ignored job' do
|
|
|
|
expect(entry).not_to be_ignored
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when job is allowed to fail' do
|
|
|
|
let(:config) { { script: 'deploy', allow_failure: true } }
|
|
|
|
|
|
|
|
it 'is an ignored job' do
|
|
|
|
expect(entry).to be_ignored
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when job is not allowed to fail' do
|
|
|
|
let(:config) { { script: 'deploy', allow_failure: false } }
|
|
|
|
|
|
|
|
it 'is not an ignored job' do
|
|
|
|
expect(entry).not_to be_ignored
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|