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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-09-15 15:09:30 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-09-15 15:09:30 +0300
commit33212c8ff1f99cdb896e8fc6f6450882287e0de5 (patch)
treeb29afde4eaf9623cda57ef6520db363d2db8492e /spec/presenters
parent03c73563048c1f808a4a3fb302f0dcbba37f5f76 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/presenters')
-rw-r--r--spec/presenters/alert_management/alert_presenter_spec.rb121
-rw-r--r--spec/presenters/alert_management/prometheus_alert_presenter_spec.rb74
2 files changed, 93 insertions, 102 deletions
diff --git a/spec/presenters/alert_management/alert_presenter_spec.rb b/spec/presenters/alert_management/alert_presenter_spec.rb
index 3b7920dfd5e..7d0dbead7a0 100644
--- a/spec/presenters/alert_management/alert_presenter_spec.rb
+++ b/spec/presenters/alert_management/alert_presenter_spec.rb
@@ -4,8 +4,7 @@ require 'spec_helper'
RSpec.describe AlertManagement::AlertPresenter do
let_it_be(:project) { create(:project) }
-
- let_it_be(:generic_payload) do
+ let_it_be(:payload) do
{
'title' => 'Alert title',
'start_time' => '2020-04-27T10:10:22.265949279Z',
@@ -20,42 +19,108 @@ RSpec.describe AlertManagement::AlertPresenter do
}
end
- let_it_be(:alert) do
- create(:alert_management_alert, :with_description, :with_host, :with_service, :with_monitoring_tool, project: project, payload: generic_payload)
- end
-
+ let_it_be(:alert) { create(:alert_management_alert, project: project, payload: payload) }
let(:alert_url) { "http://localhost/#{project.full_path}/-/alert_management/#{alert.iid}/details" }
subject(:presenter) { described_class.new(alert) }
describe '#issue_description' do
+ let_it_be(:alert) { create(:alert_management_alert, project: project, payload: {}) }
+
let(:markdown_line_break) { ' ' }
- it 'returns an alert issue description' do
- expect(presenter.issue_description).to eq(
- <<~MARKDOWN.chomp
- **Start time:** #{presenter.start_time}#{markdown_line_break}
- **Severity:** #{presenter.severity}#{markdown_line_break}
- **Service:** #{alert.service}#{markdown_line_break}
- **Monitoring tool:** #{alert.monitoring_tool}#{markdown_line_break}
- **Hosts:** #{alert.hosts.join(' ')}#{markdown_line_break}
- **Description:** #{alert.description}#{markdown_line_break}
- **GitLab alert:** #{alert_url}
-
- #### Alert Details
-
- **title:** Alert title#{markdown_line_break}
- **start_time:** 2020-04-27T10:10:22.265949279Z#{markdown_line_break}
- **custom.alert.fields:** ["one", "two"]#{markdown_line_break}
- **yet.another:** 73
- MARKDOWN
- )
+ subject { presenter.issue_description }
+
+ context 'with an empty payload' do
+ it do
+ is_expected.to eq(
+ <<~MARKDOWN.chomp
+ **Start time:** #{presenter.start_time}#{markdown_line_break}
+ **Severity:** #{presenter.severity}#{markdown_line_break}
+ **GitLab alert:** #{alert_url}
+
+ MARKDOWN
+ )
+ end
+ end
+
+ context 'with optional alert attributes' do
+ let_it_be(:alert) do
+ create(:alert_management_alert, :with_description, :with_host, :with_service, :with_monitoring_tool, project: project, payload: payload)
+ end
+
+ before do
+ allow(alert.parsed_payload).to receive(:full_query).and_return('metric > 1')
+ end
+
+ it do
+ is_expected.to eq(
+ <<~MARKDOWN.chomp
+ **Start time:** #{presenter.start_time}#{markdown_line_break}
+ **Severity:** #{presenter.severity}#{markdown_line_break}
+ **full_query:** `metric > 1`#{markdown_line_break}
+ **Service:** #{alert.service}#{markdown_line_break}
+ **Monitoring tool:** #{alert.monitoring_tool}#{markdown_line_break}
+ **Hosts:** #{alert.hosts.join(' ')}#{markdown_line_break}
+ **Description:** #{alert.description}#{markdown_line_break}
+ **GitLab alert:** #{alert_url}
+
+ #### Alert Details
+
+ **title:** Alert title#{markdown_line_break}
+ **start_time:** 2020-04-27T10:10:22.265949279Z#{markdown_line_break}
+ **custom.alert.fields:** ["one", "two"]#{markdown_line_break}
+ **yet.another:** 73
+ MARKDOWN
+ )
+ end
+ end
+
+ context 'with incident markdown' do
+ before do
+ allow(alert.parsed_payload).to receive(:alert_markdown).and_return('**`markdown example`**')
+ end
+
+ it do
+ is_expected.to eq(
+ <<~MARKDOWN.chomp
+ **Start time:** #{presenter.start_time}#{markdown_line_break}
+ **Severity:** #{presenter.severity}#{markdown_line_break}
+ **GitLab alert:** #{alert_url}
+
+
+ ---
+
+ **`markdown example`**
+ MARKDOWN
+ )
+ end
+ end
+
+ context 'with metrics_dashboard_url' do
+ before do
+ allow(alert.parsed_payload).to receive(:metrics_dashboard_url).and_return('https://gitlab.com/metrics')
+ end
+
+ it do
+ is_expected.to eq(
+ <<~MARKDOWN.chomp
+ **Start time:** #{presenter.start_time}#{markdown_line_break}
+ **Severity:** #{presenter.severity}#{markdown_line_break}
+ **GitLab alert:** #{alert_url}
+
+ [](https://gitlab.com/metrics)
+ MARKDOWN
+ )
+ end
end
end
- describe '#metrics_dashboard_url' do
- it 'is not defined' do
- expect(presenter.metrics_dashboard_url).to be_nil
+ describe '#start_time' do
+ it 'formats the start time of the alert' do
+ alert.started_at = Time.utc(2019, 5, 5)
+
+ expect(presenter.start_time). to eq('05 May 2019, 12:00AM (UTC)')
end
end
diff --git a/spec/presenters/alert_management/prometheus_alert_presenter_spec.rb b/spec/presenters/alert_management/prometheus_alert_presenter_spec.rb
deleted file mode 100644
index 74c77b70e5a..00000000000
--- a/spec/presenters/alert_management/prometheus_alert_presenter_spec.rb
+++ /dev/null
@@ -1,74 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-RSpec.describe AlertManagement::PrometheusAlertPresenter do
- let_it_be(:project) { create(:project) }
- let(:payload) do
- {
- 'annotations' => {
- 'title' => 'Alert title',
- 'gitlab_incident_markdown' => '**`markdown example`**',
- 'custom annotation' => 'custom annotation value'
- },
- 'startsAt' => '2020-04-27T10:10:22.265949279Z',
- 'generatorURL' => 'http://8d467bd4607a:9090/graph?g0.expr=vector%281%29&g0.tab=1'
- }
- end
-
- let!(:alert) do
- create(:alert_management_alert, :prometheus, project: project, payload: payload)
- end
-
- let(:alert_url) { "http://localhost/#{project.full_path}/-/alert_management/#{alert.iid}/details" }
-
- subject(:presenter) { described_class.new(alert) }
-
- describe '#issue_description' do
- let(:markdown_line_break) { ' ' }
-
- it 'returns an alert issue description' do
- expect(presenter.issue_description).to eq(
- <<~MARKDOWN.chomp
- **Start time:** #{presenter.start_time}#{markdown_line_break}
- **Severity:** #{presenter.severity}#{markdown_line_break}
- **full_query:** `vector(1)`#{markdown_line_break}
- **Monitoring tool:** Prometheus#{markdown_line_break}
- **GitLab alert:** #{alert_url}
-
- #### Alert Details
-
- **annotations.custom annotation:** custom annotation value#{markdown_line_break}
- **annotations.gitlab_incident_markdown:** **`markdown example`**#{markdown_line_break}
- **annotations.title:** Alert title#{markdown_line_break}
- **startsAt:** 2020-04-27T10:10:22.265949279Z#{markdown_line_break}
- **generatorURL:** http://8d467bd4607a:9090/graph?g0.expr=vector%281%29&g0.tab=1
-
- ---
-
- **`markdown example`**
- MARKDOWN
- )
- end
- end
-
- describe '#metrics_dashboard_url' do
- subject { presenter.metrics_dashboard_url }
-
- context 'for a non-prometheus alert' do
- it { is_expected.to be_nil }
- end
-
- context 'for a self-managed prometheus alert' do
- include_context 'self-managed prometheus alert attributes'
-
- it { is_expected.to eq(dashboard_url_for_alert) }
- end
-
- context 'for a gitlab-managed prometheus alert' do
- include_context 'gitlab-managed prometheus alert attributes'
-
- it { is_expected.to eq(dashboard_url_for_alert) }
- end
- end
-end