Commit b1b0c18b authored by Grzegorz Bizon's avatar Grzegorz Bizon

Add hidden job in new CI config that is irrelevant

parent dbab56a9
......@@ -54,8 +54,11 @@ module Gitlab
if leaf?
@config
else
defined = @nodes.select { |_key, value| value.defined? }
Hash[defined.map { |key, node| [key, node.value] }]
meaningful = @nodes.select do |_key, value|
value.defined? && value.relevant?
end
Hash[meaningful.map { |key, node| [key, node.value] }]
end
end
......@@ -63,6 +66,10 @@ module Gitlab
true
end
def relevant?
true
end
def self.default
end
......
module Gitlab
module Ci
class Config
module Node
##
# Entry that represents a hidden CI/CD job.
#
class HiddenJob < Entry
include Validatable
validations do
validates :config, type: Hash
end
def relevant?
false
end
end
end
end
end
end
......@@ -19,12 +19,20 @@ module Gitlab
private
def create_node(key, essence)
Node::Job.new(essence).tap do |job|
fabricate_job(key, essence).tap do |job|
job.key = key
job.parent = self
job.description = "#{key} job definition."
end
end
def fabricate_job(key, essence)
if key.to_s.start_with?('.')
Node::HiddenJob.new(essence)
else
Node::Job.new(essence)
end
end
end
end
end
......
......@@ -31,7 +31,7 @@ module Gitlab
def location
predecessors = ancestors.map(&:key).compact
current = key || @node.class.name.demodulize.underscore
current = key || @node.class.name.demodulize.underscore.humanize
predecessors.append(current).join(':')
end
end
......
require 'spec_helper'
describe Gitlab::Ci::Config::Node::HiddenJob do
let(:entry) { described_class.new(config) }
describe 'validations' do
context 'when entry config value is correct' do
let(:config) { { image: 'ruby:2.2' } }
describe '#value' do
it 'returns key value' do
expect(entry.value).to eq(image: 'ruby:2.2')
end
end
describe '#valid?' do
it 'is valid' do
expect(entry).to be_valid
end
end
end
context 'when entry value is not correct' do
context 'incorrect config value type' do
let(:config) { ['incorrect'] }
describe '#errors' do
it 'saves errors' do
expect(entry.errors)
.to include 'hidden job config should be a hash'
end
end
end
end
end
describe '#leaf?' do
it 'is a leaf' do
expect(entry).to be_leaf
end
end
describe '#relevant?' do
it 'is not a relevant entry' do
expect(entry).not_to be_relevant
end
end
end
......@@ -33,4 +33,10 @@ describe Gitlab::Ci::Config::Node::Job do
end
end
end
describe '#relevant?' do
it 'is a relevant entry' do
expect(entry).to be_relevant
end
end
end
......@@ -36,18 +36,29 @@ describe Gitlab::Ci::Config::Node::Jobs do
end
end
describe '#descendants' do
context 'when valid job entries processed' do
before { entry.process! }
let(:config) do
{ rspec: { script: 'rspec' },
spinach: { script: 'spinach' } }
spinach: { script: 'spinach' },
'.hidden'.to_sym => {} }
end
it 'creates two descendant nodes' do
expect(entry.descendants.count).to eq 2
expect(entry.descendants)
.to all(be_an_instance_of(Gitlab::Ci::Config::Node::Job))
describe '#descendants' do
it 'creates valid descendant nodes' do
expect(entry.descendants.count).to eq 3
expect(entry.descendants.first(2))
.to all(be_an_instance_of(Gitlab::Ci::Config::Node::Job))
expect(entry.descendants.last)
.to be_an_instance_of(Gitlab::Ci::Config::Node::HiddenJob)
end
end
describe '#value' do
it 'returns value of visible jobs only' do
expect(entry.value.keys).to eq [:rspec, :spinach]
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