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
path: root/spec/lib
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-04-10 21:09:32 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-10 21:09:32 +0300
commited5add1c2f001c9bd54e664b32f212de172eca6a (patch)
treef9449cbecde36706f25a62f426b5398566ae5cca /spec/lib
parentde2fb5b82c92c90f90ed67ced45143c04e934fb8 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/gitlab/alerting/alert_spec.rb42
1 files changed, 40 insertions, 2 deletions
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