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 ...@@ -12,20 +12,34 @@ module Gitlab
validates :config, presence: true validates :config, presence: true
end end
node :before_script, Script,
description: 'Global before script overridden in this job.'
node :stage, Stage, node :stage, Stage,
description: 'Pipeline stage this job will be executed into.' description: 'Pipeline stage this job will be executed into.'
node :type, Stage, node :type, Stage,
description: 'Deprecated: stage this job will be executed into.' description: 'Deprecated: stage this job will be executed into.'
helpers :stage, :type helpers :before_script, :stage, :type
def value 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 end
private private
def to_hash
{ before_script: before_script,
stage: stage }
end
def compose! def compose!
super super
......
...@@ -970,7 +970,7 @@ EOT ...@@ -970,7 +970,7 @@ EOT
config = YAML.dump({ rspec: { script: "test", before_script: [10, "test"] } }) config = YAML.dump({ rspec: { script: "test", before_script: [10, "test"] } })
expect do expect do
GitlabCiYamlProcessor.new(config, path) 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 end
it "returns errors if after_script parameter is invalid" do it "returns errors if after_script parameter is invalid" do
......
...@@ -4,23 +4,15 @@ describe Gitlab::Ci::Config::Node::Job do ...@@ -4,23 +4,15 @@ describe Gitlab::Ci::Config::Node::Job do
let(:entry) { described_class.new(config, global: global) } let(:entry) { described_class.new(config, global: global) }
let(:global) { spy('Global') } let(:global) { spy('Global') }
describe 'validations' do before do
before do entry.process!
entry.process! entry.validate!
entry.validate! end
end
describe 'validations' do
context 'when entry config value is correct' do context 'when entry config value is correct' do
let(:config) { { script: 'rspec' } } 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 describe '#valid?' do
it 'is valid' do it 'is valid' do
expect(entry).to be_valid expect(entry).to be_valid
...@@ -33,7 +25,7 @@ describe Gitlab::Ci::Config::Node::Job do ...@@ -33,7 +25,7 @@ describe Gitlab::Ci::Config::Node::Job do
let(:config) { ['incorrect'] } let(:config) { ['incorrect'] }
describe '#errors' do describe '#errors' do
it 'saves errors' do it 'reports error about a config type' do
expect(entry.errors) expect(entry.errors)
.to include 'job config should be a hash' .to include 'job config should be a hash'
end end
...@@ -52,6 +44,32 @@ describe Gitlab::Ci::Config::Node::Job do ...@@ -52,6 +44,32 @@ describe Gitlab::Ci::Config::Node::Job do
end end
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 describe '#relevant?' do
it 'is a relevant entry' do it 'is a relevant entry' do
expect(entry).to be_relevant 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