summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/ci/config/normalizer/number_strategy_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/ci/config/normalizer/number_strategy_spec.rb')
-rw-r--r--spec/lib/gitlab/ci/config/normalizer/number_strategy_spec.rb68
1 files changed, 68 insertions, 0 deletions
diff --git a/spec/lib/gitlab/ci/config/normalizer/number_strategy_spec.rb b/spec/lib/gitlab/ci/config/normalizer/number_strategy_spec.rb
new file mode 100644
index 00000000000..06f47fe11c6
--- /dev/null
+++ b/spec/lib/gitlab/ci/config/normalizer/number_strategy_spec.rb
@@ -0,0 +1,68 @@
+# frozen_string_literal: true
+
+require 'fast_spec_helper'
+
+RSpec.describe Gitlab::Ci::Config::Normalizer::NumberStrategy do
+ describe '.applies_to?' do
+ subject { described_class.applies_to?(config) }
+
+ context 'with numbers' do
+ let(:config) { 5 }
+
+ it { is_expected.to be_truthy }
+ end
+
+ context 'with hash that has :number key' do
+ let(:config) { { number: 5 } }
+
+ it { is_expected.to be_truthy }
+ end
+
+ context 'with a float number' do
+ let(:config) { 5.5 }
+
+ it { is_expected.to be_falsey }
+ end
+
+ context 'with hash that does not have :number key' do
+ let(:config) { { matrix: 5 } }
+
+ it { is_expected.to be_falsey }
+ end
+ end
+
+ describe '.build_from' do
+ subject { described_class.build_from('test', config) }
+
+ shared_examples 'parallelized job' do
+ it { expect(subject.size).to eq(3) }
+
+ it 'has attributes' do
+ expect(subject.map(&:attributes)).to match_array(
+ [
+ { name: 'test 1/3', instance: 1, parallel: { total: 3 } },
+ { name: 'test 2/3', instance: 2, parallel: { total: 3 } },
+ { name: 'test 3/3', instance: 3, parallel: { total: 3 } }
+ ]
+ )
+ end
+
+ it 'has parallelized name' do
+ expect(subject.map(&:name)).to match_array(
+ ['test 1/3', 'test 2/3', 'test 3/3'])
+ end
+ end
+
+ context 'with numbers' do
+ let(:config) { 3 }
+
+ it_behaves_like 'parallelized job'
+ end
+
+ context 'with hash that has :number key' do
+ let(:config) { { number: 3 } }
+
+ it_behaves_like 'parallelized job'
+ end
+ end
+end