Commit 940763e0 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Use CI config errors from new processor in legacy one

parent a3c07455
......@@ -14,7 +14,9 @@ module Ci
attr_reader :before_script, :after_script, :image, :services, :path, :cache
def initialize(config, path = nil)
@config = Gitlab::Ci::Config.new(config).to_hash
@ci_config = Gitlab::Ci::Config.new(config)
@config = @ci_config.to_hash
@path = path
initial_parsing
......@@ -99,6 +101,10 @@ module Ci
end
def validate!
unless @ci_config.valid?
raise ValidationError, @ci_config.errors.first
end
validate_global!
@jobs.each do |name, job|
......@@ -109,10 +115,6 @@ module Ci
end
def validate_global!
unless validate_array_of_strings(@before_script)
raise ValidationError, "before_script should be an array of strings"
end
unless @after_script.nil? || validate_array_of_strings(@after_script)
raise ValidationError, "after_script should be an array of strings"
end
......
......@@ -3,6 +3,8 @@ module Gitlab
class Config
class LoaderError < StandardError; end
delegate :valid?, :errors, to: :@global
def initialize(config)
loader = Loader.new(config)
......@@ -11,6 +13,8 @@ module Gitlab
end
@config = loader.load
@global = Node::Global.new(@config, self)
@global.process!
end
def to_hash
......
......@@ -18,7 +18,7 @@ module Gitlab
def process!
keys.each_pair do |key, entry|
next unless @value.include?(key)
@nodes[key] = entry.new(@value[key], config, self)
@nodes[key] = entry.new(@value[key], @config, self)
end
nodes.each(&:process!)
......
......@@ -29,17 +29,43 @@ describe Gitlab::Ci::Config do
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
context 'when config is invalid' do
let(:yml) { '// invalid' }
describe '.new' do
it 'raises error' do
expect { config }.to raise_error(
Gitlab::Ci::Config::LoaderError,
/Invalid configuration format/
)
context 'when yml is incorrect' do
let(:yml) { '// invalid' }
describe '.new' do
it 'raises error' do
expect { config }.to raise_error(
Gitlab::Ci::Config::LoaderError,
/Invalid configuration format/
)
end
end
end
context 'when config logic is incorrect' do
let(:yml) { 'before_script: "ls"' }
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
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment