Commit 24807014 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Extend CI job entries fabrication and validation

parent a80a01e8
......@@ -38,6 +38,7 @@ module Gitlab
def initialize(*)
super
@global = self
end
......
......@@ -10,6 +10,7 @@ module Gitlab
validations do
validates :config, type: Hash
validates :config, presence: true
end
def relevant?
......
......@@ -8,6 +8,10 @@ module Gitlab
class Job < Entry
include Configurable
validations do
validates :config, presence: true
end
node :stage, Stage,
description: 'Pipeline stage this job will be executed into.'
......
......@@ -30,17 +30,19 @@ module Gitlab
private
def create(name, config)
job_node(name).new(config, job_attributes(name))
Node::Factory.new(job_node(name))
.value(config || {})
.with(key: name, parent: self, global: @global)
.with(description: "#{name} job definition.")
.create!
end
def job_node(name)
name.to_s.start_with?('.') ? Node::HiddenJob : Node::Job
end
def job_attributes(name)
@attributes.merge(key: name,
parent: self,
description: "#{name} job definition.")
if name.to_s.start_with?('.')
Node::HiddenJob
else
Node::Job
end
end
end
end
......
......@@ -137,7 +137,7 @@ describe Gitlab::Ci::Config::Node::Global do
end
context 'when most of entires not defined' do
let(:hash) { { cache: { key: 'a' }, rspec: {} } }
let(:hash) { { cache: { key: 'a' }, rspec: { script: %w[ls] } } }
before { global.process! }
describe '#nodes' do
......
......@@ -31,6 +31,16 @@ describe Gitlab::Ci::Config::Node::HiddenJob do
end
end
end
context 'when config is empty' do
let(:config) { {} }
describe '#valid' do
it 'is invalid' do
expect(entry).not_to be_valid
end
end
end
end
end
......
......@@ -39,6 +39,16 @@ describe Gitlab::Ci::Config::Node::Job do
end
end
end
context 'when config is empty' do
let(:config) { {} }
describe '#valid' do
it 'is invalid' do
expect(entry).not_to be_valid
end
end
end
end
end
......
......@@ -4,6 +4,11 @@ describe Gitlab::Ci::Config::Node::Jobs do
let(:entry) { described_class.new(config, global: spy) }
describe 'validations' do
before do
entry.process!
entry.validate!
end
context 'when entry config value is correct' do
let(:config) { { rspec: { script: 'rspec' } } }
......@@ -25,25 +30,20 @@ describe Gitlab::Ci::Config::Node::Jobs do
end
end
context 'when no visible jobs present' do
let(:config) { { '.hidden'.to_sym => {} } }
context 'when job is unspecified' do
let(:config) { { rspec: nil } }
context 'when not processed' do
it 'is valid' do
expect(entry.errors).to be_empty
end
it 'is not valid' do
expect(entry).not_to be_valid
end
end
context 'when processed' do
before do
entry.process!
entry.validate!
end
context 'when no visible jobs present' do
let(:config) { { '.hidden'.to_sym => { script: [] } } }
it 'returns error about no visible jobs defined' do
expect(entry.errors)
.to include 'jobs config should contain at least one visible job'
end
it 'returns error about no visible jobs defined' do
expect(entry.errors)
.to include 'jobs config should contain at least one visible job'
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