diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 11:18:50 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 11:18:50 +0000 |
commit | 8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781 (patch) | |
tree | a77e7fe7a93de11213032ed4ab1f33a3db51b738 /spec/services/alert_management/process_prometheus_alert_service_spec.rb | |
parent | 00b35af3db1abfe813a778f643dad221aad51fca (diff) | |
download | gitlab-ce-8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781.tar.gz |
Add latest changes from gitlab-org/gitlab@13-1-stable-ee
Diffstat (limited to 'spec/services/alert_management/process_prometheus_alert_service_spec.rb')
-rw-r--r-- | spec/services/alert_management/process_prometheus_alert_service_spec.rb | 40 |
1 files changed, 31 insertions, 9 deletions
diff --git a/spec/services/alert_management/process_prometheus_alert_service_spec.rb b/spec/services/alert_management/process_prometheus_alert_service_spec.rb index 73f9f103902..5b4da5e9077 100644 --- a/spec/services/alert_management/process_prometheus_alert_service_spec.rb +++ b/spec/services/alert_management/process_prometheus_alert_service_spec.rb @@ -5,8 +5,12 @@ require 'spec_helper' RSpec.describe AlertManagement::ProcessPrometheusAlertService do let_it_be(:project) { create(:project) } + before do + allow(ProjectServiceWorker).to receive(:perform_async) + end + describe '#execute' do - subject { described_class.new(project, nil, payload).execute } + subject(:execute) { described_class.new(project, nil, payload).execute } context 'when alert payload is valid' do let(:parsed_alert) { Gitlab::Alerting::Alert.new(project: project, payload: payload) } @@ -37,12 +41,22 @@ RSpec.describe AlertManagement::ProcessPrometheusAlertService do context 'when alert with the same fingerprint already exists' do let!(:alert) { create(:alert_management_alert, :resolved, project: project, fingerprint: parsed_alert.gitlab_fingerprint) } + it 'increases alert events count' do + expect { execute }.to change { alert.reload.events }.by(1) + end + context 'when status can be changed' do it 'changes status to triggered' do - expect { subject }.to change { alert.reload.triggered? }.to(true) + expect { execute }.to change { alert.reload.triggered? }.to(true) end end + it 'does not executes the alert service hooks' do + expect(alert).not_to receive(:execute_services) + + subject + end + context 'when status change did not succeed' do before do allow(AlertManagement::Alert).to receive(:for_fingerprint).and_return([alert]) @@ -56,7 +70,7 @@ RSpec.describe AlertManagement::ProcessPrometheusAlertService do alert_id: alert.id ) - subject + execute end end @@ -66,7 +80,15 @@ RSpec.describe AlertManagement::ProcessPrometheusAlertService do context 'when alert does not exist' do context 'when alert can be created' do it 'creates a new alert' do - expect { subject }.to change { AlertManagement::Alert.where(project: project).count }.by(1) + expect { execute }.to change { AlertManagement::Alert.where(project: project).count }.by(1) + end + + it 'executes the alert service hooks' do + slack_service = create(:service, type: 'SlackService', project: project, alert_events: true, active: true) + + subject + + expect(ProjectServiceWorker).to have_received(:perform_async).with(slack_service.id, an_instance_of(Hash)) end end @@ -85,7 +107,7 @@ RSpec.describe AlertManagement::ProcessPrometheusAlertService do alert_errors: { hosts: ['hosts array is over 255 chars'] } ) - subject + execute end end @@ -99,7 +121,7 @@ RSpec.describe AlertManagement::ProcessPrometheusAlertService do context 'when status can be changed' do it 'resolves an existing alert' do - expect { subject }.to change { alert.reload.resolved? }.to(true) + expect { execute }.to change { alert.reload.resolved? }.to(true) end end @@ -116,7 +138,7 @@ RSpec.describe AlertManagement::ProcessPrometheusAlertService do alert_id: alert.id ) - subject + execute end end @@ -128,8 +150,8 @@ RSpec.describe AlertManagement::ProcessPrometheusAlertService do let(:payload) { {} } it 'responds with bad_request' do - expect(subject).to be_error - expect(subject.http_status).to eq(:bad_request) + expect(execute).to be_error + expect(execute.http_status).to eq(:bad_request) end end end |