Validate new before script CI configuration entry
This commit is contained in:
parent
251dd571df
commit
6dbd1c86a8
|
@ -8,6 +8,9 @@ module Gitlab
|
|||
end
|
||||
|
||||
def validate!
|
||||
unless validate_array_of_strings(@value)
|
||||
@errors << 'before_script should be an array of strings'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,10 +3,12 @@ module Gitlab
|
|||
class Config
|
||||
module Node
|
||||
class Entry
|
||||
attr_reader :hash, :config, :parent, :nodes, :errors
|
||||
include Config::ValidationHelpers
|
||||
|
||||
def initialize(hash, config, parent = nil)
|
||||
@hash = hash
|
||||
attr_reader :value, :config, :parent, :nodes, :errors
|
||||
|
||||
def initialize(value, config, parent = nil)
|
||||
@value = value
|
||||
@config = config
|
||||
@parent = parent
|
||||
@nodes = {}
|
||||
|
@ -15,8 +17,8 @@ module Gitlab
|
|||
|
||||
def process!
|
||||
keys.each_pair do |key, entry|
|
||||
next unless hash.include?(key)
|
||||
@nodes[key] = entry.new(hash[key], config, self)
|
||||
next unless @value.include?(key)
|
||||
@nodes[key] = entry.new(@value[key], config, self)
|
||||
end
|
||||
|
||||
@nodes.values.each(&:process!)
|
||||
|
|
|
@ -1,5 +1,27 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Gitlab::Ci::Config::Node::BeforeScript do
|
||||
let(:entry) { described_class.new(hash, config) }
|
||||
let(:entry) { described_class.new(value, config) }
|
||||
let(:config) { double('config') }
|
||||
|
||||
describe '#validate!' do
|
||||
before { entry.validate! }
|
||||
|
||||
context 'when entry value is correct' do
|
||||
let(:value) { ['ls', 'pwd'] }
|
||||
|
||||
it 'does not append errors' do
|
||||
expect(entry.errors).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
context 'when entry value is not correct' do
|
||||
let(:value) { 'ls' }
|
||||
|
||||
it 'saves errors' do
|
||||
expect(entry.errors)
|
||||
.to include /should be an array of strings/
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue