Skip to content
Snippets Groups Projects
Commit 940763e0 authored by Grzegorz Bizon's avatar Grzegorz Bizon
Browse files

Use CI config errors from new processor in legacy one

parent a3c07455
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -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
Loading
Loading
@@ -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|
Loading
Loading
@@ -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
Loading
Loading
Loading
Loading
@@ -3,6 +3,8 @@ module Gitlab
class Config
class LoaderError < StandardError; end
 
delegate :valid?, :errors, to: :@global
def initialize(config)
loader = Loader.new(config)
 
Loading
Loading
@@ -11,6 +13,8 @@ module Gitlab
end
 
@config = loader.load
@global = Node::Global.new(@config, self)
@global.process!
end
 
def to_hash
Loading
Loading
Loading
Loading
@@ -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!)
Loading
Loading
Loading
Loading
@@ -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
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment