2016-06-03 14:54:33 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2016-06-06 02:20:55 -04:00
|
|
|
describe Gitlab::Ci::Config::Loader do
|
|
|
|
let(:loader) { described_class.new(yml) }
|
2016-06-03 14:54:33 -04:00
|
|
|
|
|
|
|
context 'when yaml syntax is correct' do
|
|
|
|
let(:yml) { 'image: ruby:2.2' }
|
|
|
|
|
|
|
|
describe '#valid?' do
|
|
|
|
it 'returns true' do
|
2016-06-06 02:20:55 -04:00
|
|
|
expect(loader.valid?).to be true
|
2016-06-03 14:54:33 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-07 06:53:46 -04:00
|
|
|
describe '#load!' do
|
2016-06-03 14:54:33 -04:00
|
|
|
it 'returns a valid hash' do
|
2016-06-07 06:53:46 -04:00
|
|
|
expect(loader.load!).to eq(image: 'ruby:2.2')
|
2016-06-03 14:54:33 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when yaml syntax is incorrect' do
|
|
|
|
let(:yml) { '// incorrect' }
|
|
|
|
|
|
|
|
describe '#valid?' do
|
|
|
|
it 'returns false' do
|
2016-06-06 02:20:55 -04:00
|
|
|
expect(loader.valid?).to be false
|
2016-06-03 14:54:33 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-07 06:53:46 -04:00
|
|
|
describe '#load!' do
|
2016-06-03 14:54:33 -04:00
|
|
|
it 'raises error' do
|
2016-06-07 06:53:46 -04:00
|
|
|
expect { loader.load! }.to raise_error(
|
2016-06-06 02:20:55 -04:00
|
|
|
Gitlab::Ci::Config::Loader::FormatError,
|
2016-06-03 14:54:33 -04:00
|
|
|
'Invalid configuration format'
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-04 21:56:16 -05:00
|
|
|
context 'when there is an unknown alias' do
|
|
|
|
let(:yml) { 'steps: *bad_alias' }
|
|
|
|
|
|
|
|
describe '#initialize' do
|
|
|
|
it 'raises FormatError' do
|
|
|
|
expect { loader }.to raise_error(Gitlab::Ci::Config::Loader::FormatError, 'Unknown alias: bad_alias')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-03 14:54:33 -04:00
|
|
|
context 'when yaml config is empty' do
|
|
|
|
let(:yml) { '' }
|
|
|
|
|
|
|
|
describe '#valid?' do
|
|
|
|
it 'returns false' do
|
2016-06-06 02:20:55 -04:00
|
|
|
expect(loader.valid?).to be false
|
2016-06-03 14:54:33 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|