summaryrefslogtreecommitdiff
path: root/spec/workers
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-08-10 23:02:09 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-08-10 23:02:09 +0000
commit8c21e23045073c07c43f4f4d9012ced728702e98 (patch)
treea14b5f617927e4f3419e599967eab727f4755491 /spec/workers
parent0a3f1f55493660acfabd198d2e1649a881d8852b (diff)
downloadgitlab-ce-8c21e23045073c07c43f4f4d9012ced728702e98.tar.gz
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'spec/workers')
-rw-r--r--spec/workers/incident_management/process_alert_worker_spec.rb77
1 files changed, 42 insertions, 35 deletions
diff --git a/spec/workers/incident_management/process_alert_worker_spec.rb b/spec/workers/incident_management/process_alert_worker_spec.rb
index 75696d15ab8..bed6dc59ac7 100644
--- a/spec/workers/incident_management/process_alert_worker_spec.rb
+++ b/spec/workers/incident_management/process_alert_worker_spec.rb
@@ -16,66 +16,73 @@ RSpec.describe IncidentManagement::ProcessAlertWorker do
subject { described_class.new.perform(nil, nil, alert.id) }
before do
+ allow(Gitlab::AppLogger).to receive(:warn).and_call_original
+
allow(IncidentManagement::CreateIssueService)
.to receive(:new).with(alert.project, parsed_payload)
.and_call_original
end
- it 'creates an issue' do
- expect(IncidentManagement::CreateIssueService)
- .to receive(:new).with(alert.project, parsed_payload)
+ shared_examples 'creates issue successfully' do
+ it 'creates an issue' do
+ expect(IncidentManagement::CreateIssueService)
+ .to receive(:new).with(alert.project, parsed_payload)
- expect { subject }.to change { Issue.count }.by(1)
- end
+ expect { subject }.to change { Issue.count }.by(1)
+ end
- context 'with invalid alert' do
- let(:invalid_alert_id) { non_existing_record_id }
+ it 'updates AlertManagement::Alert#issue_id' do
+ subject
- subject { described_class.new.perform(nil, nil, invalid_alert_id) }
+ expect(alert.reload.issue_id).to eq(created_issue.id)
+ end
- it 'does not create issues' do
- expect(IncidentManagement::CreateIssueService).not_to receive(:new)
+ it 'does not write a warning to log' do
+ subject
- expect { subject }.not_to change { Issue.count }
+ expect(Gitlab::AppLogger).not_to have_received(:warn)
end
end
context 'with valid alert' do
- before do
- allow(Gitlab::AppLogger).to receive(:warn).and_call_original
- end
+ it_behaves_like 'creates issue successfully'
- context 'when alert can be updated' do
- it 'updates AlertManagement::Alert#issue_id' do
- subject
+ context 'when alert cannot be updated' do
+ let_it_be(:alert) { create(:alert_management_alert, :with_validation_errors, project: project, payload: payload) }
- expect(alert.reload.issue_id).to eq(created_issue.id)
+ it 'updates AlertManagement::Alert#issue_id' do
+ expect { subject }.not_to change { alert.reload.issue_id }
end
- it 'does not write a warning to log' do
+ it 'logs a warning' do
subject
- expect(Gitlab::AppLogger).not_to have_received(:warn)
+ expect(Gitlab::AppLogger).to have_received(:warn).with(
+ message: 'Cannot link an Issue with Alert',
+ issue_id: created_issue.id,
+ alert_id: alert.id,
+ alert_errors: { hosts: ['hosts array is over 255 chars'] }
+ )
end
+ end
- context 'when alert cannot be updated' do
- let_it_be(:alert) { create(:alert_management_alert, :with_validation_errors, project: project, payload: payload) }
+ context 'prometheus alert' do
+ let_it_be(:alert) { create(:alert_management_alert, :prometheus, project: project, started_at: started_at) }
+ let_it_be(:parsed_payload) { alert.payload }
- it 'updates AlertManagement::Alert#issue_id' do
- expect { subject }.not_to change { alert.reload.issue_id }
- end
+ it_behaves_like 'creates issue successfully'
+ end
+ end
- it 'logs a warning' do
- subject
+ context 'with invalid alert' do
+ let(:invalid_alert_id) { non_existing_record_id }
- expect(Gitlab::AppLogger).to have_received(:warn).with(
- message: 'Cannot link an Issue with Alert',
- issue_id: created_issue.id,
- alert_id: alert.id,
- alert_errors: { hosts: ['hosts array is over 255 chars'] }
- )
- end
- end
+ subject { described_class.new.perform(nil, nil, invalid_alert_id) }
+
+ it 'does not create issues' do
+ expect(IncidentManagement::CreateIssueService).not_to receive(:new)
+
+ expect { subject }.not_to change { Issue.count }
end
end
end