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 ...@@ -105,6 +105,7 @@ module Ci
validate_job_keys!(name, job) validate_job_keys!(name, job)
validate_job_types!(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_variables!(name, job) if job[:variables]
validate_job_cache!(name, job) if job[:cache] validate_job_cache!(name, job) if job[:cache]
validate_job_artifacts!(name, job) if job[:artifacts] validate_job_artifacts!(name, job) if job[:artifacts]
...@@ -153,6 +154,12 @@ module Ci ...@@ -153,6 +154,12 @@ module Ci
end end
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) def validate_job_variables!(name, job)
unless validate_variables(job[:variables]) unless validate_variables(job[:variables])
raise ValidationError, raise ValidationError,
......
...@@ -12,7 +12,6 @@ module Gitlab ...@@ -12,7 +12,6 @@ module Gitlab
validates :config, presence: true validates :config, presence: true
with_options on: :processed do with_options on: :processed do
validates :global, required: true
validates :name, presence: true validates :name, presence: true
validates :name, type: Symbol validates :name, type: Symbol
end end
......
...@@ -10,22 +10,6 @@ module Gitlab ...@@ -10,22 +10,6 @@ module Gitlab
validations do validations do
validates :config, type: String 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 end
def self.default def self.default
......
...@@ -1089,14 +1089,14 @@ EOT ...@@ -1089,14 +1089,14 @@ EOT
config = YAML.dump({ rspec: { script: "test", type: "acceptance" } }) config = YAML.dump({ rspec: { script: "test", type: "acceptance" } })
expect do expect do
GitlabCiYamlProcessor.new(config, path) 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 end
it "returns errors if job stage is not a defined stage" do it "returns errors if job stage is not a defined stage" do
config = YAML.dump({ types: ["build", "test"], rspec: { script: "test", type: "acceptance" } }) config = YAML.dump({ types: ["build", "test"], rspec: { script: "test", type: "acceptance" } })
expect do expect do
GitlabCiYamlProcessor.new(config, path) 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 end
it "returns errors if stages is not an array" do it "returns errors if stages is not an array" do
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::Ci::Config::Node::Stage do describe Gitlab::Ci::Config::Node::Stage do
let(:stage) { described_class.new(config, global: global) } let(:stage) { described_class.new(config) }
let(:global) { spy('Global') }
describe 'validations' do describe 'validations' do
context 'when stage config value is correct' do context 'when stage config value is correct' do
let(:config) { 'build' } let(:config) { 'build' }
before do
allow(global).to receive(:stages).and_return(%w[build])
end
describe '#value' do describe '#value' do
it 'returns a stage key' do it 'returns a stage key' do
expect(stage.value).to eq config expect(stage.value).to eq config
...@@ -25,19 +20,6 @@ describe Gitlab::Ci::Config::Node::Stage do ...@@ -25,19 +20,6 @@ describe Gitlab::Ci::Config::Node::Stage do
end end
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 context 'when value has a wrong type' do
let(:config) { { test: true } } let(:config) { { test: true } }
...@@ -46,47 +28,6 @@ describe Gitlab::Ci::Config::Node::Stage do ...@@ -46,47 +28,6 @@ describe Gitlab::Ci::Config::Node::Stage do
.to include 'stage config should be a string' .to include 'stage config should be a string'
end end
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 end
describe '.default' do 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