Commit 3e16b015 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Revert logical validation in CI job stage entry

parent f7c80e9f
......@@ -105,6 +105,7 @@ module Ci
validate_job_keys!(name, job)
validate_job_types!(name, job)
validate_job_stage!(name, job) if job[:stage]
validate_job_variables!(name, job) if job[:variables]
validate_job_cache!(name, job) if job[:cache]
validate_job_artifacts!(name, job) if job[:artifacts]
......@@ -153,6 +154,12 @@ module Ci
end
end
def validate_job_stage!(name, job)
unless job[:stage].is_a?(String) && job[:stage].in?(@stages)
raise ValidationError, "#{name} job: stage parameter should be #{@stages.join(", ")}"
end
end
def validate_job_variables!(name, job)
unless validate_variables(job[:variables])
raise ValidationError,
......
......@@ -12,7 +12,6 @@ module Gitlab
validates :config, presence: true
with_options on: :processed do
validates :global, required: true
validates :name, presence: true
validates :name, type: Symbol
end
......
......@@ -10,22 +10,6 @@ module Gitlab
validations do
validates :config, type: String
with_options on: :processed do
validates :global, required: true
validate do
unless known?
errors.add(:config,
'should be one of defined stages ' \
"(#{global.stages.join(', ')})")
end
end
end
end
def known?
@global.stages.include?(@config)
end
def self.default
......
......@@ -1089,14 +1089,14 @@ EOT
config = YAML.dump({ rspec: { script: "test", type: "acceptance" } })
expect do
GitlabCiYamlProcessor.new(config, path)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "jobs:rspec:type config should be one of defined stages (build, test, deploy)")
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: stage parameter should be build, test, deploy")
end
it "returns errors if job stage is not a defined stage" do
config = YAML.dump({ types: ["build", "test"], rspec: { script: "test", type: "acceptance" } })
expect do
GitlabCiYamlProcessor.new(config, path)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "jobs:rspec:type config should be one of defined stages (build, test)")
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: stage parameter should be build, test")
end
it "returns errors if stages is not an array" do
......
require 'spec_helper'
describe Gitlab::Ci::Config::Node::Stage do
let(:stage) { described_class.new(config, global: global) }
let(:global) { spy('Global') }
let(:stage) { described_class.new(config) }
describe 'validations' do
context 'when stage config value is correct' do
let(:config) { 'build' }
before do
allow(global).to receive(:stages).and_return(%w[build])
end
describe '#value' do
it 'returns a stage key' do
expect(stage.value).to eq config
......@@ -25,19 +20,6 @@ describe Gitlab::Ci::Config::Node::Stage do
end
end
context 'when stage config is incorrect' do
describe '#errors' do
context 'when reference to global node is not set' do
let(:stage) { described_class.new('test') }
it 'raises error' do
expect { stage.validate! }.to raise_error(
Gitlab::Ci::Config::Node::Entry::InvalidError,
/Entry needs global attribute set internally./
)
end
end
context 'when value has a wrong type' do
let(:config) { { test: true } }
......@@ -46,47 +28,6 @@ describe Gitlab::Ci::Config::Node::Stage do
.to include 'stage config should be a string'
end
end
context 'when stage is not present in global configuration' do
let(:config) { 'unknown' }
before do
allow(global)
.to receive(:stages).and_return(%w[test deploy])
end
it 'reports error about missing stage' do
stage.validate!
expect(stage.errors)
.to include 'stage config should be one of ' \
'defined stages (test, deploy)'
end
end
end
end
end
describe '#known?' do
before do
allow(global).to receive(:stages).and_return(%w[test deploy])
end
context 'when stage is not known' do
let(:config) { :unknown }
it 'returns false' do
expect(stage.known?).to be false
end
end
context 'when stage is known' do
let(:config) { 'test' }
it 'returns false' do
expect(stage.known?).to be true
end
end
end
describe '.default' do
......
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