From ed5add1c2f001c9bd54e664b32f212de172eca6a Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Fri, 10 Apr 2020 18:09:32 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- spec/lib/gitlab/alerting/alert_spec.rb | 42 ++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/gitlab/alerting/alert_spec.rb b/spec/lib/gitlab/alerting/alert_spec.rb index 8b67cf949ce..6d97f08af91 100644 --- a/spec/lib/gitlab/alerting/alert_spec.rb +++ b/spec/lib/gitlab/alerting/alert_spec.rb @@ -9,11 +9,14 @@ describe Gitlab::Alerting::Alert do let(:payload) { {} } shared_context 'gitlab alert' do - let(:gitlab_alert_id) { gitlab_alert.prometheus_metric_id.to_s } let!(:gitlab_alert) { create(:prometheus_alert, project: project) } + let(:gitlab_alert_id) { gitlab_alert.id } before do - payload['labels'] = { 'gitlab_alert_id' => gitlab_alert_id } + payload['labels'] = { + 'gitlab_alert_id' => gitlab_alert.prometheus_metric_id.to_s, + 'gitlab_prometheus_alert_id' => gitlab_alert_id + } end end @@ -68,6 +71,41 @@ describe Gitlab::Alerting::Alert do it { is_expected.to be_nil } end + + context 'when two alerts with the same metric exist' do + include_context 'gitlab alert' + + let!(:second_gitlab_alert) do + create(:prometheus_alert, + project: project, + prometheus_metric_id: gitlab_alert.prometheus_metric_id + ) + end + + context 'alert id given in params' do + before do + payload['labels'] = { + 'gitlab_alert_id' => gitlab_alert.prometheus_metric_id.to_s, + 'gitlab_prometheus_alert_id' => second_gitlab_alert.id + } + end + + it { is_expected.to eq(second_gitlab_alert) } + end + + context 'metric id given in params' do + # This tests the case when two alerts are found, as metric id + # is not unique. + + # Note the metric id was incorrectly named as 'gitlab_alert_id' + # in PrometheusAlert#to_param. + before do + payload['labels'] = { 'gitlab_alert_id' => gitlab_alert.prometheus_metric_id } + end + + it { is_expected.to be_nil } + end + end end describe '#title' do -- cgit v1.2.3