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