diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-08 18:09:29 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-08 18:09:29 +0300 |
commit | 5372e109c0660e4670aa987568a51082beca1b3c (patch) | |
tree | 76f8f1178d5f304f0aea8c0c610729f695c9e18e /spec/workers/prometheus | |
parent | 403678e00406edc8094f087ec70e00aa29e49bef (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/workers/prometheus')
-rw-r--r-- | spec/workers/prometheus/create_default_alerts_worker_spec.rb | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/spec/workers/prometheus/create_default_alerts_worker_spec.rb b/spec/workers/prometheus/create_default_alerts_worker_spec.rb new file mode 100644 index 00000000000..1b1867d5bb6 --- /dev/null +++ b/spec/workers/prometheus/create_default_alerts_worker_spec.rb @@ -0,0 +1,66 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Prometheus::CreateDefaultAlertsWorker do + let_it_be(:project) { create(:project) } + let(:worker) { described_class.new } + let(:logger) { worker.send(:logger) } + let(:service) { instance_double(Prometheus::CreateDefaultAlertsService) } + let(:service_result) { ServiceResponse.success } + + subject { described_class.new.perform(project.id) } + + before do + allow(Prometheus::CreateDefaultAlertsService) + .to receive(:new).with(project: project) + .and_return(service) + allow(service).to receive(:execute) + .and_return(service_result) + end + + it_behaves_like 'an idempotent worker' do + let(:job_args) { [project.id] } + + it 'calls the service' do + expect(service).to receive(:execute) + + subject + end + + context 'project is nil' do + let(:job_args) { [nil] } + + it 'does not call the service' do + expect(service).not_to receive(:execute) + + subject + end + end + + context 'when service returns an error' do + let(:error_message) { 'some message' } + let(:service_result) { ServiceResponse.error(message: error_message) } + + it 'succeeds and logs the error' do + expect(logger) + .to receive(:info) + .with(a_hash_including('message' => error_message)) + .exactly(worker_exec_times).times + + subject + end + end + end + + context 'when service raises an exception' do + let(:error_message) { 'some exception' } + let(:exception) { StandardError.new(error_message) } + + it 're-raises exception' do + allow(service).to receive(:execute).and_raise(exception) + + expect { subject }.to raise_error(exception) + end + end +end |