Commit 149c2917 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Improve extended CI/CD config specs and fix a bug

parent c0b67036
...@@ -10,7 +10,7 @@ module Gitlab ...@@ -10,7 +10,7 @@ module Gitlab
CircularDependencyError = Class.new(ExtensionError) CircularDependencyError = Class.new(ExtensionError)
def initialize(hash) def initialize(hash)
@hash = hash.deep_dup @hash = hash.to_h.deep_dup
each { |entry| entry.extend! if entry.extensible? } each { |entry| entry.extend! if entry.extensible? }
end end
......
...@@ -40,16 +40,17 @@ module Gitlab ...@@ -40,16 +40,17 @@ module Gitlab
if unknown_extension? if unknown_extension?
raise Extendable::Collection::InvalidExtensionError, raise Extendable::Collection::InvalidExtensionError,
'Unknown extension!' "Unknown extends key in extended `#{key}`!"
end end
if invalid_base? if invalid_base?
raise Extendable::Collection::InvalidExtensionError, raise Extendable::Collection::InvalidExtensionError,
'Invalid base hash!' "Invalid base hash in extended `#{key}`!"
end end
if circular_dependency? if circular_dependency?
raise Extendable::Collection::CircularDependencyError raise Extendable::Collection::CircularDependencyError,
"Circular dependency detected in extended `#{key}`!"
end end
@context[key] = base_hash!.deep_merge(value) @context[key] = base_hash!.deep_merge(value)
...@@ -62,7 +63,7 @@ module Gitlab ...@@ -62,7 +63,7 @@ module Gitlab
end end
def unknown_extension? def unknown_extension?
!@context.key?(key) !@context.key?(extends_key)
end end
def invalid_base? def invalid_base?
......
...@@ -179,7 +179,7 @@ describe Gitlab::Ci::Config::Extendable::Collection do ...@@ -179,7 +179,7 @@ describe Gitlab::Ci::Config::Extendable::Collection do
end end
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 let(:hash) do
{ {
test: { test: {
......
...@@ -115,13 +115,13 @@ describe Gitlab::Ci::Config::Extendable::Entry do ...@@ -115,13 +115,13 @@ describe Gitlab::Ci::Config::Extendable::Entry do
let(:hash) do let(:hash) do
{ {
first: 'my value', first: 'my value',
second: { extends: 'first' }, test: { extends: 'first' }
test: { extends: 'second' }
} }
end end
it 'raises an error' do it 'raises an error' do
expect { subject.extend! }.to raise_error(StandardError) expect { subject.extend! }
.to raise_error(StandardError, /Invalid base hash/)
end end
end end
...@@ -131,7 +131,8 @@ describe Gitlab::Ci::Config::Extendable::Entry do ...@@ -131,7 +131,8 @@ describe Gitlab::Ci::Config::Extendable::Entry do
end end
it 'raises an error' do it 'raises an error' do
expect { subject.extend! }.to raise_error(StandardError) expect { subject.extend! }
.to raise_error(StandardError, /Unknown extends key/)
end end
end end
...@@ -177,7 +178,7 @@ describe Gitlab::Ci::Config::Extendable::Entry do ...@@ -177,7 +178,7 @@ describe Gitlab::Ci::Config::Extendable::Entry do
end end
it 'does not mutate orignal context' do it 'does not mutate orignal context' do
original = hash.dup original = hash.deep_dup
subject.extend! 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