Commit 8048dcc8 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Implement CI configuration nodes tree processing

parent 7f2f683e
......@@ -3,8 +3,11 @@ module Gitlab
class Config
module Node
class BeforeScript < Entry
def leaf?
true
def keys
{}
end
def validate!
end
end
end
......
......@@ -3,14 +3,32 @@ module Gitlab
class Config
module Node
class Entry
attr_reader :hash, :config, :parent, :nodes, :errors
def initialize(hash, config, parent = nil)
@hash = hash
@config = config
@parent = parent
@nodes = {}
@errors = []
end
def process!
keys.each_pair do |key, entry|
next unless hash.include?(key)
@nodes[key] = entry.new(hash[key], config, self)
end
@nodes.values.each(&:process!)
@nodes.values.each(&:validate!)
end
def keys
raise NotImplementedError
end
def allowed_keys
[]
def validate!
raise NotImplementedError
end
end
end
......
......@@ -3,6 +3,9 @@ module Gitlab
class Config
module Node
class Global < Entry
def keys
{ before_script: BeforeScript }
end
end
end
end
......
......@@ -2,10 +2,4 @@ require 'spec_helper'
describe Gitlab::Ci::Config::Node::BeforeScript do
let(:entry) { described_class.new(hash, config) }
describe '#leaf?' do
it 'is a leaf entry' do
expect(entry).to be_leaf
end
end
end
require 'spec_helper'
describe Gitlab::Ci::Config::Node::Global do
let(:global) { described_class.new(hash, config) }
let(:config) { double('Config') }
describe '#keys' do
it 'can contain global config keys' do
expect(global.keys).to include :before_script
end
end
context 'when hash is valid' do
let(:hash) do
{ before_script: ['ls', 'pwd'] }
end
describe '#process!' do
before { global.process! }
it 'creates nodes hash' do
expect(global.nodes).to be_a Hash
end
it 'creates node object for each entry' do
expect(global.nodes.count).to eq 1
end
it 'creates node object using valid class' do
expect(global.nodes[:before_script])
.to be_an_instance_of Gitlab::Ci::Config::Node::BeforeScript
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