summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2018-08-17 12:53:04 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2018-09-04 14:17:01 +0200
commitd5eff68576361f43e5979bb713ecb823323c24bb (patch)
tree492fb7f829b98d067ff912f0d69626f44c6c5ea4
parenta24d4b3c674452ecb63f5a250b619362cc24630c (diff)
downloadgitlab-ce-d5eff68576361f43e5979bb713ecb823323c24bb.tar.gz
Improve extended CI/CD config specs and fix a bug
-rw-r--r--lib/gitlab/ci/config/extendable/collection.rb2
-rw-r--r--lib/gitlab/ci/config/extendable/entry.rb9
-rw-r--r--spec/lib/gitlab/ci/config/extendable/collection_spec.rb2
-rw-r--r--spec/lib/gitlab/ci/config/extendable/entry_spec.rb11
4 files changed, 13 insertions, 11 deletions
diff --git a/lib/gitlab/ci/config/extendable/collection.rb b/lib/gitlab/ci/config/extendable/collection.rb
index b57b3aa5d47..123219c90f2 100644
--- a/lib/gitlab/ci/config/extendable/collection.rb
+++ b/lib/gitlab/ci/config/extendable/collection.rb
@@ -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
diff --git a/lib/gitlab/ci/config/extendable/entry.rb b/lib/gitlab/ci/config/extendable/entry.rb
index 5b26faaa806..f14d2c1817c 100644
--- a/lib/gitlab/ci/config/extendable/entry.rb
+++ b/lib/gitlab/ci/config/extendable/entry.rb
@@ -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?
diff --git a/spec/lib/gitlab/ci/config/extendable/collection_spec.rb b/spec/lib/gitlab/ci/config/extendable/collection_spec.rb
index 20483800315..a47a49fc03a 100644
--- a/spec/lib/gitlab/ci/config/extendable/collection_spec.rb
+++ b/spec/lib/gitlab/ci/config/extendable/collection_spec.rb
@@ -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: {
diff --git a/spec/lib/gitlab/ci/config/extendable/entry_spec.rb b/spec/lib/gitlab/ci/config/extendable/entry_spec.rb
index 7cc6e3f01f1..39b3aec3165 100644
--- a/spec/lib/gitlab/ci/config/extendable/entry_spec.rb
+++ b/spec/lib/gitlab/ci/config/extendable/entry_spec.rb
@@ -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!