Skip to content
Snippets Groups Projects
Commit 4491bf28 authored by Grzegorz Bizon's avatar Grzegorz Bizon
Browse files

Move CI job config validations to new classes

parent 580c4e18
No related branches found
No related tags found
1 merge request!5087Move CI job config entries from legacy to new config
Pipeline #
Loading
Loading
@@ -71,8 +71,6 @@ module Ci
@ci_config.jobs.each do |name, param|
add_job(name, param)
end
raise ValidationError, "Please define at least one job" if @jobs.none?
end
 
def add_job(name, job)
Loading
Loading
Loading
Loading
@@ -24,6 +24,7 @@ module Gitlab
 
compose!
process_nodes!
@validator.validate(:processed)
end
 
def leaf?
Loading
Loading
Loading
Loading
@@ -10,12 +10,27 @@ module Gitlab
 
validations do
validates :config, type: Hash
validate :jobs_presence, on: :processed
def jobs_presence
unless relevant?
errors.add(:config, 'should contain at least one visible job')
end
end
end
 
def nodes
@config
end
 
def relevant?
@nodes.values.any?(&:relevant?)
end
def leaf?
false
end
private
 
def create_node(key, essence)
Loading
Loading
Loading
Loading
@@ -1061,7 +1061,14 @@ EOT
config = YAML.dump({ before_script: ["bundle update"] })
expect do
GitlabCiYamlProcessor.new(config, path)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "Please define at least one job")
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "jobs config should contain at least one visible job")
end
it "returns errors if there are no visible jobs defined" do
config = YAML.dump({ before_script: ["bundle update"], '.hidden'.to_sym => {} })
expect do
GitlabCiYamlProcessor.new(config, path)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "jobs config should contain at least one visible job")
end
 
it "returns errors if job allow_failure parameter is not an boolean" do
Loading
Loading
Loading
Loading
@@ -108,7 +108,10 @@ describe Gitlab::Ci::Config::Node::Global do
end
 
context 'when deprecated types key defined' do
let(:hash) { { types: ['test', 'deploy'] } }
let(:hash) do
{ types: ['test', 'deploy'],
rspec: { script: 'rspec' } }
end
 
it 'returns array of types as stages' do
expect(global.stages).to eq %w[test deploy]
Loading
Loading
@@ -174,7 +177,7 @@ describe Gitlab::Ci::Config::Node::Global do
# details.
#
context 'when entires specified but not defined' do
let(:hash) { { variables: nil } }
let(:hash) { { variables: nil, rspec: { script: 'rspec' } } }
before { global.process! }
 
describe '#variables' do
Loading
Loading
Loading
Loading
@@ -4,17 +4,9 @@ describe Gitlab::Ci::Config::Node::Jobs do
let(:entry) { described_class.new(config) }
 
describe 'validations' do
before { entry.process! }
context 'when entry config value is correct' do
let(:config) { { rspec: { script: 'rspec' } } }
 
describe '#value' do
it 'returns key value' do
expect(entry.value).to eq(rspec: { script: 'rspec' })
end
end
describe '#valid?' do
it 'is valid' do
expect(entry).to be_valid
Loading
Loading
@@ -23,15 +15,34 @@ describe Gitlab::Ci::Config::Node::Jobs do
end
 
context 'when entry value is not correct' do
context 'incorrect config value type' do
let(:config) { ['incorrect'] }
describe '#errors' do
context 'incorrect config value type' do
let(:config) { ['incorrect'] }
 
describe '#errors' do
it 'saves errors' do
it 'returns error about incorrect type' do
expect(entry.errors)
.to include 'jobs config should be a hash'
end
end
context 'when no visible jobs present' do
let(:config) { { '.hidden'.to_sym => {} } }
context 'when not processed' do
it 'is valid' do
expect(entry.errors).to be_empty
end
end
context 'when processed' do
before { entry.process! }
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
end
end
end
Loading
Loading
@@ -45,6 +56,13 @@ describe Gitlab::Ci::Config::Node::Jobs do
'.hidden'.to_sym => {} }
end
 
describe '#value' do
it 'returns key value' do
expect(entry.value).to eq(rspec: { script: 'rspec' },
spinach: { script: 'spinach' })
end
end
describe '#descendants' do
it 'creates valid descendant nodes' do
expect(entry.descendants.count).to eq 3
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment