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