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
|
# frozen_string_literal: true
module QA
RSpec.describe 'Monitor', product_group: :respond do
describe 'Alert settings' do
shared_examples 'sends test alert using authorization key' do |type|
it 'creates new alert', :aggregate_failures do
response = RestClient.post(
credentials[:url],
payload.to_json,
{ 'Content-Type': 'application/json', Authorization: "Bearer #{credentials[:auth_key]}" }
)
# With HTTP type, a successful request returns 200 and a JSON with the alert's title
# With Prometheus type, a successful request returns 201
if type == 'http'
expect(response.code).to eq 200
expect(JSON.parse(response).first['title']).to eq alert_title
else
expect(response.code).to eq 201
end
Page::Project::Menu.perform(&:go_to_monitor_alerts)
Page::Project::Monitor::Alerts::Index.perform do |index|
expect(index).to have_alert_with_title(alert_title)
end
end
end
let(:project) do
Resource::Project.fabricate_via_api! do |project|
project.name = 'project-for-alerts'
project.description = 'Project for alerts'
end
end
let(:alert_title) { Faker::Lorem.word }
before do
Flow::Login.sign_in
project.visit!
end
context(
'when using HTTP endpoint integration',
testcase: 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/386734'
) do
let(:payload) do
{ title: alert_title, description: alert_title }
end
let(:credentials) do
Flow::AlertSettings.setup_http_endpoint(send: false)
end
it_behaves_like 'sends test alert using authorization key', 'http'
end
context(
'when using Prometheus integration',
testcase: 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/386735'
) do
let(:payload) do
{
version: '4',
groupKey: nil,
status: 'firing',
receiver: '',
groupLabels: {},
commonLabels: {},
commonAnnotations: {},
externalURL: '',
alerts: [
{
startsAt: Time.now,
generatorURL: Faker::Internet.url,
endsAt: nil,
status: 'firing',
labels: { gitlab_environment_name: Faker::Lorem.word },
annotations:
{
title: alert_title,
gitlab_y_label: 'status'
}
}
]
}
end
let(:credentials) do
Flow::AlertSettings.setup_prometheus(send: false)
end
it_behaves_like 'sends test alert using authorization key'
end
end
end
end
|