summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/ci/config/extendable
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2018-08-16 14:48:38 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2018-09-04 14:17:00 +0200
commit58414c143f928aa229ae871541cd35df293d6f54 (patch)
tree445caa501a959f1802ac1727f01b46eb3c80df41 /spec/lib/gitlab/ci/config/extendable
parent5b9a6ca00a023493c750f9d4a3b06729fdc96fff (diff)
downloadgitlab-ce-58414c143f928aa229ae871541cd35df293d6f54.tar.gz
Support recursive `extends:` in `.gitlab-ci.yml`
Diffstat (limited to 'spec/lib/gitlab/ci/config/extendable')
-rw-r--r--spec/lib/gitlab/ci/config/extendable/collection_spec.rb122
1 files changed, 122 insertions, 0 deletions
diff --git a/spec/lib/gitlab/ci/config/extendable/collection_spec.rb b/spec/lib/gitlab/ci/config/extendable/collection_spec.rb
new file mode 100644
index 00000000000..453c7357561
--- /dev/null
+++ b/spec/lib/gitlab/ci/config/extendable/collection_spec.rb
@@ -0,0 +1,122 @@
+require 'fast_spec_helper'
+
+describe Gitlab::Ci::Config::Extendable::Collection do
+ subject { described_class.new(hash) }
+
+ describe '#each' do
+ context 'when there is extendable entry in the hash' do
+ let(:test) do
+ { extends: 'something', only: %w[master] }
+ end
+
+ let(:hash) do
+ { something: { script: 'ls' }, test: test }
+ end
+
+ it 'yields the test hash' do
+ expect { |b| subject.each(&b) }.to yield_control
+ end
+ end
+
+ context 'when not extending using a hash' do
+ let(:hash) do
+ { something: { extends: [1], script: 'ls' } }
+ end
+
+ it 'yields invalid extends as well' do
+ expect { |b| subject.each(&b) }.to yield_control
+ end
+ end
+ end
+
+ describe '#extend!' do
+ context 'when a hash has a single simple extension' do
+ let(:hash) do
+ {
+ something: {
+ script: 'deploy',
+ only: { variables: %w[$SOMETHING] }
+ },
+
+ test: {
+ extends: 'something',
+ script: 'ls',
+ only: { refs: %w[master] }
+ }
+ }
+ end
+
+ it 'extends a hash with a deep reverse merge' do
+ expect(subject.extend!).to eq(
+ something: {
+ script: 'deploy',
+ only: { variables: %w[$SOMETHING] }
+ },
+
+ test: {
+ extends: 'something',
+ script: 'ls',
+ only: {
+ refs: %w[master],
+ variables: %w[$SOMETHING]
+ }
+ }
+ )
+ end
+ end
+
+ context 'when a hash uses recursive extensions' do
+ let(:hash) do
+ {
+ test: {
+ extends: 'something',
+ script: 'ls',
+ only: { refs: %w[master] }
+ },
+
+ something: {
+ extends: '.first',
+ script: 'deploy',
+ only: { variables: %w[$SOMETHING] }
+ },
+
+ '.first': {
+ script: 'run',
+ only: { kubernetes: 'active' }
+ }
+ }
+ end
+
+ it 'extends a hash with a deep reverse merge' do
+ expect(subject.extend!).to eq(
+ '.first': {
+ script: 'run',
+ only: { kubernetes: 'active' }
+ },
+
+ something: {
+ extends: '.first',
+ script: 'deploy',
+ only: {
+ kubernetes: 'active',
+ variables: %w[$SOMETHING]
+ }
+ },
+
+ test: {
+ extends: 'something',
+ script: 'ls',
+ only: {
+ refs: %w[master],
+ variables: %w[$SOMETHING],
+ kubernetes: 'active'
+ }
+ }
+ )
+ end
+ end
+
+ pending 'when invalid `extends` is specified'
+ pending 'when circular dependecy has been detected'
+ end
+end