diff options
author | Markus Doits <markus.doits@stellenticket.de> | 2018-10-19 16:47:18 +0200 |
---|---|---|
committer | Markus Doits <markus.doits@stellenticket.de> | 2018-11-07 13:04:43 +0100 |
commit | 9818bb561889579ed1031e90b7879ec1c3f0e25a (patch) | |
tree | 445a085e087644243d8e67f1bb22d04c63abcf57 /spec/lib/gitlab/ci/config | |
parent | ff3484a0b331456b36f82b0d6cda2afd56da566e (diff) | |
download | gitlab-ce-9818bb561889579ed1031e90b7879ec1c3f0e25a.tar.gz |
refactoring after latest feedback
Diffstat (limited to 'spec/lib/gitlab/ci/config')
-rw-r--r-- | spec/lib/gitlab/ci/config/entry/retry_spec.rb | 169 |
1 files changed, 111 insertions, 58 deletions
diff --git a/spec/lib/gitlab/ci/config/entry/retry_spec.rb b/spec/lib/gitlab/ci/config/entry/retry_spec.rb index cc5dfb56655..4feddafb580 100644 --- a/spec/lib/gitlab/ci/config/entry/retry_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/retry_spec.rb @@ -3,72 +3,125 @@ require 'spec_helper' describe Gitlab::Ci::Config::Entry::Retry do let(:entry) { described_class.new(config) } - describe 'validation' do - context 'when retry value is correct' do - context 'when it is a numeric' do - let(:config) { 2 } + shared_context 'when retry value is a numeric', :numeric do + let(:config) { max } + let(:max) {} + end - it 'is valid' do - expect(entry).to be_valid - end + shared_context 'when retry value is a hash', :hash do + let(:config) { { max: max, when: public_send(:when) }.compact } + let(:when) {} + let(:max) {} + end + + describe '#value' do + subject(:value) { entry.value } + + context 'when retry value is a numeric', :numeric do + let(:max) { 2 } + + it 'is returned as a hash with max key' do + expect(value).to eq(max: 2) end + end - context 'when it is a hash without when' do - let(:config) { { max: 2 } } + context 'when retry value is a hash', :hash do + context 'and `when` is a string' do + let(:when) { 'unknown_failure' } - it 'is valid' do - expect(entry).to be_valid + it 'returns when wrapped in an array' do + expect(value).to eq(when: ['unknown_failure']) end end - context 'when it is a hash with string when' do - let(:config) { { max: 2, when: 'unknown_failure' } } + context 'and `when` is an array' do + let(:when) { %w[unknown_failure runner_system_failure] } - it 'is valid' do - expect(entry).to be_valid + it 'returns when as it was passed' do + expect(value).to eq(when: %w[unknown_failure runner_system_failure]) end end + end + end - context 'when it is a hash with string when always' do - let(:config) { { max: 2, when: 'always' } } + describe 'validation' do + context 'when retry value is correct' do + context 'when it is a numeric', :numeric do + let(:max) { 2 } it 'is valid' do expect(entry).to be_valid end end - context 'when it is a hash with array when' do - let(:config) { { max: 2, when: %w[unknown_failure runner_system_failure] } } + context 'when it is a hash', :hash do + context 'with max' do + let(:max) { 2 } - it 'is valid' do - expect(entry).to be_valid + it 'is valid' do + expect(entry).to be_valid + end + end + + context 'with string when' do + let(:when) { 'unknown_failure' } + + it 'is valid' do + expect(entry).to be_valid + end + end + + context 'with string when always' do + let(:when) { 'always' } + + it 'is valid' do + expect(entry).to be_valid + end end - end - # Those values are documented at `doc/ci/yaml/README.md`. If any of - # those values gets invalid, documentation must be updated. To make - # sure this is catched, check explicitly that all of the documented - # values are valid. If they are not it means the documentation and this - # array must be updated. - RETRY_WHEN_IN_DOCUMENTATION = %w[ - always - unknown_failure - script_failure - api_failure - stuck_or_timeout_failure - runner_system_failure - missing_dependency_failure - runner_unsupported - ].freeze - - RETRY_WHEN_IN_DOCUMENTATION.each do |reason| - context "when it is a hash with value from documentation `#{reason}`" do - let(:config) { { max: 2, when: reason } } + context 'with array when' do + let(:when) { %w[unknown_failure runner_system_failure] } it 'is valid' do expect(entry).to be_valid end end + + # Those values are documented at `doc/ci/yaml/README.md`. If any of + # those values gets invalid, documentation must be updated. To make + # sure this is catched, check explicitly that all of the documented + # values are valid. If they are not it means the documentation and this + # array must be updated. + RETRY_WHEN_IN_DOCUMENTATION = %w[ + always + unknown_failure + script_failure + api_failure + stuck_or_timeout_failure + runner_system_failure + missing_dependency_failure + runner_unsupported + ].freeze + + RETRY_WHEN_IN_DOCUMENTATION.each do |reason| + context "with when from documentation `#{reason}`" do + let(:when) { reason } + + it 'is valid' do + expect(entry).to be_valid + end + end + end + + CommitStatus.failure_reasons.each_key do |reason| + context "with when from CommitStatus.failure_reasons `#{reason}`" do + let(:when) { reason } + + it 'is valid' do + expect(entry).to be_valid + end + end + end end end @@ -82,9 +135,9 @@ describe Gitlab::Ci::Config::Entry::Retry do end end - context 'not defined as a hash' do + context 'when it is a numeric', :numeric do context 'when it is lower than zero' do - let(:config) { -1 } + let(:max) { -1 } it 'returns error about value too low' do expect(entry).not_to be_valid @@ -94,7 +147,7 @@ describe Gitlab::Ci::Config::Entry::Retry do end context 'when it is not an integer' do - let(:config) { 1.5 } + let(:max) { 1.5 } it 'returns error about wrong value' do expect(entry).not_to be_valid @@ -103,7 +156,7 @@ describe Gitlab::Ci::Config::Entry::Retry do end context 'when the value is too high' do - let(:config) { 10 } + let(:max) { 10 } it 'returns error about value too high' do expect(entry).not_to be_valid @@ -112,7 +165,7 @@ describe Gitlab::Ci::Config::Entry::Retry do end end - context 'defined as a hash' do + context 'when it is a hash', :hash do context 'with unknown keys' do let(:config) { { max: 2, unknown_key: :something, one_more: :key } } @@ -123,8 +176,8 @@ describe Gitlab::Ci::Config::Entry::Retry do end end - context 'when max is lower than zero' do - let(:config) { { max: -1 } } + context 'with max lower than zero' do + let(:max) { -1 } it 'returns error about value too low' do expect(entry).not_to be_valid @@ -133,8 +186,8 @@ describe Gitlab::Ci::Config::Entry::Retry do end end - context 'when max is not an integer' do - let(:config) { { max: 1.5 } } + context 'with max not an integer' do + let(:max) { 1.5 } it 'returns error about wrong value' do expect(entry).not_to be_valid @@ -142,8 +195,8 @@ describe Gitlab::Ci::Config::Entry::Retry do end end - context 'when max is too high' do - let(:config) { { max: 10 } } + context 'iwth max too high' do + let(:max) { 10 } it 'returns error about value too high' do expect(entry).not_to be_valid @@ -151,8 +204,8 @@ describe Gitlab::Ci::Config::Entry::Retry do end end - context 'when when has the wrong format' do - let(:config) { { when: true } } + context 'with when in wrong format' do + let(:when) { true } it 'returns error about the wrong format' do expect(entry).not_to be_valid @@ -160,8 +213,8 @@ describe Gitlab::Ci::Config::Entry::Retry do end end - context 'when when is a string and unknown' do - let(:config) { { when: 'unknown_reason' } } + context 'with an unknown when string' do + let(:when) { 'unknown_reason' } it 'returns error about the wrong format' do expect(entry).not_to be_valid @@ -169,8 +222,8 @@ describe Gitlab::Ci::Config::Entry::Retry do end end - context 'when when is an array and includes unknown failures' do - let(:config) { { when: %w[unknown_reason runner_system_failure] } } + context 'with an unknown failure reason in a when array' do + let(:when) { %w[unknown_reason runner_system_failure] } it 'returns error about the wrong format' do expect(entry).not_to be_valid |