Commit c019585c authored by Grzegorz Bizon's avatar Grzegorz Bizon

Validate interface only with CI node validator

parent 56e88b8c
......@@ -8,30 +8,33 @@ module Gitlab
class Cache < Entry
include Configurable
node :key, Key,
description: 'Cache key used to define a cache affinity.'
node :untracked, Boolean,
description: 'Cache all untracked files.'
node :paths, Paths,
description: 'Specify which paths should be cached across builds.'
validations do
validate :allowed_keys
validate :keys
def unknown_keys
return [] unless @node.config.is_a?(Hash)
@node.config.keys - @node.class.nodes.keys
return [] unless config.is_a?(Hash)
config.keys - allowed_keys
end
def allowed_keys
def keys
if unknown_keys.any?
errors.add(:config, "contains unknown keys #{unknown_keys}")
end
end
end
node :key, Node::Key,
description: 'Cache key used to define a cache affinity.'
node :untracked, Boolean,
description: 'Cache all untracked files.'
node :paths, Paths,
description: 'Specify which paths should be cached across builds.'
def allowed_keys
self.class.nodes.keys
end
end
end
end
......
......@@ -8,12 +8,11 @@ module Gitlab
def initialize(node)
super(node)
@node = node
end
def messages
errors.full_messages.map do |error|
"#{@node.key} #{error}".humanize
"#{key} #{error}".humanize
end
end
......
......@@ -5,7 +5,13 @@ describe Gitlab::Ci::Config::Node::Validator do
let(:validator_instance) { validator.new(node) }
let(:node) { spy('node') }
shared_examples 'delegated validator' do
describe 'delegated validator' do
before do
validator.class_eval do
validates :test_attribute, presence: true
end
end
context 'when node is valid' do
before do
allow(node).to receive(:test_attribute).and_return('valid value')
......@@ -40,28 +46,4 @@ describe Gitlab::Ci::Config::Node::Validator do
end
end
end
describe 'attributes validations' do
before do
validator.class_eval do
validates :test_attribute, presence: true
end
end
it_behaves_like 'delegated validator'
end
describe 'interface validations' do
before do
validator.class_eval do
validate do
unless @node.test_attribute == 'valid value'
errors.add(:test_attribute, 'invalid value')
end
end
end
end
it_behaves_like 'delegated validator'
end
end
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