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

Add before_script node to CI job entry config

parent 24807014
......@@ -12,20 +12,34 @@ module Gitlab
validates :config, presence: true
end
node :before_script, Script,
description: 'Global before script overridden in this job.'
node :stage, Stage,
description: 'Pipeline stage this job will be executed into.'
node :type, Stage,
description: 'Deprecated: stage this job will be executed into.'
helpers :stage, :type
helpers :before_script, :stage, :type
def value
@config.merge(stage: stage_value)
raise InvalidError unless valid?
##
# TODO, refactoring step: do not expose internal configuration,
# return only hash value without merging it to internal config.
#
@config.merge(to_hash.compact)
end
private
def to_hash
{ before_script: before_script,
stage: stage }
end
def compose!
super
......
......@@ -970,7 +970,7 @@ EOT
config = YAML.dump({ rspec: { script: "test", before_script: [10, "test"] } })
expect do
GitlabCiYamlProcessor.new(config, path)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: before_script should be an array of strings")
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "jobs:rspec:before_script config should be an array of strings")
end
it "returns errors if after_script parameter is invalid" do
......
......@@ -4,23 +4,15 @@ describe Gitlab::Ci::Config::Node::Job do
let(:entry) { described_class.new(config, global: global) }
let(:global) { spy('Global') }
describe 'validations' do
before do
entry.process!
entry.validate!
end
describe 'validations' do
context 'when entry config value is correct' do
let(:config) { { script: 'rspec' } }
describe '#value' do
it 'returns key value' do
expect(entry.value)
.to eq(script: 'rspec',
stage: 'test')
end
end
describe '#valid?' do
it 'is valid' do
expect(entry).to be_valid
......@@ -33,7 +25,7 @@ describe Gitlab::Ci::Config::Node::Job do
let(:config) { ['incorrect'] }
describe '#errors' do
it 'saves errors' do
it 'reports error about a config type' do
expect(entry.errors)
.to include 'job config should be a hash'
end
......@@ -52,6 +44,32 @@ describe Gitlab::Ci::Config::Node::Job do
end
end
describe '#value' do
context 'when entry is correct' do
let(:config) do
{ before_script: %w[ls pwd],
script: 'rspec' }
end
it 'returns correct value' do
expect(entry.value)
.to eq(before_script: %w[ls pwd],
script: 'rspec',
stage: 'test')
end
end
context 'when entry is incorrect' do
let(:config) { {} }
it 'raises error' do
expect { entry.value }.to raise_error(
Gitlab::Ci::Config::Node::Entry::InvalidError
)
end
end
end
describe '#relevant?' do
it 'is a relevant entry' do
expect(entry).to be_relevant
......
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