diff options
-rw-r--r-- | lib/gitlab/ci/config/node/before_script.rb | 7 | ||||
-rw-r--r-- | lib/gitlab/ci/config/node/entry.rb | 22 | ||||
-rw-r--r-- | lib/gitlab/ci/config/node/global.rb | 3 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/node/before_script_spec.rb | 6 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/node/global_spec.rb | 30 |
5 files changed, 58 insertions, 10 deletions
diff --git a/lib/gitlab/ci/config/node/before_script.rb b/lib/gitlab/ci/config/node/before_script.rb index bf73c01efbc..88ebd6bb304 100644 --- a/lib/gitlab/ci/config/node/before_script.rb +++ b/lib/gitlab/ci/config/node/before_script.rb @@ -3,8 +3,11 @@ module Gitlab class Config module Node class BeforeScript < Entry - def leaf? - true + def keys + {} + end + + def validate! end end end diff --git a/lib/gitlab/ci/config/node/entry.rb b/lib/gitlab/ci/config/node/entry.rb index eb1b52a3e5d..6336535bc03 100644 --- a/lib/gitlab/ci/config/node/entry.rb +++ b/lib/gitlab/ci/config/node/entry.rb @@ -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 diff --git a/lib/gitlab/ci/config/node/global.rb b/lib/gitlab/ci/config/node/global.rb index b3dd6df0a44..81a9d0667be 100644 --- a/lib/gitlab/ci/config/node/global.rb +++ b/lib/gitlab/ci/config/node/global.rb @@ -3,6 +3,9 @@ module Gitlab class Config module Node class Global < Entry + def keys + { before_script: BeforeScript } + end end end end diff --git a/spec/lib/gitlab/ci/config/node/before_script_spec.rb b/spec/lib/gitlab/ci/config/node/before_script_spec.rb index eb86931c586..d4a8eea3fff 100644 --- a/spec/lib/gitlab/ci/config/node/before_script_spec.rb +++ b/spec/lib/gitlab/ci/config/node/before_script_spec.rb @@ -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 diff --git a/spec/lib/gitlab/ci/config/node/global_spec.rb b/spec/lib/gitlab/ci/config/node/global_spec.rb index 89594fa20ce..e2e8fcfabd3 100644 --- a/spec/lib/gitlab/ci/config/node/global_spec.rb +++ b/spec/lib/gitlab/ci/config/node/global_spec.rb @@ -1,5 +1,35 @@ 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 |