2018-11-20 20:47:30 +05:30
|
|
|
require 'fast_spec_helper'
|
|
|
|
|
|
|
|
require_dependency 'active_model'
|
2016-06-16 23:09:34 +05:30
|
|
|
|
|
|
|
describe Gitlab::Ci::Config do
|
|
|
|
let(:config) do
|
|
|
|
described_class.new(yml)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when config is valid' do
|
|
|
|
let(:yml) do
|
|
|
|
<<-EOS
|
|
|
|
image: ruby:2.2
|
|
|
|
|
|
|
|
rspec:
|
|
|
|
script:
|
|
|
|
- gem install rspec
|
|
|
|
- rspec
|
|
|
|
EOS
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#to_hash' do
|
|
|
|
it 'returns hash created from string' do
|
|
|
|
hash = {
|
|
|
|
image: 'ruby:2.2',
|
|
|
|
rspec: {
|
|
|
|
script: ['gem install rspec',
|
|
|
|
'rspec']
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(config.to_hash).to eq hash
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#valid?' do
|
|
|
|
it 'is valid' do
|
|
|
|
expect(config).to be_valid
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has no errors' do
|
|
|
|
expect(config.errors).to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|
2016-06-16 23:09:34 +05:30
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
context 'when using extendable hash' do
|
|
|
|
let(:yml) do
|
|
|
|
<<-EOS
|
|
|
|
image: ruby:2.2
|
|
|
|
|
|
|
|
rspec:
|
|
|
|
script: rspec
|
|
|
|
|
|
|
|
test:
|
|
|
|
extends: rspec
|
|
|
|
image: ruby:alpine
|
|
|
|
EOS
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'correctly extends the hash' do
|
|
|
|
hash = {
|
|
|
|
image: 'ruby:2.2',
|
|
|
|
rspec: { script: 'rspec' },
|
|
|
|
test: {
|
|
|
|
extends: 'rspec',
|
|
|
|
image: 'ruby:alpine',
|
|
|
|
script: 'rspec'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(config).to be_valid
|
|
|
|
expect(config.to_hash).to eq hash
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
context 'when config is invalid' do
|
|
|
|
context 'when yml is incorrect' do
|
|
|
|
let(:yml) { '// invalid' }
|
2016-06-16 23:09:34 +05:30
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
describe '.new' do
|
|
|
|
it 'raises error' do
|
|
|
|
expect { config }.to raise_error(
|
2018-11-20 20:47:30 +05:30
|
|
|
described_class::ConfigError,
|
2016-08-24 12:49:21 +05:30
|
|
|
/Invalid configuration format/
|
|
|
|
)
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
end
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|
2016-06-16 23:09:34 +05:30
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
context 'when config logic is incorrect' do
|
|
|
|
let(:yml) { 'before_script: "ls"' }
|
2016-06-16 23:09:34 +05:30
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
describe '#valid?' do
|
|
|
|
it 'is not valid' do
|
|
|
|
expect(config).not_to be_valid
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has errors' do
|
|
|
|
expect(config.errors).not_to be_empty
|
|
|
|
end
|
|
|
|
end
|
2016-06-16 23:09:34 +05:30
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
describe '#errors' do
|
|
|
|
it 'returns an array of strings' do
|
|
|
|
expect(config.errors).to all(be_an_instance_of(String))
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-11-20 20:47:30 +05:30
|
|
|
|
|
|
|
context 'when invalid extended hash has been provided' do
|
|
|
|
let(:yml) do
|
|
|
|
<<-EOS
|
|
|
|
test:
|
|
|
|
extends: test
|
|
|
|
script: rspec
|
|
|
|
EOS
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'raises an error' do
|
|
|
|
expect { config }.to raise_error(
|
|
|
|
described_class::ConfigError, /circular dependency detected/
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
end
|