Commit 39ec62ea authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'fix/improve-naming-convention-in-ci-config' into 'master'

Improve naming convention in ci configuration module

## What does this MR do?

This MR improves the naming convention in CI configuration module to reflect the domain design better.

## What are the relevant issue numbers?

Related to #15060

See merge request !7448
parents 763a89a3 b3f38797
...@@ -2,7 +2,7 @@ module Ci ...@@ -2,7 +2,7 @@ module Ci
class GitlabCiYamlProcessor class GitlabCiYamlProcessor
class ValidationError < StandardError; end class ValidationError < StandardError; end
include Gitlab::Ci::Config::Node::LegacyValidationHelpers include Gitlab::Ci::Config::Entry::LegacyValidationHelpers
attr_reader :path, :cache, :stages, :jobs attr_reader :path, :cache, :stages, :jobs
......
...@@ -13,7 +13,7 @@ module Gitlab ...@@ -13,7 +13,7 @@ module Gitlab
def initialize(config) def initialize(config)
@config = Loader.new(config).load! @config = Loader.new(config).load!
@global = Node::Global.new(@config) @global = Entry::Global.new(@config)
@global.compose! @global.compose!
end end
......
module Gitlab module Gitlab
module Ci module Ci
class Config class Config
module Node module Entry
## ##
# Entry that represents a configuration of job artifacts. # Entry that represents a configuration of job artifacts.
# #
class Artifacts < Entry class Artifacts < Node
include Validatable include Validatable
include Attributable include Attributable
......
module Gitlab module Gitlab
module Ci module Ci
class Config class Config
module Node module Entry
module Attributable module Attributable
extend ActiveSupport::Concern extend ActiveSupport::Concern
......
module Gitlab module Gitlab
module Ci module Ci
class Config class Config
module Node module Entry
## ##
# Entry that represents a boolean value. # Entry that represents a boolean value.
# #
class Boolean < Entry class Boolean < Node
include Validatable include Validatable
validations do validations do
......
module Gitlab module Gitlab
module Ci module Ci
class Config class Config
module Node module Entry
## ##
# Entry that represents a cache configuration # Entry that represents a cache configuration
# #
class Cache < Entry class Cache < Node
include Configurable include Configurable
ALLOWED_KEYS = %i[key untracked paths] ALLOWED_KEYS = %i[key untracked paths]
...@@ -14,13 +14,13 @@ module Gitlab ...@@ -14,13 +14,13 @@ module Gitlab
validates :config, allowed_keys: ALLOWED_KEYS validates :config, allowed_keys: ALLOWED_KEYS
end end
node :key, Node::Key, entry :key, Entry::Key,
description: 'Cache key used to define a cache affinity.' description: 'Cache key used to define a cache affinity.'
node :untracked, Node::Boolean, entry :untracked, Entry::Boolean,
description: 'Cache all untracked files.' description: 'Cache all untracked files.'
node :paths, Node::Paths, entry :paths, Entry::Paths,
description: 'Specify which paths should be cached across builds.' description: 'Specify which paths should be cached across builds.'
end end
end end
......
module Gitlab module Gitlab
module Ci module Ci
class Config class Config
module Node module Entry
## ##
# Entry that represents a job script. # Entry that represents a job script.
# #
class Commands < Entry class Commands < Node
include Validatable include Validatable
validations do validations do
......
module Gitlab module Gitlab
module Ci module Ci
class Config class Config
module Node module Entry
## ##
# This mixin is responsible for adding DSL, which purpose is to # This mixin is responsible for adding DSL, which purpose is to
# simplifly process of adding child nodes. # simplifly process of adding child nodes.
...@@ -48,8 +48,8 @@ module Gitlab ...@@ -48,8 +48,8 @@ module Gitlab
private # rubocop:disable Lint/UselessAccessModifier private # rubocop:disable Lint/UselessAccessModifier
def node(key, node, metadata) def entry(key, entry, metadata)
factory = Node::Factory.new(node) factory = Entry::Factory.new(entry)
.with(description: metadata[:description]) .with(description: metadata[:description])
(@nodes ||= {}).merge!(key.to_sym => factory) (@nodes ||= {}).merge!(key.to_sym => factory)
......
module Gitlab module Gitlab
module Ci module Ci
class Config class Config
module Node module Entry
## ##
# Entry that represents an environment. # Entry that represents an environment.
# #
class Environment < Entry class Environment < Node
include Validatable include Validatable
ALLOWED_KEYS = %i[name url action on_stop] ALLOWED_KEYS = %i[name url action on_stop]
......
module Gitlab module Gitlab
module Ci module Ci
class Config class Config
module Node module Entry
## ##
# Factory class responsible for fabricating node entry objects. # Factory class responsible for fabricating entry objects.
# #
class Factory class Factory
class InvalidFactory < StandardError; end class InvalidFactory < StandardError; end
def initialize(node) def initialize(entry)
@node = node @entry = entry
@metadata = {} @metadata = {}
@attributes = {} @attributes = {}
end end
...@@ -37,11 +37,11 @@ module Gitlab ...@@ -37,11 +37,11 @@ module Gitlab
# See issue #18775. # See issue #18775.
# #
if @value.nil? if @value.nil?
Node::Unspecified.new( Entry::Unspecified.new(
fabricate_unspecified fabricate_unspecified
) )
else else
fabricate(@node, @value) fabricate(@entry, @value)
end end
end end
...@@ -49,21 +49,21 @@ module Gitlab ...@@ -49,21 +49,21 @@ module Gitlab
def fabricate_unspecified def fabricate_unspecified
## ##
# If node has a default value we fabricate concrete node # If entry has a default value we fabricate concrete node
# with default value. # with default value.
# #
if @node.default.nil? if @entry.default.nil?
fabricate(Node::Undefined) fabricate(Entry::Undefined)
else else
fabricate(@node, @node.default) fabricate(@entry, @entry.default)
end end
end end
def fabricate(node, value = nil) def fabricate(entry, value = nil)
node.new(value, @metadata).tap do |entry| entry.new(value, @metadata).tap do |node|
entry.key = @attributes[:key] node.key = @attributes[:key]
entry.parent = @attributes[:parent] node.parent = @attributes[:parent]
entry.description = @attributes[:description] node.description = @attributes[:description]
end end
end end
end end
......
module Gitlab module Gitlab
module Ci module Ci
class Config class Config
module Node module Entry
## ##
# This class represents a global entry - root node for entire # This class represents a global entry - root Entry for entire
# GitLab CI Configuration file. # GitLab CI Configuration file.
# #
class Global < Entry class Global < Node
include Configurable include Configurable
node :before_script, Node::Script, entry :before_script, Entry::Script,
description: 'Script that will be executed before each job.' description: 'Script that will be executed before each job.'
node :image, Node::Image, entry :image, Entry::Image,
description: 'Docker image that will be used to execute jobs.' description: 'Docker image that will be used to execute jobs.'
node :services, Node::Services, entry :services, Entry::Services,
description: 'Docker images that will be linked to the container.' description: 'Docker images that will be linked to the container.'
node :after_script, Node::Script, entry :after_script, Entry::Script,
description: 'Script that will be executed after each job.' description: 'Script that will be executed after each job.'
node :variables, Node::Variables, entry :variables, Entry::Variables,
description: 'Environment variables that will be used.' description: 'Environment variables that will be used.'
node :stages, Node::Stages, entry :stages, Entry::Stages,
description: 'Configuration of stages for this pipeline.' description: 'Configuration of stages for this pipeline.'
node :types, Node::Stages, entry :types, Entry::Stages,
description: 'Deprecated: stages for this pipeline.' description: 'Deprecated: stages for this pipeline.'
node :cache, Node::Cache, entry :cache, Entry::Cache,
description: 'Configure caching between build jobs.' description: 'Configure caching between build jobs.'
helpers :before_script, :image, :services, :after_script, helpers :before_script, :image, :services, :after_script,
...@@ -46,7 +46,7 @@ module Gitlab ...@@ -46,7 +46,7 @@ module Gitlab
private private
def compose_jobs! def compose_jobs!
factory = Node::Factory.new(Node::Jobs) factory = Entry::Factory.new(Entry::Jobs)
.value(@config.except(*self.class.nodes.keys)) .value(@config.except(*self.class.nodes.keys))
.with(key: :jobs, parent: self, .with(key: :jobs, parent: self,
description: 'Jobs definition for this pipeline') description: 'Jobs definition for this pipeline')
......
module Gitlab module Gitlab
module Ci module Ci
class Config class Config
module Node module Entry
## ##
# Entry that represents a hidden CI/CD job. # Entry that represents a hidden CI/CD key.
# #
class Hidden < Entry class Hidden < Node
include Validatable include Validatable
validations do validations do
......
module Gitlab module Gitlab
module Ci module Ci
class Config class Config
module Node module Entry
## ##
# Entry that represents a Docker image. # Entry that represents a Docker image.
# #
class Image < Entry class Image < Node
include Validatable include Validatable
validations do validations do
......
module Gitlab module Gitlab
module Ci module Ci
class Config class Config
module Node module Entry
## ##
# Entry that represents a concrete CI/CD job. # Entry that represents a concrete CI/CD job.
# #
class Job < Entry class Job < Node
include Configurable include Configurable
include Attributable include Attributable
...@@ -34,43 +34,43 @@ module Gitlab ...@@ -34,43 +34,43 @@ module Gitlab
end end
end end
node :before_script, Node::Script, entry :before_script, Entry::Script,
description: 'Global before script overridden in this job.' description: 'Global before script overridden in this job.'
node :script, Node::Commands, entry :script, Entry::Commands,
description: 'Commands that will be executed in this job.' description: 'Commands that will be executed in this job.'
node :stage, Node::Stage, entry :stage, Entry::Stage,
description: 'Pipeline stage this job will be executed into.' description: 'Pipeline stage this job will be executed into.'
node :type, Node::Stage, entry :type, Entry::Stage,
description: 'Deprecated: stage this job will be executed into.' description: 'Deprecated: stage this job will be executed into.'
node :after_script, Node::Script, entry :after_script, Entry::Script,
description: 'Commands that will be executed when finishing job.' description: 'Commands that will be executed when finishing job.'
node :cache, Node::Cache, entry :cache, Entry::Cache,
description: 'Cache definition for this job.' description: 'Cache definition for this job.'
node :image, Node::Image, entry :image, Entry::Image,
description: 'Image that will be used to execute this job.' description: 'Image that will be used to execute this job.'
node :services, Node::Services, entry :services, Entry::Services,
description: 'Services that will be used to execute this job.' description: 'Services that will be used to execute this job.'
node :only, Node::Trigger, entry :only, Entry::Trigger,
description: 'Refs policy this job will be executed for.' description: 'Refs policy this job will be executed for.'
node :except, Node::Trigger, entry :except, Entry::Trigger,
description: 'Refs policy this job will be executed for.' description: 'Refs policy this job will be executed for.'
node :variables, Node::Variables, entry :variables, Entry::Variables,
description: 'Environment variables available for this job.' description: 'Environment variables available for this job.'
node :artifacts, Node::Artifacts, entry :artifacts, Entry::Artifacts,
description: 'Artifacts configuration for this job.' description: 'Artifacts configuration for this job.'
node :environment, Node::Environment, entry :environment, Entry::Environment,
description: 'Environment configuration for this job.' description: 'Environment configuration for this job.'
helpers :before_script, :script, :stage, :type, :after_script, helpers :before_script, :script, :stage, :type, :after_script,
......
module Gitlab module Gitlab
module Ci module Ci
class Config class Config
module Node module Entry
## ##
# Entry that represents a set of jobs. # Entry that represents a set of jobs.
# #
class Jobs < Entry class Jobs < Node
include Validatable include Validatable
validations do validations do
...@@ -29,9 +29,9 @@ module Gitlab ...@@ -29,9 +29,9 @@ module Gitlab
def compose!(deps = nil) def compose!(deps = nil)
super do super do
@config.each do |name, config| @config.each do |name, config|
node = hidden?(name) ? Node::Hidden : Node::Job node = hidden?(name) ? Entry::Hidden : Entry::Job
factory = Node::Factory.new(node) factory = Entry::Factory.new(node)
.value(config || {}) .value(config || {})
.metadata(name: name) .metadata(name: name)
.with(key: name, parent: self, .with(key: name, parent: self,
......
module Gitlab module Gitlab
module Ci module Ci
class Config class Config
module Node module Entry
## ##
# Entry that represents a key. # Entry that represents a key.
# #
class Key < Entry class Key < Node
include Validatable include Validatable
validations do validations do
......
module Gitlab module Gitlab
module Ci module Ci
class Config class Config
module Node module Entry
module LegacyValidationHelpers module LegacyValidationHelpers
private private
......
module Gitlab module Gitlab
module Ci module Ci
class Config class Config
module Node module Entry
## ##
# Base abstract class for each configuration entry node. # Base abstract class for each configuration entry node.
# #
class Entry class Node
class InvalidError < StandardError; end class InvalidError < StandardError; end
attr_reader :config, :metadata attr_reader :config, :metadata
...@@ -21,7 +21,7 @@ module Gitlab ...@@ -21,7 +21,7 @@ module Gitlab
end end
def [](key) def [](key)
@entries[key] || Node::Undefined.new @entries[key] || Entry::Undefined.new
end end
def compose!(deps = nil) def compose!(deps = nil)
......
module Gitlab module Gitlab
module Ci module Ci
class Config class Config
module Node module Entry
## ##
# Entry that represents an array of paths. # Entry that represents an array of paths.
# #
class Paths < Entry class Paths < Node
include Validatable include Validatable
validations do validations do
......
module Gitlab module Gitlab
module Ci module Ci
class Config class Config
module Node module Entry
## ##
# Entry that represents a script. # Entry that represents a script.
# #
class Script < Entry class Script < Node
include Validatable include Validatable
validations do validations do
......
module Gitlab module Gitlab
module Ci module Ci
class Config class Config
module Node module Entry
## ##
# Entry that represents a configuration of Docker services. # Entry that represents a configuration of Docker services.
# #
class Services < Entry class Services < Node
include Validatable include Validatable
validations do validations do
......
module Gitlab module Gitlab
module Ci module Ci
class Config class Config
module Node module Entry
## ##
# Entry that represents a stage for a job. # Entry that represents a stage for a job.
# #
class Stage < Entry class Stage < Node
include Validatable include Validatable
validations do validations do
......
module Gitlab module Gitlab
module Ci module Ci
class Config class Config
module Node module Entry
## ##
# Entry that represents a configuration for pipeline stages. # Entry that represents a configuration for pipeline stages.
# #
class Stages < Entry class Stages < Node
include Validatable include Validatable
validations do validations do
......
module Gitlab module Gitlab
module Ci module Ci
class Config class Config
module Node module Entry
## ##
# Entry that represents a trigger policy for the job. # Entry that represents a trigger policy for the job.
# #
class Trigger < Entry class Trigger < Node
include Validatable include Validatable
validations do validations do
......
module Gitlab module Gitlab
module Ci module Ci
class Config class Config
module Node module Entry
## ##
# This class represents an undefined node. # This class represents an undefined entry.
# #
# Implements the Null Object pattern. class Undefined < Node
#
class Undefined < Entry
def initialize(*) def initialize(*)
super(nil) super(nil)
end end
......
module Gitlab module Gitlab
module Ci module Ci
class Config class Config
module Node module Entry
## ##
# This class represents an unspecified entry node. # This class represents an unspecified entry.
# #
# It decorates original entry adding method that indicates it is # It decorates original entry adding method that indicates it is
# unspecified. # unspecified.
......
module Gitlab module Gitlab
module Ci module Ci
class Config class Config
module Node module Entry
module Validatable module Validatable
extend ActiveSupport::Concern extend ActiveSupport::Concern
class_methods do class_methods do
def validator def validator
@validator ||= Class.new(Node::Validator).tap do |validator| @validator ||= Class.new(Entry::Validator).tap do |validator|
if defined?(@validations) if defined?(@validations)
@validations.each { |rules| validator.class_eval(&rules) } @validations.each { |rules| validator.class_eval(&rules) }
end end
......
module Gitlab module Gitlab
module Ci module Ci
class Config class Config
module Node module Entry
class Validator < SimpleDelegator class Validator < SimpleDelegator
include ActiveModel::Validations include ActiveModel::Validations
include Node::Validators include Entry::Validators
def initialize(node) def initialize(entry)
super(node) super(entry)
@node = node @entry = entry
end end
def messages def messages
...@@ -30,7 +30,7 @@ module Gitlab ...@@ -30,7 +30,7 @@ module Gitlab
def key_name def key_name
if key.blank? if key.blank?
@node.class.name.demodulize.underscore.humanize @entry.class.name.demodulize.underscore.humanize
else else
key key
end end
......
module Gitlab module Gitlab
module Ci module Ci
class Config class Config
module Node module Entry
module Validators module Validators
class AllowedKeysValidator < ActiveModel::EachValidator class AllowedKeysValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value) def validate_each(record, attribute, value)
......
module Gitlab module Gitlab
module Ci module Ci
class Config class Config
module Node module Entry
## ##
# Entry that represents environment variables. # Entry that represents environment variables.
# #
class Variables < Entry class Variables < Node
include Validatable include Validatable
validations do validations do
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::Ci::Config::Node::Artifacts do describe Gitlab::Ci::Config::Entry::Artifacts do
let(:entry) { described_class.new(config) } let(:entry) { described_class.new(config) }
describe 'validation' do describe 'validation' do
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::Ci::Config::Node::Attributable do describe Gitlab::Ci::Config::Entry::Attributable do
let(:node) { Class.new } let(:node) { Class.new }
let(:instance) { node.new } let(:instance) { node.new }
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::Ci::Config::Node::Boolean do describe Gitlab::Ci::Config::Entry::Boolean do
let(:entry) { described_class.new(config) } let(:entry) { described_class.new(config) }
describe 'validations' do describe 'validations' do
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::Ci::Config::Node::Cache do describe Gitlab::Ci::Config::Entry::Cache do
let(:entry) { described_class.new(config) } let(:entry) { described_class.new(config) }
describe 'validations' do describe 'validations' do
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::Ci::Config::Node::Commands do describe Gitlab::Ci::Config::Entry::Commands do
let(:entry) { described_class.new(config) } let(:entry) { described_class.new(config) }
context 'when entry config value is an array' do context 'when entry config value is an array' do
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::Ci::Config::Node::Configurable do describe Gitlab::Ci::Config::Entry::Configurable do
let(:node) { Class.new } let(:entry) { Class.new }
before do before do
node.include(described_class) entry.include(described_class)
end end
describe 'validations' do describe 'validations' do
let(:validator) { node.validator.new(instance) } let(:validator) { entry.validator.new(instance) }
before do before do
node.class_eval do entry.class_eval do
attr_reader :config attr_reader :config
def initialize(config) def initialize(config)
...@@ -22,16 +22,16 @@ describe Gitlab::Ci::Config::Node::Configurable do ...@@ -22,16 +22,16 @@ describe Gitlab::Ci::Config::Node::Configurable do
validator.validate validator.validate
end end
context 'when node validator is invalid' do context 'when entry validator is invalid' do
let(:instance) { node.new('ls') } let(:instance) { entry.new('ls') }
it 'returns invalid validator' do it 'returns invalid validator' do
expect(validator).to be_invalid expect(validator).to be_invalid
end end
end end
context 'when node instance is valid' do context 'when entry instance is valid' do
let(:instance) { node.new(key: 'value') } let(:instance) { entry.new(key: 'value') }
it 'returns valid validator' do it 'returns valid validator' do
expect(validator).to be_valid expect(validator).to be_valid
...@@ -39,26 +39,26 @@ describe Gitlab::Ci::Config::Node::Configurable do ...@@ -39,26 +39,26 @@ describe Gitlab::Ci::Config::Node::Configurable do
end end
end end
describe 'configured nodes' do describe 'configured entries' do
before do before do
node.class_eval do entry.class_eval do
node :object, Object, description: 'test object' entry :object, Object, description: 'test object'
end end
end end
describe '.nodes' do describe '.nodes' do
it 'has valid nodes' do it 'has valid nodes' do
expect(node.nodes).to include :object expect(entry.nodes).to include :object
end end
it 'creates a node factory' do it 'creates a node factory' do
expect(node.nodes[:object]) expect(entry.nodes[:object])
.to be_an_instance_of Gitlab::Ci::Config::Node::Factory .to be_an_instance_of Gitlab::Ci::Config::Entry::Factory
end end
it 'returns a duplicated factory object' do it 'returns a duplicated factory object' do
first_factory = node.nodes[:object] first_factory = entry.nodes[:object]
second_factory = node.nodes[:object] second_factory = entry.nodes[:object]
expect(first_factory).not_to be_equal(second_factory) expect(first_factory).not_to be_equal(second_factory)
end end
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::Ci::Config::Node::Environment do describe Gitlab::Ci::Config::Entry::Environment do
let(:entry) { described_class.new(config) } let(:entry) { described_class.new(config) }
before { entry.compose! } before { entry.compose! }
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::Ci::Config::Node::Factory do describe Gitlab::Ci::Config::Entry::Factory do
describe '#create!' do describe '#create!' do
let(:factory) { described_class.new(node) } let(:factory) { described_class.new(entry) }
let(:node) { Gitlab::Ci::Config::Node::Script } let(:entry) { Gitlab::Ci::Config::Entry::Script }
context 'when setting a concrete value' do context 'when setting a concrete value' do
it 'creates entry with valid value' do it 'creates entry with valid value' do
...@@ -54,7 +54,7 @@ describe Gitlab::Ci::Config::Node::Factory do ...@@ -54,7 +54,7 @@ describe Gitlab::Ci::Config::Node::Factory do
context 'when not setting a value' do context 'when not setting a value' do
it 'raises error' do it 'raises error' do
expect { factory.create! }.to raise_error( expect { factory.create! }.to raise_error(
Gitlab::Ci::Config::Node::Factory::InvalidFactory Gitlab::Ci::Config::Entry::Factory::InvalidFactory
) )
end end
end end
...@@ -66,12 +66,12 @@ describe Gitlab::Ci::Config::Node::Factory do ...@@ -66,12 +66,12 @@ describe Gitlab::Ci::Config::Node::Factory do
.create! .create!
expect(entry) expect(entry)
.to be_an_instance_of Gitlab::Ci::Config::Node::Unspecified .to be_an_instance_of Gitlab::Ci::Config::Entry::Unspecified
end end
end end
context 'when passing metadata' do context 'when passing metadata' do
let(:node) { spy('node') } let(:entry) { spy('entry') }
it 'passes metadata as a parameter' do it 'passes metadata as a parameter' do
factory factory
...@@ -79,7 +79,7 @@ describe Gitlab::Ci::Config::Node::Factory do ...@@ -79,7 +79,7 @@ describe Gitlab::Ci::Config::Node::Factory do
.metadata(some: 'hash') .metadata(some: 'hash')
.create! .create!
expect(node).to have_received(:new) expect(entry).to have_received(:new)
.with('some value', { some: 'hash' }) .with('some value', { some: 'hash' })
end end
end end
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::Ci::Config::Node::Global do describe Gitlab::Ci::Config::Entry::Global do
let(:global) { described_class.new(hash) } let(:global) { described_class.new(hash) }
describe '.nodes' do describe '.nodes' do
...@@ -40,9 +40,9 @@ describe Gitlab::Ci::Config::Node::Global do ...@@ -40,9 +40,9 @@ describe Gitlab::Ci::Config::Node::Global do
it 'creates node object using valid class' do it 'creates node object using valid class' do
expect(global.descendants.first) expect(global.descendants.first)
.to be_an_instance_of Gitlab::Ci::Config::Node::Script .to be_an_instance_of Gitlab::Ci::Config::Entry::Script
expect(global.descendants.second) expect(global.descendants.second)
.to be_an_instance_of Gitlab::Ci::Config::Node::Image .to be_an_instance_of Gitlab::Ci::Config::Entry::Image
end end
it 'sets correct description for nodes' do it 'sets correct description for nodes' do
...@@ -181,7 +181,7 @@ describe Gitlab::Ci::Config::Node::Global do ...@@ -181,7 +181,7 @@ describe Gitlab::Ci::Config::Node::Global do
it 'contains unspecified nodes' do it 'contains unspecified nodes' do
expect(global.descendants.first) expect(global.descendants.first)
.to be_an_instance_of Gitlab::Ci::Config::Node::Unspecified .to be_an_instance_of Gitlab::Ci::Config::Entry::Unspecified
end end
end end
...@@ -284,7 +284,7 @@ describe Gitlab::Ci::Config::Node::Global do ...@@ -284,7 +284,7 @@ describe Gitlab::Ci::Config::Node::Global do
context 'when node exists' do context 'when node exists' do
it 'returns correct entry' do it 'returns correct entry' do
expect(global[:cache]) expect(global[:cache])
.to be_an_instance_of Gitlab::Ci::Config::Node::Cache .to be_an_instance_of Gitlab::Ci::Config::Entry::Cache
expect(global[:jobs][:rspec][:script].value).to eq ['ls'] expect(global[:jobs][:rspec][:script].value).to eq ['ls']
end end
end end
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::Ci::Config::Node::Hidden do describe Gitlab::Ci::Config::Entry::Hidden do
let(:entry) { described_class.new(config) } let(:entry) { described_class.new(config) }
describe 'validations' do describe 'validations' do
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::Ci::Config::Node::Image do describe Gitlab::Ci::Config::Entry::Image do
let(:entry) { described_class.new(config) } let(:entry) { described_class.new(config) }
describe 'validation' do describe 'validation' do
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::Ci::Config::Node::Job do describe Gitlab::Ci::Config::Entry::Job do
let(:entry) { described_class.new(config, name: :rspec) } let(:entry) { described_class.new(config, name: :rspec) }
describe 'validations' do describe 'validations' do
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::Ci::Config::Node::Jobs do describe Gitlab::Ci::Config::Entry::Jobs do
let(:entry) { described_class.new(config) } let(:entry) { described_class.new(config) }
describe 'validations' do describe 'validations' do
...@@ -74,9 +74,9 @@ describe Gitlab::Ci::Config::Node::Jobs do ...@@ -74,9 +74,9 @@ describe Gitlab::Ci::Config::Node::Jobs do
it 'creates valid descendant nodes' do it 'creates valid descendant nodes' do
expect(entry.descendants.count).to eq 3 expect(entry.descendants.count).to eq 3
expect(entry.descendants.first(2)) expect(entry.descendants.first(2))
.to all(be_an_instance_of(Gitlab::Ci::Config::Node::Job)) .to all(be_an_instance_of(Gitlab::Ci::Config::Entry::Job))
expect(entry.descendants.last) expect(entry.descendants.last)
.to be_an_instance_of(Gitlab::Ci::Config::Node::Hidden) .to be_an_instance_of(Gitlab::Ci::Config::Entry::Hidden)
end end
end end
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::Ci::Config::Node::Key do describe Gitlab::Ci::Config::Entry::Key do
let(:entry) { described_class.new(config) } let(:entry) { described_class.new(config) }
describe 'validations' do describe 'validations' do
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::Ci::Config::Node::Paths do describe Gitlab::Ci::Config::Entry::Paths do
let(:entry) { described_class.new(config) } let(:entry) { described_class.new(config) }
describe 'validations' do describe 'validations' do
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::Ci::Config::Node::Script do describe Gitlab::Ci::Config::Entry::Script do
let(:entry) { described_class.new(config) } let(:entry) { described_class.new(config) }
describe 'validations' do describe 'validations' do
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::Ci::Config::Node::Services do describe Gitlab::Ci::Config::Entry::Services do
let(:entry) { described_class.new(config) } let(:entry) { described_class.new(config) }
describe 'validations' do describe 'validations' do
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::Ci::Config::Node::Stage do describe Gitlab::Ci::Config::Entry::Stage do
let(:stage) { described_class.new(config) } let(:stage) { described_class.new(config) }
describe 'validations' do describe 'validations' do
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::Ci::Config::Node::Stages do describe Gitlab::Ci::Config::Entry::Stages do
let(:entry) { described_class.new(config) } let(:entry) { described_class.new(config) }
describe 'validations' do describe 'validations' do
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::Ci::Config::Node::Trigger do describe Gitlab::Ci::Config::Entry::Trigger do
let(:entry) { described_class.new(config) } let(:entry) { described_class.new(config) }
describe 'validations' do describe 'validations' do
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::Ci::Config::Node::Undefined do describe Gitlab::Ci::Config::Entry::Undefined do
let(:entry) { described_class.new } let(:entry) { described_class.new }
describe '#leaf?' do describe '#leaf?' do
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::Ci::Config::Node::Unspecified do describe Gitlab::Ci::Config::Entry::Unspecified do
let(:unspecified) { described_class.new(entry) } let(:unspecified) { described_class.new(entry) }
let(:entry) { spy('Entry') } let(:entry) { spy('Entry') }
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::Ci::Config::Node::Validatable do describe Gitlab::Ci::Config::Entry::Validatable do
let(:node) { Class.new } let(:entry) { Class.new }
before do before do
node.include(described_class) entry.include(described_class)
end end
describe '.validator' do describe '.validator' do
before do before do
node.class_eval do entry.class_eval do
attr_accessor :test_attribute attr_accessor :test_attribute
validations do validations do
...@@ -19,34 +19,34 @@ describe Gitlab::Ci::Config::Node::Validatable do ...@@ -19,34 +19,34 @@ describe Gitlab::Ci::Config::Node::Validatable do
end end
it 'returns validator' do it 'returns validator' do
expect(node.validator.superclass) expect(entry.validator.superclass)
.to be Gitlab::Ci::Config::Node::Validator .to be Gitlab::Ci::Config::Entry::Validator
end end
it 'returns only one validator to mitigate leaks' do it 'returns only one validator to mitigate leaks' do
expect { node.validator }.not_to change { node.validator } expect { entry.validator }.not_to change { entry.validator }
end end
context 'when validating node instance' do context 'when validating entry instance' do
let(:node_instance) { node.new } let(:entry_instance) { entry.new }
context 'when attribute is valid' do context 'when attribute is valid' do
before do before do
node_instance.test_attribute = 'valid' entry_instance.test_attribute = 'valid'
end end
it 'instance of validator is valid' do it 'instance of validator is valid' do
expect(node.validator.new(node_instance)).to be_valid expect(entry.validator.new(entry_instance)).to be_valid
end end
end end
context 'when attribute is not valid' do context 'when attribute is not valid' do
before do before do
node_instance.test_attribute = nil entry_instance.test_attribute = nil
end end
it 'instance of validator is invalid' do it 'instance of validator is invalid' do
expect(node.validator.new(node_instance)).to be_invalid expect(entry.validator.new(entry_instance)).to be_invalid
end end
end end
end end
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::Ci::Config::Node::Validator do describe Gitlab::Ci::Config::Entry::Validator do
let(:validator) { Class.new(described_class) } let(:validator) { Class.new(described_class) }
let(:validator_instance) { validator.new(node) } let(:validator_instance) { validator.new(node) }
let(:node) { spy('node') } let(:node) { spy('node') }
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::Ci::Config::Node::Variables do describe Gitlab::Ci::Config::Entry::Variables do
let(:entry) { described_class.new(config) } let(:entry) { described_class.new(config) }
describe 'validations' do describe 'validations' do
......
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