summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/ci/config
diff options
context:
space:
mode:
authorMarkus Doits <markus.doits@stellenticket.de>2018-09-19 17:27:31 +0200
committerMarkus Doits <markus.doits@stellenticket.de>2018-11-07 13:01:53 +0100
commit0db50a808d15e7a3d93552da8a0051ed5245f461 (patch)
tree84d3e52719fe67b99493ca06cc095b444fae9f1e /spec/lib/gitlab/ci/config
parent42f36954348c3f09dc31e4c7697f857f9dc63111 (diff)
downloadgitlab-ce-0db50a808d15e7a3d93552da8a0051ed5245f461.tar.gz
update job config validator to validate new retry syntax
Diffstat (limited to 'spec/lib/gitlab/ci/config')
-rw-r--r--spec/lib/gitlab/ci/config/entry/job_spec.rb149
1 files changed, 130 insertions, 19 deletions
diff --git a/spec/lib/gitlab/ci/config/entry/job_spec.rb b/spec/lib/gitlab/ci/config/entry/job_spec.rb
index f1a2946acda..9941c975517 100644
--- a/spec/lib/gitlab/ci/config/entry/job_spec.rb
+++ b/spec/lib/gitlab/ci/config/entry/job_spec.rb
@@ -98,41 +98,152 @@ describe Gitlab::Ci::Config::Entry::Job do
end
end
+ context 'when retry value is correct' do
+ context 'when it is a numeric' do
+ let(:config) { { script: 'rspec', retry: 2 } }
+
+ it 'is valid' do
+ expect(entry).to be_valid
+ end
+ end
+
+ context 'when it is a hash without when' do
+ let(:config) { { script: 'rspec', retry: { max: 2 } } }
+
+ it 'is valid' do
+ expect(entry).to be_valid
+ end
+ end
+
+ context 'when it is a hash with string when' do
+ let(:config) { { script: 'rspec', retry: { max: 2, when: 'unknown_failure' } } }
+
+ it 'is valid' do
+ expect(entry).to be_valid
+ end
+ end
+
+ context 'when it is a hash with string when always' do
+ let(:config) { { script: 'rspec', retry: { max: 2, when: 'always' } } }
+
+ it 'is valid' do
+ expect(entry).to be_valid
+ end
+ end
+
+ context 'when it is a hash with array when' do
+ let(:config) { { script: 'rspec', retry: { max: 2, when: %w[unknown_failure runner_system_failure] } } }
+
+ it 'is valid' do
+ expect(entry).to be_valid
+ end
+ end
+ end
+
context 'when retry value is not correct' do
- context 'when it is not a numeric value' do
+ context 'when it is not a numeric nor an array' do
let(:config) { { retry: true } }
it 'returns error about invalid type' do
expect(entry).not_to be_valid
- expect(entry.errors).to include 'job retry is not a number'
+ expect(entry.errors).to include 'job retry should be a hash or an integer'
end
end
- context 'when it is lower than zero' do
- let(:config) { { retry: -1 } }
+ context 'not defined as a hash' do
+ context 'when it is lower than zero' do
+ let(:config) { { retry: -1 } }
- it 'returns error about value too low' do
- expect(entry).not_to be_valid
- expect(entry.errors)
- .to include 'job retry must be greater than or equal to 0'
+ it 'returns error about value too low' do
+ expect(entry).not_to be_valid
+ expect(entry.errors)
+ .to include 'job retry max must be greater than or equal to 0'
+ end
end
- end
- context 'when it is not an integer' do
- let(:config) { { retry: 1.5 } }
+ context 'when it is not an integer' do
+ let(:config) { { retry: 1.5 } }
- it 'returns error about wrong value' do
- expect(entry).not_to be_valid
- expect(entry.errors).to include 'job retry must be an integer'
+ it 'returns error about wrong value' do
+ expect(entry).not_to be_valid
+ expect(entry.errors).to include 'job retry should be a hash or an integer'
+ end
+ end
+
+ context 'when the value is too high' do
+ let(:config) { { retry: 10 } }
+
+ it 'returns error about value too high' do
+ expect(entry).not_to be_valid
+ expect(entry.errors).to include 'job retry max must be less than or equal to 2'
+ end
end
end
- context 'when the value is too high' do
- let(:config) { { retry: 10 } }
+ context 'defined as a hash' do
+ context 'with unkown keys' do
+ let(:config) { { retry: { max: 2, unknown_key: :something, one_more: :key } } }
- it 'returns error about value too high' do
- expect(entry).not_to be_valid
- expect(entry.errors).to include 'job retry must be less than or equal to 2'
+ it 'returns error about the unknown key' do
+ expect(entry).not_to be_valid
+ expect(entry.errors)
+ .to include 'job config retry contains unknown keys: unknown_key, one_more'
+ end
+ end
+
+ context 'when max is lower than zero' do
+ let(:config) { { retry: { max: -1 } } }
+
+ it 'returns error about value too low' do
+ expect(entry).not_to be_valid
+ expect(entry.errors)
+ .to include 'job retry max must be greater than or equal to 0'
+ end
+ end
+
+ context 'when max is not an integer' do
+ let(:config) { { retry: { max: 1.5 } } }
+
+ it 'returns error about wrong value' do
+ expect(entry).not_to be_valid
+ expect(entry.errors).to include 'job retry max must be an integer'
+ end
+ end
+
+ context 'when max is too high' do
+ let(:config) { { retry: { max: 10 } } }
+
+ it 'returns error about value too high' do
+ expect(entry).not_to be_valid
+ expect(entry.errors).to include 'job retry max must be less than or equal to 2'
+ end
+ end
+
+ context 'when when has the wrong format' do
+ let(:config) { { retry: { when: true } } }
+
+ it 'returns error about the wrong format' do
+ expect(entry).not_to be_valid
+ expect(entry.errors).to include 'job retry max must be an integer'
+ end
+ end
+
+ context 'when when is a string and unknown' do
+ let(:config) { { retry: { when: 'unknown_reason' } } }
+
+ it 'returns error about the wrong format' do
+ expect(entry).not_to be_valid
+ expect(entry.errors).to include 'job retry when is unknown'
+ end
+ end
+
+ context 'when when is an array and includes unknown failures' do
+ let(:config) { { retry: { when: %w[unknown_reason runner_system_failure] } } }
+
+ it 'returns error about the wrong format' do
+ expect(entry).not_to be_valid
+ expect(entry.errors).to include 'job retry when cannot have unknown failures unknown_reason'
+ end
end
end
end