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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
# frozen_string_literal: true
require 'fast_spec_helper'
require 'support/helpers/stubbed_feature'
require 'support/helpers/stub_feature_flags'
RSpec.describe Gitlab::Ci::Config::Normalizer::MatrixStrategy do
include StubFeatureFlags
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 },
variables: {
'PROVIDER' => 'aws',
'STACK' => 'app1'
},
job_variables: {
'PROVIDER' => 'aws',
'STACK' => 'app1'
}
},
{
name: 'test: [aws, app2]',
instance: 2,
parallel: { total: 4 },
variables: {
'PROVIDER' => 'aws',
'STACK' => 'app2'
},
job_variables: {
'PROVIDER' => 'aws',
'STACK' => 'app2'
}
},
{
name: 'test: [ovh, app]',
instance: 3,
parallel: { total: 4 },
variables: {
'PROVIDER' => 'ovh',
'STACK' => 'app'
},
job_variables: {
'PROVIDER' => 'ovh',
'STACK' => 'app'
}
},
{
name: 'test: [gcp, app]',
instance: 4,
parallel: { total: 4 },
variables: {
'PROVIDER' => 'gcp',
'STACK' => 'app'
},
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
context 'when the FF ci_workflow_rules_variables is disabled' do
before do
stub_feature_flags(ci_workflow_rules_variables: false)
end
it 'excludes job_variables' do
expect(subject.map(&:attributes)).to match_array(
[
{
name: 'test: [aws, app1]',
instance: 1,
parallel: { total: 4 },
variables: {
'PROVIDER' => 'aws',
'STACK' => 'app1'
}
},
{
name: 'test: [aws, app2]',
instance: 2,
parallel: { total: 4 },
variables: {
'PROVIDER' => 'aws',
'STACK' => 'app2'
}
},
{
name: 'test: [ovh, app]',
instance: 3,
parallel: { total: 4 },
variables: {
'PROVIDER' => 'ovh',
'STACK' => 'app'
}
},
{
name: 'test: [gcp, app]',
instance: 4,
parallel: { total: 4 },
variables: {
'PROVIDER' => 'gcp',
'STACK' => 'app'
}
}
]
)
end
end
end
end
|