Improve extended CI/CD config specs and fix a bug

This commit is contained in:
Grzegorz Bizon 2018-08-17 12:53:04 +02:00
parent a24d4b3c67
commit d5eff68576
4 changed files with 13 additions and 11 deletions

View file

@ -10,7 +10,7 @@ module Gitlab
CircularDependencyError = Class.new(ExtensionError)
def initialize(hash)
@hash = hash.deep_dup
@hash = hash.to_h.deep_dup
each { |entry| entry.extend! if entry.extensible? }
end

View file

@ -40,16 +40,17 @@ module Gitlab
if unknown_extension?
raise Extendable::Collection::InvalidExtensionError,
'Unknown extension!'
"Unknown extends key in extended `#{key}`!"
end
if invalid_base?
raise Extendable::Collection::InvalidExtensionError,
'Invalid base hash!'
"Invalid base hash in extended `#{key}`!"
end
if circular_dependency?
raise Extendable::Collection::CircularDependencyError
raise Extendable::Collection::CircularDependencyError,
"Circular dependency detected in extended `#{key}`!"
end
@context[key] = base_hash!.deep_merge(value)
@ -62,7 +63,7 @@ module Gitlab
end
def unknown_extension?
!@context.key?(key)
!@context.key?(extends_key)
end
def invalid_base?

View file

@ -179,7 +179,7 @@ describe Gitlab::Ci::Config::Extendable::Collection do
end
end
context 'when extensible entry has non-hash inheritace defined' do
context 'when extensible entry has non-hash inheritance defined' do
let(:hash) do
{
test: {

View file

@ -115,13 +115,13 @@ describe Gitlab::Ci::Config::Extendable::Entry do
let(:hash) do
{
first: 'my value',
second: { extends: 'first' },
test: { extends: 'second' }
test: { extends: 'first' }
}
end
it 'raises an error' do
expect { subject.extend! }.to raise_error(StandardError)
expect { subject.extend! }
.to raise_error(StandardError, /Invalid base hash/)
end
end
@ -131,7 +131,8 @@ describe Gitlab::Ci::Config::Extendable::Entry do
end
it 'raises an error' do
expect { subject.extend! }.to raise_error(StandardError)
expect { subject.extend! }
.to raise_error(StandardError, /Unknown extends key/)
end
end
@ -177,7 +178,7 @@ describe Gitlab::Ci::Config::Extendable::Entry do
end
it 'does not mutate orignal context' do
original = hash.dup
original = hash.deep_dup
subject.extend!