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 ...@@ -14,7 +14,9 @@ module Ci
attr_reader :before_script, :after_script, :image, :services, :path, :cache attr_reader :before_script, :after_script, :image, :services, :path, :cache
def initialize(config, path = nil) 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 @path = path
initial_parsing initial_parsing
...@@ -99,6 +101,10 @@ module Ci ...@@ -99,6 +101,10 @@ module Ci
end end
def validate! def validate!
unless @ci_config.valid?
raise ValidationError, @ci_config.errors.first
end
validate_global! validate_global!
@jobs.each do |name, job| @jobs.each do |name, job|
...@@ -109,10 +115,6 @@ module Ci ...@@ -109,10 +115,6 @@ module Ci
end end
def validate_global! 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) unless @after_script.nil? || validate_array_of_strings(@after_script)
raise ValidationError, "after_script should be an array of strings" raise ValidationError, "after_script should be an array of strings"
end end
......
...@@ -3,6 +3,8 @@ module Gitlab ...@@ -3,6 +3,8 @@ module Gitlab
class Config class Config
class LoaderError < StandardError; end class LoaderError < StandardError; end
delegate :valid?, :errors, to: :@global
def initialize(config) def initialize(config)
loader = Loader.new(config) loader = Loader.new(config)
...@@ -11,6 +13,8 @@ module Gitlab ...@@ -11,6 +13,8 @@ module Gitlab
end end
@config = loader.load @config = loader.load
@global = Node::Global.new(@config, self)
@global.process!
end end
def to_hash def to_hash
......
...@@ -18,7 +18,7 @@ module Gitlab ...@@ -18,7 +18,7 @@ module Gitlab
def process! def process!
keys.each_pair do |key, entry| keys.each_pair do |key, entry|
next unless @value.include?(key) next unless @value.include?(key)
@nodes[key] = entry.new(@value[key], config, self) @nodes[key] = entry.new(@value[key], @config, self)
end end
nodes.each(&:process!) nodes.each(&:process!)
......
...@@ -29,9 +29,20 @@ describe Gitlab::Ci::Config do ...@@ -29,9 +29,20 @@ describe Gitlab::Ci::Config do
expect(config.to_hash).to eq hash expect(config.to_hash).to eq hash
end 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 end
context 'when config is invalid' do context 'when config is invalid' do
context 'when yml is incorrect' do
let(:yml) { '// invalid' } let(:yml) { '// invalid' }
describe '.new' do describe '.new' do
...@@ -43,5 +54,20 @@ describe Gitlab::Ci::Config do ...@@ -43,5 +54,20 @@ describe Gitlab::Ci::Config do
end end
end 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
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