diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-12-09 14:07:26 +0100 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-12-09 14:07:26 +0100 |
commit | 56baeca3622ff4a05b5281002ec9440d41b57225 (patch) | |
tree | 80e596089ca46c50f5198fcc9387ba93c5e48aae | |
parent | a4ae474195950c6784159c3e948382d6baac99d3 (diff) | |
download | gitlab-ce-56baeca3622ff4a05b5281002ec9440d41b57225.tar.gz |
Add remaining tests for ci environment config rulesfix/refine-ci-configuration-rules
-rw-r--r-- | lib/gitlab/ci/config/rule/environments.rb | 4 | ||||
-rw-r--r-- | spec/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 |