2016-06-16 23:09:34 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2019-01-03 12:48:30 +05:30
|
|
|
describe Gitlab::Ci::Config::Loader do
|
2016-06-16 23:09:34 +05:30
|
|
|
let(:loader) { described_class.new(yml) }
|
|
|
|
|
|
|
|
context 'when yaml syntax is correct' do
|
|
|
|
let(:yml) { 'image: ruby:2.2' }
|
|
|
|
|
|
|
|
describe '#valid?' do
|
|
|
|
it 'returns true' do
|
|
|
|
expect(loader.valid?).to be true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#load!' do
|
|
|
|
it 'returns a valid hash' do
|
|
|
|
expect(loader.load!).to eq(image: 'ruby:2.2')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when yaml syntax is incorrect' do
|
|
|
|
let(:yml) { '// incorrect' }
|
|
|
|
|
|
|
|
describe '#valid?' do
|
|
|
|
it 'returns false' do
|
|
|
|
expect(loader.valid?).to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#load!' do
|
|
|
|
it 'raises error' do
|
|
|
|
expect { loader.load! }.to raise_error(
|
2019-01-03 12:48:30 +05:30
|
|
|
Gitlab::Ci::Config::Loader::FormatError,
|
2016-06-16 23:09:34 +05:30
|
|
|
'Invalid configuration format'
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
context 'when there is an unknown alias' do
|
|
|
|
let(:yml) { 'steps: *bad_alias' }
|
|
|
|
|
|
|
|
describe '#initialize' do
|
|
|
|
it 'raises FormatError' do
|
2019-01-03 12:48:30 +05:30
|
|
|
expect { loader }.to raise_error(Gitlab::Ci::Config::Loader::FormatError, 'Unknown alias: bad_alias')
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-16 23:09:34 +05:30
|
|
|
context 'when yaml config is empty' do
|
|
|
|
let(:yml) { '' }
|
|
|
|
|
|
|
|
describe '#valid?' do
|
|
|
|
it 'returns false' do
|
|
|
|
expect(loader.valid?).to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|