From 56baeca3622ff4a05b5281002ec9440d41b57225 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Fri, 9 Dec 2016 14:07:26 +0100 Subject: Add remaining tests for ci environment config rules --- lib/gitlab/ci/config/rule/environments.rb | 4 +- .../lib/gitlab/ci/config/rule/environments_spec.rb | 83 ++++++++++++++++++++-- 2 files changed, 81 insertions(+), 6 deletions(-) diff --git a/lib/gitlab/ci/config/rule/environments.rb b/lib/gitlab/ci/config/rule/environments.rb index b01359cf338..7c2f88d0691 100644 --- a/lib/gitlab/ci/config/rule/environments.rb +++ b/lib/gitlab/ci/config/rule/environments.rb @@ -36,6 +36,8 @@ module Gitlab end end + private + def stop_job_undefined? !@stop_job.specified? end @@ -45,7 +47,7 @@ module Gitlab end def stop_job_environment_name_invalid? - @environment.name != @stop_job_environment.name + @job_environment.name != @stop_job_environment.name end def stop_job_action_invalid? diff --git a/spec/lib/gitlab/ci/config/rule/environments_spec.rb b/spec/lib/gitlab/ci/config/rule/environments_spec.rb index 0cdbabd319d..857653c89b8 100644 --- a/spec/lib/gitlab/ci/config/rule/environments_spec.rb +++ b/spec/lib/gitlab/ci/config/rule/environments_spec.rb @@ -59,12 +59,85 @@ describe Gitlab::Ci::Config::Rule::Environments do end end - context 'when teardown job is defined' do + context 'when teardown job has environment defined' do + context 'when teardown job has invalid environment name' do + let(:config) do + { deploy: { + script: 'rspec', + environment: { + name: 'test', + on_stop: 'teardown' + } + }, + + teardown: { + script: 'echo teardown', + environment: 'staging' + } + } + end + + it 'adds errors about invalid environment name' do + expect(global.errors) + .to include 'jobs:teardown:environment name does not match ' \ + 'environment name defined in `deploy` job' + end + end + + context 'when teardown job has valid environment name' do + context 'when teardown has invalid action name' do + let(:config) do + { deploy: { + script: 'rspec', + environment: { + name: 'test', + on_stop: 'teardown' + } + }, + + teardown: { + script: 'echo teardown', + environment: { + name: 'test', + action: 'start' + } + } + } + end + + it 'adds error about invalid action name' do + expect(global.errors) + .to include 'jobs:teardown:environment action should be ' \ + 'defined as `stop`' + end + end + + context 'when teardown job has valid action name' do + let(:config) do + { deploy: { + script: 'rspec', + environment: { + name: 'test', + on_stop: 'teardown' + } + }, + + teardown: { + script: 'echo teardown', + environment: { + name: 'test', + action: 'stop' + } + } + } + end + + it 'does not invalidate configuration' do + expect(global).to be_valid + end + end + end end end end - - def define_config(hash) - Gitlab::Ci::Config::Node::Global.new(hash) - end end -- cgit v1.2.1