Commit b0ae0d73 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Use only node factory to create CI config entries

parent 6f02da2c
...@@ -21,25 +21,29 @@ module Gitlab ...@@ -21,25 +21,29 @@ module Gitlab
def create! def create!
raise InvalidFactory unless @attributes.has_key?(:value) raise InvalidFactory unless @attributes.has_key?(:value)
fabricate.tap do |entry|
entry.key = @attributes[:key]
entry.parent = @attributes[:parent]
entry.description = @attributes[:description]
end
end
private
def fabricate
## ##
# We assume that unspecified entry is undefined. # We assume that unspecified entry is undefined.
# See issue #18775. # See issue #18775.
# #
if @attributes[:value].nil? if @attributes[:value].nil?
Node::Undefined.new(@node) fabricate(Node::Undefined, @node)
else else
@node.new(@attributes[:value]) fabricate(@node, @attributes[:value])
end
end end
def self.fabricate(node, value, **attributes)
node.new(value).tap do |entry|
entry.key = attributes[:key]
entry.parent = attributes[:parent]
entry.description = attributes[:description]
end
end
private
def fabricate(node, value)
self.class.fabricate(node, value, @attributes)
end end
end end
end end
......
...@@ -42,8 +42,8 @@ module Gitlab ...@@ -42,8 +42,8 @@ module Gitlab
def initialize(config) def initialize(config)
return super unless config.is_a?(Hash) return super unless config.is_a?(Hash)
jobs = config.except(*self.class.nodes.keys) jobs = config.except(*nodes.keys)
global = config.slice(*self.class.nodes.keys) global = config.slice(*nodes.keys)
super(global.merge(jobs: jobs)) super(global.merge(jobs: jobs))
end end
......
...@@ -33,20 +33,14 @@ module Gitlab ...@@ -33,20 +33,14 @@ module Gitlab
private private
def create_node(key, essence) def create_node(key, value)
fabricate_job(key, essence).tap do |job| node = key.to_s.start_with?('.') ? Node::HiddenJob : Node::Job
job.key = key
job.parent = self
job.description = "#{key} job definition."
end
end
def fabricate_job(key, essence) attributes = { key: key,
if key.to_s.start_with?('.') parent: self,
Node::HiddenJob.new(essence) description: "#{key} job definition." }
else
Node::Job.new(essence) Node::Factory.fabricate(node, value, attributes)
end
end end
end end
end end
......
...@@ -5,6 +5,18 @@ describe Gitlab::Ci::Config::Node::Factory do ...@@ -5,6 +5,18 @@ describe Gitlab::Ci::Config::Node::Factory do
let(:factory) { described_class.new(entry_class) } let(:factory) { described_class.new(entry_class) }
let(:entry_class) { Gitlab::Ci::Config::Node::Script } let(:entry_class) { Gitlab::Ci::Config::Node::Script }
describe '.fabricate' do
it 'fabricates entry with attributes set' do
fabricated = described_class
.fabricate(entry_class, ['ls'],
parent: factory, key: :test)
expect(fabricated.parent).to be factory
expect(fabricated.key).to eq :test
expect(fabricated.value).to eq ['ls']
end
end
context 'when setting up a value' do context 'when setting up a value' do
it 'creates entry with valid value' do it 'creates entry with valid value' do
entry = factory entry = factory
......
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