2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Gitlab::Ci::Config::Entry::Default do
|
2021-06-08 01:23:25 +05:30
|
|
|
let(:config) { {} }
|
2019-09-30 21:07:59 +05:30
|
|
|
let(:entry) { described_class.new(config) }
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
it_behaves_like 'with inheritable CI config' do
|
|
|
|
let(:inheritable_key) { nil }
|
|
|
|
let(:inheritable_class) { Gitlab::Ci::Config::Entry::Root }
|
|
|
|
|
|
|
|
# These are entries defined in Root
|
|
|
|
# that we know that we don't want to inherit
|
|
|
|
# as they do not have sense in context of Default
|
|
|
|
let(:ignored_inheritable_columns) do
|
|
|
|
%i[default include variables stages types workflow]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
describe '.nodes' do
|
|
|
|
it 'returns a hash' do
|
|
|
|
expect(described_class.nodes).to be_a(Hash)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when filtering all the entry/node names' do
|
|
|
|
it 'contains the expected node names' do
|
|
|
|
expect(described_class.nodes.keys)
|
|
|
|
.to match_array(%i[before_script image services
|
2020-01-01 13:55:28 +05:30
|
|
|
after_script cache interruptible
|
|
|
|
timeout retry tags artifacts])
|
2019-09-30 21:07:59 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'validations' do
|
|
|
|
before do
|
|
|
|
entry.compose!
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when default entry value is correct' do
|
|
|
|
let(:config) { { before_script: ['rspec'] } }
|
|
|
|
|
|
|
|
describe '#valid?' do
|
|
|
|
it 'is valid' do
|
|
|
|
expect(entry).to be_valid
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when default entry is empty' do
|
|
|
|
let(:config) { {} }
|
|
|
|
|
|
|
|
describe '#valid' do
|
|
|
|
it 'is valid' do
|
|
|
|
expect(entry).to be_valid
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when default entry 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 'default config should be a hash'
|
|
|
|
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
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#compose!' do
|
|
|
|
let(:specified) do
|
|
|
|
double('specified', 'specified?' => true, value: 'specified')
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:unspecified) { double('unspecified', 'specified?' => false) }
|
|
|
|
let(:deps) { double('deps', '[]' => unspecified) }
|
|
|
|
|
|
|
|
context 'when default entry inherits configuration from root' do
|
|
|
|
let(:config) do
|
|
|
|
{ image: 'some_image' }
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(deps).to receive('[]').with(:image).and_return(specified)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'raises error' do
|
|
|
|
expect { entry.compose!(deps) }.to raise_error(
|
2019-12-26 22:10:19 +05:30
|
|
|
Gitlab::Ci::Config::Entry::Default::InheritError)
|
2019-09-30 21:07:59 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when default entry inherits a non-defined configuration from root' do
|
|
|
|
let(:config) do
|
|
|
|
{ image: 'some_image' }
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(deps).to receive('[]').with(:after_script).and_return(specified)
|
|
|
|
|
|
|
|
entry.compose!(deps)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'inherits non-defined configuration entries' do
|
|
|
|
expect(entry[:image].value).to eq(name: 'some_image')
|
|
|
|
expect(entry[:after_script].value).to eq('specified')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|