Commit a3c07455 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Collect errors from all nodes in new CI config

parent 6dbd1c86
...@@ -5,7 +5,7 @@ module Gitlab ...@@ -5,7 +5,7 @@ module Gitlab
class Entry class Entry
include Config::ValidationHelpers include Config::ValidationHelpers
attr_reader :value, :config, :parent, :nodes, :errors attr_reader :value, :parent
def initialize(value, config, parent = nil) def initialize(value, config, parent = nil)
@value = value @value = value
...@@ -21,8 +21,20 @@ module Gitlab ...@@ -21,8 +21,20 @@ module Gitlab
@nodes[key] = entry.new(@value[key], config, self) @nodes[key] = entry.new(@value[key], config, self)
end end
@nodes.values.each(&:process!) nodes.each(&:process!)
@nodes.values.each(&:validate!) nodes.each(&:validate!)
end
def errors
@errors + nodes.map(&:errors).flatten
end
def valid?
errors.none?
end
def nodes
@nodes.values
end end
def keys def keys
......
...@@ -19,7 +19,7 @@ describe Gitlab::Ci::Config::Node::Global do ...@@ -19,7 +19,7 @@ describe Gitlab::Ci::Config::Node::Global do
before { global.process! } before { global.process! }
it 'creates nodes hash' do it 'creates nodes hash' do
expect(global.nodes).to be_a Hash expect(global.nodes).to be_an Array
end end
it 'creates node object for each entry' do it 'creates node object for each entry' do
...@@ -27,9 +27,30 @@ describe Gitlab::Ci::Config::Node::Global do ...@@ -27,9 +27,30 @@ describe Gitlab::Ci::Config::Node::Global do
end end
it 'creates node object using valid class' do it 'creates node object using valid class' do
expect(global.nodes[:before_script]) expect(global.nodes.first)
.to be_an_instance_of Gitlab::Ci::Config::Node::BeforeScript .to be_an_instance_of Gitlab::Ci::Config::Node::BeforeScript
end end
end end
end end
context 'when hash is not valid' do
let(:hash) do
{ before_script: 'ls' }
end
before { global.process! }
describe '#valid?' do
it 'is not valid' do
expect(global).not_to be_valid
end
end
describe '#errors' do
it 'reports errors from child nodes' do
expect(global.errors)
.to include 'before_script should be an array of strings'
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