summaryrefslogtreecommitdiff
path: root/spec/presenters
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-09-14 12:09:34 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-09-14 12:09:34 +0000
commit9a5dcad39c5dd81384ae4ec2398435883b944363 (patch)
tree3c684d30e4500028299d7948171e885b844a1ade /spec/presenters
parent0923a94d58cdd15cdb6379330e5eb41d30ccb8cc (diff)
downloadgitlab-ce-9a5dcad39c5dd81384ae4ec2398435883b944363.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/presenters')
-rw-r--r--spec/presenters/alert_management/alert_presenter_spec.rb27
-rw-r--r--spec/presenters/alert_management/prometheus_alert_presenter_spec.rb6
-rw-r--r--spec/presenters/projects/prometheus/alert_presenter_spec.rb120
3 files changed, 71 insertions, 82 deletions
diff --git a/spec/presenters/alert_management/alert_presenter_spec.rb b/spec/presenters/alert_management/alert_presenter_spec.rb
index 365dc84ff53..3b7920dfd5e 100644
--- a/spec/presenters/alert_management/alert_presenter_spec.rb
+++ b/spec/presenters/alert_management/alert_presenter_spec.rb
@@ -9,7 +9,14 @@ RSpec.describe AlertManagement::AlertPresenter do
{
'title' => 'Alert title',
'start_time' => '2020-04-27T10:10:22.265949279Z',
- 'custom' => { 'param' => 73 }
+ 'custom' => {
+ 'alert' => {
+ 'fields' => %w[one two]
+ }
+ },
+ 'yet' => {
+ 'another' => 73
+ }
}
end
@@ -37,7 +44,10 @@ RSpec.describe AlertManagement::AlertPresenter do
#### Alert Details
- **custom.param:** 73
+ **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
@@ -54,4 +64,17 @@ RSpec.describe AlertManagement::AlertPresenter do
expect(presenter.details_url).to match(%r{#{project.web_url}/-/alert_management/#{alert.iid}/details})
end
end
+
+ describe '#details' do
+ subject { presenter.details }
+
+ it 'renders the payload as inline hash' do
+ is_expected.to eq(
+ 'title' => 'Alert title',
+ 'start_time' => '2020-04-27T10:10:22.265949279Z',
+ 'custom.alert.fields' => %w[one two],
+ 'yet.another' => 73
+ )
+ end
+ end
end
diff --git a/spec/presenters/alert_management/prometheus_alert_presenter_spec.rb b/spec/presenters/alert_management/prometheus_alert_presenter_spec.rb
index 8ff51b9a8e1..74c77b70e5a 100644
--- a/spec/presenters/alert_management/prometheus_alert_presenter_spec.rb
+++ b/spec/presenters/alert_management/prometheus_alert_presenter_spec.rb
@@ -38,7 +38,11 @@ RSpec.describe AlertManagement::PrometheusAlertPresenter do
#### Alert Details
- **custom annotation:** custom annotation value
+ **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
---
diff --git a/spec/presenters/projects/prometheus/alert_presenter_spec.rb b/spec/presenters/projects/prometheus/alert_presenter_spec.rb
index 1c37e551385..4f1b1931fb9 100644
--- a/spec/presenters/projects/prometheus/alert_presenter_spec.rb
+++ b/spec/presenters/projects/prometheus/alert_presenter_spec.rb
@@ -65,32 +65,25 @@ RSpec.describe Projects::Prometheus::AlertPresenter do
<<~MARKDOWN.chomp
**Start time:** #{presenter.start_time}
- MARKDOWN
- )
- end
- end
-
- context 'with annotations' do
- before do
- payload['annotations'] = { 'title' => 'Alert Title', 'foo' => 'value1', 'bar' => 'value2' }
- end
-
- it do
- is_expected.to eq(
- <<~MARKDOWN.chomp
- **Start time:** #{presenter.start_time}
-
#### Alert Details
- **foo:** value1#{markdown_line_break}
- **bar:** value2
+ **startsAt:** #{presenter.starts_at_raw}
MARKDOWN
)
end
end
- context 'with full query' do
+ context 'with optional attributes' do
before do
+ payload['annotations'] = {
+ 'title' => 'Alert Title',
+ 'foo' => 'value1',
+ 'bar' => 'value2',
+ 'description' => 'Alert Description',
+ 'monitoring_tool' => 'monitoring_tool_name',
+ 'service' => 'service_name',
+ 'hosts' => ['http://localhost:3000', 'http://localhost:3001']
+ }
payload['generatorURL'] = 'http://host?g0.expr=query'
end
@@ -98,72 +91,52 @@ RSpec.describe Projects::Prometheus::AlertPresenter do
is_expected.to eq(
<<~MARKDOWN.chomp
**Start time:** #{presenter.start_time}#{markdown_line_break}
- **full_query:** `query`
+ **full_query:** `query`#{markdown_line_break}
+ **Service:** service_name#{markdown_line_break}
+ **Monitoring tool:** monitoring_tool_name#{markdown_line_break}
+ **Hosts:** http://localhost:3000 http://localhost:3001
+ #### Alert Details
+
+ **annotations.hosts:** ["http://localhost:3000", "http://localhost:3001"]#{markdown_line_break}
+ **annotations.service:** service_name#{markdown_line_break}
+ **annotations.monitoring_tool:** monitoring_tool_name#{markdown_line_break}
+ **annotations.description:** Alert Description#{markdown_line_break}
+ **annotations.bar:** value2#{markdown_line_break}
+ **annotations.foo:** value1#{markdown_line_break}
+ **annotations.title:** Alert Title#{markdown_line_break}
+ **generatorURL:** http://host?g0.expr=query#{markdown_line_break}
+ **startsAt:** #{presenter.starts_at_raw}
MARKDOWN
)
end
end
- context 'with the Generic Alert parameters' do
- let(:generic_alert_params) do
- {
- 'title' => 'The Generic Alert Title',
- 'description' => 'The Generic Alert Description',
- 'monitoring_tool' => 'monitoring_tool_name',
- 'service' => 'service_name',
- 'hosts' => ['http://localhost:3000', 'http://localhost:3001']
- }
- end
-
+ context 'when hosts is a string' do
before do
- payload['annotations'] = generic_alert_params
+ payload['annotations'] = { 'hosts' => 'http://localhost:3000' }
end
it do
is_expected.to eq(
<<~MARKDOWN.chomp
- **Start time:** #{presenter.start_time}#{markdown_line_break}
- **Service:** service_name#{markdown_line_break}
- **Monitoring tool:** monitoring_tool_name#{markdown_line_break}
- **Hosts:** http://localhost:3000 http://localhost:3001
+ **Start time:** #{presenter.start_time}#{markdown_line_break}
+ **Hosts:** http://localhost:3000
- #### Alert Details
+ #### Alert Details
- **description:** The Generic Alert Description
+ **annotations.hosts:** http://localhost:3000#{markdown_line_break}
+ **startsAt:** #{presenter.starts_at_raw}
MARKDOWN
)
end
-
- context 'when hosts is a string' do
- before do
- payload['annotations'] = { 'hosts' => 'http://localhost:3000' }
- end
-
- it do
- is_expected.to eq(
- <<~MARKDOWN.chomp
- **Start time:** #{presenter.start_time}#{markdown_line_break}
- **Hosts:** http://localhost:3000
-
- MARKDOWN
- )
- end
- end
end
context 'with embedded metrics' do
let(:starts_at) { '2018-03-12T09:06:00Z' }
shared_examples_for 'markdown with metrics embed' do
- let(:expected_markdown) do
- <<~MARKDOWN.chomp
- **Start time:** #{presenter.start_time}#{markdown_line_break}
- **full_query:** `avg(metric) > 1.0`
-
- [](#{presenter.metrics_dashboard_url})
- MARKDOWN
- end
+ let(:embed_regex) { /\n\[\]\(#{Regexp.quote(presenter.metrics_dashboard_url)}\)\z/ }
context 'without a starting time available' do
around do |example|
@@ -174,11 +147,11 @@ RSpec.describe Projects::Prometheus::AlertPresenter do
payload.delete('startsAt')
end
- it { is_expected.to eq(expected_markdown) }
+ it { is_expected.to match(embed_regex) }
end
context 'with a starting time available' do
- it { is_expected.to eq(expected_markdown) }
+ it { is_expected.to match(embed_regex) }
end
end
@@ -208,12 +181,8 @@ RSpec.describe Projects::Prometheus::AlertPresenter do
end
context 'when not enough information is present for an embed' do
- let(:expected_markdown) do
- <<~MARKDOWN.chomp
- **Start time:** #{presenter.start_time}#{markdown_line_break}
- **full_query:** `avg(metric) > 1.0`
-
- MARKDOWN
+ shared_examples_for 'does not include an embed' do
+ it { is_expected.not_to match(/\[\]\(.+\)/) }
end
context 'without title' do
@@ -221,7 +190,7 @@ RSpec.describe Projects::Prometheus::AlertPresenter do
payload['annotations'].delete('title')
end
- it { is_expected.to eq(expected_markdown) }
+ it_behaves_like 'does not include an embed'
end
context 'without environment' do
@@ -229,22 +198,15 @@ RSpec.describe Projects::Prometheus::AlertPresenter do
payload['labels'].delete('gitlab_environment_name')
end
- it { is_expected.to eq(expected_markdown) }
+ it_behaves_like 'does not include an embed'
end
context 'without full_query' do
- let(:expected_markdown) do
- <<~MARKDOWN.chomp
- **Start time:** #{presenter.start_time}
-
- MARKDOWN
- end
-
before do
payload.delete('generatorURL')
end
- it { is_expected.to eq(expected_markdown) }
+ it_behaves_like 'does not include an embed'
end
end
end