Welcome to mirror list, hosted at ThFree Co, Russian Federation.

matrix_strategy_spec.rb « normalizer « config « ci « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1cc8b4622246c569ee43361be8fee8b7fd1c7ed6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# frozen_string_literal: true

require 'fast_spec_helper'

RSpec.describe Gitlab::Ci::Config::Normalizer::MatrixStrategy do
  describe '.applies_to?' do
    subject { described_class.applies_to?(config) }

    context 'with hash that has :matrix key' do
      let(:config) { { matrix: [] } }

      it { is_expected.to be_truthy }
    end

    context 'with hash that does not have :matrix key' do
      let(:config) { { number: [] } }

      it { is_expected.to be_falsey }
    end

    context 'with a number' do
      let(:config) { 5 }

      it { is_expected.to be_falsey }
    end
  end

  describe '.build_from' do
    subject { described_class.build_from('test', config) }

    let(:config) do
      {
        matrix: [
          { 'PROVIDER' => %w[aws], 'STACK' => %w[app1 app2] },
          { 'PROVIDER' => %w[ovh gcp], 'STACK' => %w[app] }
        ]
      }
    end

    it { expect(subject.size).to eq(4) }

    it 'has attributes' do
      expect(subject.map(&:attributes)).to match_array(
        [
          {
            name: 'test: [aws, app1]',
            instance: 1,
            parallel: { total: 4 },
            job_variables: {
              'PROVIDER' => 'aws',
              'STACK' => 'app1'
            }
          },
          {
            name: 'test: [aws, app2]',
            instance: 2,
            parallel: { total: 4 },
            job_variables: {
              'PROVIDER' => 'aws',
              'STACK' => 'app2'
            }
          },
          {
            name: 'test: [ovh, app]',
            instance: 3,
            parallel: { total: 4 },
            job_variables: {
              'PROVIDER' => 'ovh',
              'STACK' => 'app'
            }
          },
          {
            name: 'test: [gcp, app]',
            instance: 4,
            parallel: { total: 4 },
            job_variables: {
              'PROVIDER' => 'gcp',
              'STACK' => 'app'
            }
          }
        ]
      )
    end

    it 'has parallelized name' do
      expect(subject.map(&:name)).to match_array(
        ['test: [aws, app1]', 'test: [aws, app2]', 'test: [gcp, app]', 'test: [ovh, app]']
      )
    end
  end
end