Verified Commit 0ff024d4 authored by Matija Čupić's avatar Matija Čupić
Browse files

Flatten Entry::Script elements

Flattens Entry::Script elements so we can use YAML anchors as part of
the before_script and after_script definition.
parent 9e5117ee
......@@ -11,7 +11,11 @@ module Gitlab
include ::Gitlab::Config::Entry::Validatable
 
validations do
validates :config, array_of_strings: true
validates :config, array_of_strings_or_arrays_of_strings: true
end
def value
config.flatten
end
end
end
......
......@@ -6,7 +6,7 @@ describe Gitlab::Ci::Config::Entry::Script do
let(:entry) { described_class.new(config) }
 
describe 'validations' do
context 'when entry config value is correct' do
context 'when entry config value is array of strings' do
let(:config) { %w(ls pwd) }
 
describe '#value' do
......@@ -28,13 +28,57 @@ describe Gitlab::Ci::Config::Entry::Script do
end
end
 
context 'when entry config value is array of arrays of strings' do
let(:config) { [['ls'], ['pwd', 'echo 1']] }
describe '#value' do
it 'returns array of strings' do
expect(entry.value).to eq ['ls', 'pwd', 'echo 1']
end
end
describe '#errors' do
it 'does not append errors' do
expect(entry.errors).to be_empty
end
end
describe '#valid?' do
it 'is valid' do
expect(entry).to be_valid
end
end
end
context 'when entry config value is array of strings and arrays of strings' do
let(:config) { ['ls', ['pwd', 'echo 1']] }
describe '#value' do
it 'returns array of strings' do
expect(entry.value).to eq ['ls', 'pwd', 'echo 1']
end
end
describe '#errors' do
it 'does not append errors' do
expect(entry.errors).to be_empty
end
end
describe '#valid?' do
it 'is valid' do
expect(entry).to be_valid
end
end
end
context 'when entry value is not correct' do
let(:config) { 'ls' }
 
describe '#errors' do
it 'saves errors' do
expect(entry.errors)
.to include 'script config should be an array of strings'
.to include 'script config should be an array of strings and arrays of strings'
end
end
 
......
......@@ -360,6 +360,19 @@ module Gitlab
expect(subject[:options][:before_script]).to eq(["local script"])
end
end
context 'when script is array of arrays of strings' do
let(:config) do
{
before_script: [["global script", "echo 1"], ["ls"], "pwd"],
test: { script: ["script"] }
}
end
it "return commands with scripts concencaced" do
expect(subject[:options][:before_script]).to eq(["global script", "echo 1", "ls", "pwd"])
end
end
end
 
describe "script" do
......@@ -427,6 +440,19 @@ module Gitlab
expect(subject[:options][:after_script]).to eq(["local after_script"])
end
end
context 'when script is array of arrays of strings' do
let(:config) do
{
after_script: [["global script", "echo 1"], ["ls"], "pwd"],
test: { script: ["script"] }
}
end
it "return commands with scripts concencaced" do
expect(subject[:options][:after_script]).to eq(["global script", "echo 1", "ls", "pwd"])
end
end
end
end
 
......
Supports Markdown
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