diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-06-06 11:54:54 +0200 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-06-06 11:59:25 +0200 |
commit | a3c0745514ad98df1fbb8a6142f6cc50df76edae (patch) | |
tree | 3c20328efc1bde7795aba52f3a5613a7f15105d2 | |
parent | 6dbd1c86a82156dd5ad39b0e2ad119a493dadeae (diff) | |
download | gitlab-ce-a3c0745514ad98df1fbb8a6142f6cc50df76edae.tar.gz |
Collect errors from all nodes in new CI config
-rw-r--r-- | lib/gitlab/ci/config/node/entry.rb | 18 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/node/global_spec.rb | 25 |
2 files changed, 38 insertions, 5 deletions
diff --git a/lib/gitlab/ci/config/node/entry.rb b/lib/gitlab/ci/config/node/entry.rb index 3220b01ca1a..45475316539 100644 --- a/lib/gitlab/ci/config/node/entry.rb +++ b/lib/gitlab/ci/config/node/entry.rb @@ -5,7 +5,7 @@ module Gitlab class Entry include Config::ValidationHelpers - attr_reader :value, :config, :parent, :nodes, :errors + attr_reader :value, :parent def initialize(value, config, parent = nil) @value = value @@ -21,8 +21,20 @@ module Gitlab @nodes[key] = entry.new(@value[key], config, self) end - @nodes.values.each(&:process!) - @nodes.values.each(&:validate!) + nodes.each(&:process!) + nodes.each(&:validate!) + end + + def errors + @errors + nodes.map(&:errors).flatten + end + + def valid? + errors.none? + end + + def nodes + @nodes.values end def keys diff --git a/spec/lib/gitlab/ci/config/node/global_spec.rb b/spec/lib/gitlab/ci/config/node/global_spec.rb index e2e8fcfabd3..4b464db35be 100644 --- a/spec/lib/gitlab/ci/config/node/global_spec.rb +++ b/spec/lib/gitlab/ci/config/node/global_spec.rb @@ -19,7 +19,7 @@ describe Gitlab::Ci::Config::Node::Global do before { global.process! } it 'creates nodes hash' do - expect(global.nodes).to be_a Hash + expect(global.nodes).to be_an Array end it 'creates node object for each entry' do @@ -27,9 +27,30 @@ describe Gitlab::Ci::Config::Node::Global do end 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 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 |