blob: 7aff33855aa9d42a52143131aaecfd60bf2efab9 (
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
|
# frozen_string_literal: true
require 'fast_spec_helper'
require 'gitlab/rspec/all'
require_relative '../../scripts/generate-failed-package-and-test-mr-message'
RSpec.describe GenerateFailedPackageAndTestMrMessage, feature_category: :tooling do
include StubENV
describe '#execute' do
let(:options) do
{
project: 1234,
api_token: 'asdf1234'
}
end
let(:commit_merge_request) do
{
'author' => {
'id' => '2',
'username' => 'test_user'
}
}
end
let(:package_and_test_job) do
{ 'web_url' => 'http://example.com' }
end
let(:merge_request) { instance_double(CommitMergeRequests, execute: [commit_merge_request]) }
let(:content) { /The `e2e:package-and-test-ee` job has failed./ }
let(:merge_request_discussion_client) { instance_double(CreateMergeRequestDiscussion, execute: true) }
let(:package_and_test_job_client) { instance_double(GetPackageAndTestJob, execute: package_and_test_job) }
subject { described_class.new(options).execute }
before do
stub_env(
'CI_MERGE_REQUEST_SOURCE_BRANCH_SHA' => 'bfcd2b9b5cad0b889494ce830697392c8ca11257',
'CI_PROJECT_ID' => '13083',
'CI_PIPELINE_ID' => '1234567',
'CI_PIPELINE_URL' => 'https://gitlab.com/gitlab-org/gitlab/-/pipelines/1234567',
'PROJECT_TOKEN_FOR_CI_SCRIPTS_API_USAGE' => 'asdf1234'
)
allow(GetPackageAndTestJob).to receive(:new)
.with(API::DEFAULT_OPTIONS)
.and_return(package_and_test_job_client)
end
context 'when package-and-test fails' do
before do
allow(CommitMergeRequests).to receive(:new)
.with(API::DEFAULT_OPTIONS.merge(sha: ENV['CI_MERGE_REQUEST_SOURCE_BRANCH_SHA']))
.and_return(merge_request)
end
it 'successfully creates a discussion' do
expect(CreateMergeRequestDiscussion).to receive(:new)
.with(API::DEFAULT_OPTIONS.merge(merge_request: commit_merge_request))
.and_return(merge_request_discussion_client)
expect(merge_request_discussion_client).to receive(:execute).with(content)
expect(subject).to eq(true)
end
end
context 'when package-and-test is did not fail' do
let(:package_and_test_job_client) { instance_double(GetPackageAndTestJob, execute: nil) }
it 'does not add a discussion' do
expect(CreateMergeRequestDiscussion).not_to receive(:new)
expect(subject).to eq(nil)
end
end
end
end
|