diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-10 18:09:32 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-10 18:09:32 +0000 |
commit | ed5add1c2f001c9bd54e664b32f212de172eca6a (patch) | |
tree | f9449cbecde36706f25a62f426b5398566ae5cca /spec/lib/gitlab | |
parent | de2fb5b82c92c90f90ed67ced45143c04e934fb8 (diff) | |
download | gitlab-ce-ed5add1c2f001c9bd54e664b32f212de172eca6a.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab')
-rw-r--r-- | spec/lib/gitlab/alerting/alert_spec.rb | 42 |
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 |