提交 24807014 编写于 作者: G Grzegorz Bizon

Extend CI job entries fabrication and validation

上级 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
if name.to_s.start_with?('.')
Node::HiddenJob
else
Node::Job
end
def job_attributes(name)
@attributes.merge(key: name,
parent: self,
description: "#{name} job definition.")
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,20 +30,16 @@ 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
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)
......@@ -48,7 +49,6 @@ describe Gitlab::Ci::Config::Node::Jobs do
end
end
end
end
context 'when valid job entries processed' do
before { entry.process! }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册