Commit d5eff685 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Improve extended CI/CD config specs and fix a bug

parent a24d4b3c
......@@ -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
......
......@@ -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?
......
......@@ -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: {
......
......@@ -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!
......
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