diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
commit | 6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch) | |
tree | 78be5963ec075d80116a932011d695dd33910b4e /spec/presenters/alert_management | |
parent | 1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff) |
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'spec/presenters/alert_management')
-rw-r--r-- | spec/presenters/alert_management/alert_presenter_spec.rb | 25 | ||||
-rw-r--r-- | spec/presenters/alert_management/prometheus_alert_presenter_spec.rb | 23 |
2 files changed, 42 insertions, 6 deletions
diff --git a/spec/presenters/alert_management/alert_presenter_spec.rb b/spec/presenters/alert_management/alert_presenter_spec.rb index b1bf7029f3e..394007a802f 100644 --- a/spec/presenters/alert_management/alert_presenter_spec.rb +++ b/spec/presenters/alert_management/alert_presenter_spec.rb @@ -4,17 +4,22 @@ require 'spec_helper' RSpec.describe AlertManagement::AlertPresenter do let_it_be(:project) { create(:project) } + let_it_be(:generic_payload) do { 'title' => 'Alert title', 'start_time' => '2020-04-27T10:10:22.265949279Z', - 'custom' => { 'param' => 73 } + 'custom' => { 'param' => 73 }, + 'runbook' => 'https://runbook.com' } 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(:alert_url) { "http://localhost/#{project.full_path}/-/alert_management/#{alert.iid}/details" } + subject(:presenter) { described_class.new(alert) } describe '#issue_description' do @@ -30,11 +35,13 @@ RSpec.describe AlertManagement::AlertPresenter do **Service:** #{alert.service}#{markdown_line_break} **Monitoring tool:** #{alert.monitoring_tool}#{markdown_line_break} **Hosts:** #{alert.hosts.join(' ')}#{markdown_line_break} - **Description:** #{alert.description} + **Description:** #{alert.description}#{markdown_line_break} + **GitLab alert:** #{alert_url} #### Alert Details - **custom.param:** 73 + **custom.param:** 73#{markdown_line_break} + **runbook:** https://runbook.com MARKDOWN ) end @@ -45,4 +52,16 @@ RSpec.describe AlertManagement::AlertPresenter do expect(presenter.metrics_dashboard_url).to be_nil end end + + describe '#runbook' do + it 'shows the runbook from the payload' do + expect(presenter.runbook).to eq('https://runbook.com') + end + end + + describe '#details_url' do + it 'returns the details URL' do + expect(presenter.details_url).to match(%r{#{project.web_url}/-/alert_management/#{alert.iid}/details}) + 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 95246914140..3cfff3c1b2f 100644 --- a/spec/presenters/alert_management/prometheus_alert_presenter_spec.rb +++ b/spec/presenters/alert_management/prometheus_alert_presenter_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' RSpec.describe AlertManagement::PrometheusAlertPresenter do let_it_be(:project) { create(:project) } - let_it_be(:payload) do + let(:payload) do { 'annotations' => { 'title' => 'Alert title', @@ -15,10 +15,13 @@ RSpec.describe AlertManagement::PrometheusAlertPresenter do 'generatorURL' => 'http://8d467bd4607a:9090/graph?g0.expr=vector%281%29&g0.tab=1' } end - let(:alert) do + + 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 @@ -32,7 +35,8 @@ RSpec.describe AlertManagement::PrometheusAlertPresenter do **Start time:** #{presenter.start_time}#{markdown_line_break} **Severity:** #{presenter.severity}#{markdown_line_break} **full_query:** `vector(1)`#{markdown_line_break} - **Monitoring tool:** Prometheus + **Monitoring tool:** Prometheus#{markdown_line_break} + **GitLab alert:** #{alert_url} #### Alert Details @@ -65,4 +69,17 @@ RSpec.describe AlertManagement::PrometheusAlertPresenter do it { is_expected.to eq(dashboard_url_for_alert) } end end + + describe '#runbook' do + subject { presenter.runbook } + + it { is_expected.to be_nil } + + context 'with runbook in payload' do + let(:expected_runbook) { 'https://awesome-runbook.com' } + let(:payload) { { 'annotations' => { 'runbook' => expected_runbook } } } + + it { is_expected.to eq(expected_runbook) } + end + end end |