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
|
# frozen_string_literal: true
# rubocop:disable RSpec/VerifiedDoubles
require 'fast_spec_helper'
require_relative '../../../scripts/api/get_package_and_test_job'
RSpec.describe GetPackageAndTestJob, feature_category: :tooling do
describe '#execute' do
let(:options) do
{
api_token: 'token',
endpoint: 'https://example.gitlab.com',
project: 12345,
pipeline_id: 1
}
end
let(:client) { double('Gitlab::Client') }
let(:client_response) { double('Gitlab::ClientResponse') }
let(:bridge_status) { 'success' }
let(:bridges_response) do
[
double(:bridge, id: 1, name: 'foo'),
double(:bridge, id: 2, name: 'bar'),
double(
:bridge,
id: 3,
name: 'e2e:package-and-test-ee',
downstream_pipeline: double(:downstream_pipeline, id: 1),
status: bridge_status
)
]
end
let(:detailed_status_label) { 'passed with warnings' }
let(:package_and_test_pipeline) do
double(
:pipeline,
id: 1,
name: 'e2e:package-and-test-ee',
detailed_status: double(
:detailed_status,
text: 'passed',
label: detailed_status_label
)
)
end
before do
allow(Gitlab)
.to receive(:client)
.and_return(client)
allow(client)
.to receive(:pipeline_bridges)
.and_return(double(auto_paginate: bridges_response))
allow(client)
.to receive(:pipeline)
.and_return(package_and_test_pipeline)
end
subject { described_class.new(options).execute }
it 'returns a package-and-test pipeline that passed with warnings' do
expect(subject).to eq(package_and_test_pipeline)
end
context 'when the bridge can not be found' do
let(:bridges_response) { [] }
it 'returns nothing' do
expect(subject).to be_nil
end
end
context 'when the downstream pipeline can not be found' do
let(:bridges_response) do
[
double(:bridge, id: 1, name: 'foo'),
double(:bridge, id: 2, name: 'bar'),
double(
:bridge,
id: 3,
name: 'e2e:package-and-test-ee',
downstream_pipeline: nil
)
]
end
it 'returns nothing' do
expect(subject).to be_nil
end
end
context 'when the bridge fails' do
let(:bridge_status) { 'failed' }
it 'returns the downstream_pipeline' do
expect(subject).to eq(package_and_test_pipeline)
end
end
context 'when the package-and-test can not be found' do
let(:package_and_test_pipeline) { nil }
it 'returns nothing' do
expect(subject).to be_nil
end
end
context 'when the package-and-test does not include a detailed status' do
let(:package_and_test_pipeline) do
double(
:pipeline,
name: 'e2e:package-and-test-ee',
detailed_status: nil
)
end
it 'returns nothing' do
expect(subject).to be_nil
end
end
context 'when the package-and-test succeeds' do
let(:detailed_status_label) { 'passed' }
it 'returns nothing' do
expect(subject).to be_nil
end
end
context 'when the package-and-test is canceled' do
let(:detailed_status_label) { 'canceled' }
it 'returns a failed package-and-test pipeline' do
expect(subject).to eq(package_and_test_pipeline)
end
end
end
end
# rubocop:enable RSpec/VerifiedDoubles
|