Skip to content
代码片段 群组 项目
提交 cfcf933d 编辑于 作者: Fabio Pitino's avatar Fabio Pitino
浏览文件

Merge branch 'aw-refactor-input-matches' into 'master'

Move self.matches to BaseInput

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/137144



Merged-by: default avatarFabio Pitino <fpitino@gitlab.com>
Approved-by: default avatarFabio Pitino <fpitino@gitlab.com>
Reviewed-by: default avatarFabio Pitino <fpitino@gitlab.com>
Co-authored-by: default avatarAvielle Wolfe <awolfe@gitlab.com>
No related branches found
No related tags found
无相关合并请求
......@@ -10,9 +10,8 @@ class Inputs
class BaseInput
ArgumentNotValidError = Class.new(StandardError)
# Checks whether the class matches the type in the specification
def self.matches?(spec)
raise NotImplementedError
spec.is_a?(Hash) && spec[:type] == type_name
end
# Human readable type used in error messages
......
......@@ -8,10 +8,6 @@ class Inputs
class BooleanInput < BaseInput
extend ::Gitlab::Utils::Override
def self.matches?(spec)
spec.is_a?(Hash) && spec[:type] == type_name
end
def self.type_name
'boolean'
end
......
......@@ -8,10 +8,6 @@ class Inputs
class NumberInput < BaseInput
extend ::Gitlab::Utils::Override
def self.matches?(spec)
spec.is_a?(Hash) && spec[:type] == type_name
end
def self.type_name
'number'
end
......
......@@ -17,7 +17,7 @@ def self.matches?(spec)
# inputs:
# foo:
# ```
spec.nil? || (spec.is_a?(Hash) && [nil, type_name].include?(spec[:type]))
spec.nil? || super || (spec.is_a?(Hash) && !spec.key?(:type))
end
def self.type_name
......
......@@ -4,8 +4,34 @@
RSpec.describe Gitlab::Ci::Config::Interpolation::Inputs::BaseInput, feature_category: :pipeline_composition do
describe '.matches?' do
it 'is not implemented' do
expect { described_class.matches?(double) }.to raise_error(NotImplementedError)
context 'when given is a hash' do
before do
stub_const('TestInput', Class.new(described_class))
TestInput.class_eval do
def self.type_name
'test'
end
end
end
context 'when the spec type matches the input type' do
it 'returns true' do
expect(TestInput.matches?({ type: 'test' })).to be_truthy
end
end
context 'when the spec type does not match the input type' do
it 'returns false' do
expect(TestInput.matches?({ type: 'string' })).to be_falsey
end
end
end
context 'when not given a hash' do
it 'returns false' do
expect(described_class.matches?([])).to be_falsey
end
end
end
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册