2016-09-13 17:45:13 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
describe Gitlab::Ci::Config::Entry::Jobs do
|
2016-09-13 17:45:13 +05:30
|
|
|
let(:entry) { described_class.new(config) }
|
|
|
|
|
|
|
|
describe 'validations' do
|
2017-09-10 17:25:29 +05:30
|
|
|
before do
|
|
|
|
entry.compose!
|
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
|
|
|
|
context 'when entry config value is correct' do
|
|
|
|
let(:config) { { rspec: { script: 'rspec' } } }
|
|
|
|
|
|
|
|
describe '#valid?' do
|
|
|
|
it 'is valid' do
|
|
|
|
expect(entry).to be_valid
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when entry value is not correct' do
|
|
|
|
describe '#errors' do
|
|
|
|
context 'incorrect config value type' do
|
|
|
|
let(:config) { ['incorrect'] }
|
|
|
|
|
|
|
|
it 'returns error about incorrect type' do
|
|
|
|
expect(entry.errors)
|
|
|
|
.to include 'jobs config should be a hash'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when job is unspecified' do
|
|
|
|
let(:config) { { rspec: nil } }
|
|
|
|
|
|
|
|
it 'reports error' do
|
|
|
|
expect(entry.errors).to include "rspec config can't be blank"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when no visible jobs present' do
|
|
|
|
let(:config) { { '.hidden'.to_sym => { script: [] } } }
|
|
|
|
|
|
|
|
it 'returns error about no visible jobs defined' do
|
|
|
|
expect(entry.errors)
|
|
|
|
.to include 'jobs config should contain at least one visible job'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-29 09:46:39 +05:30
|
|
|
context 'when valid job entries composed' do
|
2017-09-10 17:25:29 +05:30
|
|
|
before do
|
|
|
|
entry.compose!
|
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
|
|
|
|
let(:config) do
|
|
|
|
{ rspec: { script: 'rspec' },
|
|
|
|
spinach: { script: 'spinach' },
|
|
|
|
'.hidden'.to_sym => {} }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#value' do
|
|
|
|
it 'returns key value' do
|
|
|
|
expect(entry.value).to eq(
|
|
|
|
rspec: { name: :rspec,
|
|
|
|
script: %w[rspec],
|
2017-08-17 22:00:37 +05:30
|
|
|
ignore: false,
|
2019-02-13 22:33:31 +05:30
|
|
|
stage: 'test',
|
|
|
|
only: { refs: %w[branches tags] },
|
|
|
|
except: {} },
|
2016-09-13 17:45:13 +05:30
|
|
|
spinach: { name: :spinach,
|
|
|
|
script: %w[spinach],
|
2017-08-17 22:00:37 +05:30
|
|
|
ignore: false,
|
2019-02-13 22:33:31 +05:30
|
|
|
stage: 'test',
|
|
|
|
only: { refs: %w[branches tags] },
|
|
|
|
except: {} })
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#descendants' do
|
|
|
|
it 'creates valid descendant nodes' do
|
|
|
|
expect(entry.descendants.count).to eq 3
|
|
|
|
expect(entry.descendants.first(2))
|
2017-08-17 22:00:37 +05:30
|
|
|
.to all(be_an_instance_of(Gitlab::Ci::Config::Entry::Job))
|
2016-09-13 17:45:13 +05:30
|
|
|
expect(entry.descendants.last)
|
2017-08-17 22:00:37 +05:30
|
|
|
.to be_an_instance_of(Gitlab::Ci::Config::Entry::Hidden)
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#value' do
|
|
|
|
it 'returns value of visible jobs only' do
|
|
|
|
expect(entry.value.keys).to eq [:rspec, :spinach]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|