Commit 6ae80732 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Add ability to define nodes in new CI config entry

parent e00ae9a8
...@@ -26,12 +26,16 @@ module Gitlab ...@@ -26,12 +26,16 @@ module Gitlab
process_nodes! process_nodes!
end end
def leaf?
nodes.none?
end
def nodes def nodes
@nodes.values self.class.nodes
end end
def leaf? def descendants
self.class.nodes.none? @nodes.values
end end
def ancestors def ancestors
...@@ -43,7 +47,7 @@ module Gitlab ...@@ -43,7 +47,7 @@ module Gitlab
end end
def errors def errors
@validator.messages + nodes.flat_map(&:errors) @validator.messages + @nodes.values.flat_map(&:errors)
end end
def value def value
...@@ -73,13 +77,13 @@ module Gitlab ...@@ -73,13 +77,13 @@ module Gitlab
private private
def compose! def compose!
self.class.nodes.each do |key, essence| nodes.each do |key, essence|
@nodes[key] = create_node(key, essence) @nodes[key] = create_node(key, essence)
end end
end end
def process_nodes! def process_nodes!
nodes.each(&:process!) @nodes.each_value(&:process!)
end end
def create_node(key, essence) def create_node(key, essence)
......
...@@ -31,24 +31,24 @@ describe Gitlab::Ci::Config::Node::Global do ...@@ -31,24 +31,24 @@ 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_an Array expect(global.descendants).to be_an Array
end end
it 'creates node object for each entry' do it 'creates node object for each entry' do
expect(global.nodes.count).to eq 9 expect(global.descendants.count).to eq 9
end end
it 'creates node object using valid class' do it 'creates node object using valid class' do
expect(global.nodes.first) expect(global.descendants.first)
.to be_an_instance_of Gitlab::Ci::Config::Node::Script .to be_an_instance_of Gitlab::Ci::Config::Node::Script
expect(global.nodes.second) expect(global.descendants.second)
.to be_an_instance_of Gitlab::Ci::Config::Node::Image .to be_an_instance_of Gitlab::Ci::Config::Node::Image
end end
it 'sets correct description for nodes' do it 'sets correct description for nodes' do
expect(global.nodes.first.description) expect(global.descendants.first.description)
.to eq 'Script that will be executed before each job.' .to eq 'Script that will be executed before each job.'
expect(global.nodes.second.description) expect(global.descendants.second.description)
.to eq 'Docker image that will be used to execute jobs.' .to eq 'Docker image that will be used to execute jobs.'
end end
end end
...@@ -139,11 +139,11 @@ describe Gitlab::Ci::Config::Node::Global do ...@@ -139,11 +139,11 @@ describe Gitlab::Ci::Config::Node::Global do
describe '#nodes' do describe '#nodes' do
it 'instantizes all nodes' do it 'instantizes all nodes' do
expect(global.nodes.count).to eq 9 expect(global.descendants.count).to eq 9
end end
it 'contains undefined nodes' do it 'contains undefined nodes' do
expect(global.nodes.first) expect(global.descendants.first)
.to be_an_instance_of Gitlab::Ci::Config::Node::Undefined .to be_an_instance_of Gitlab::Ci::Config::Node::Undefined
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