From c6b3ec3f56fa32a0e0ed3de0d0878d25f1adaddf Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Tue, 7 Apr 2020 15:09:30 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- .../members/update_highest_role_service_spec.rb | 44 ---------------------- .../projects/alerting/notify_service_spec.rb | 14 +++---- .../projects/import_export/export_service_spec.rb | 24 ++---------- .../prometheus/alerts/notify_service_spec.rb | 31 +++++++-------- 4 files changed, 26 insertions(+), 87 deletions(-) delete mode 100644 spec/services/members/update_highest_role_service_spec.rb (limited to 'spec/services') diff --git a/spec/services/members/update_highest_role_service_spec.rb b/spec/services/members/update_highest_role_service_spec.rb deleted file mode 100644 index 6fcb939203d..00000000000 --- a/spec/services/members/update_highest_role_service_spec.rb +++ /dev/null @@ -1,44 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' -require 'sidekiq/testing' - -describe Members::UpdateHighestRoleService, :clean_gitlab_redis_shared_state do - include ExclusiveLeaseHelpers - - let_it_be(:user) { create(:user) } - let_it_be(:lease_key) { "update_highest_role:#{user.id}" } - let(:service) { described_class.new(user.id) } - - describe '#perform' do - subject { service.execute } - - context 'when lease is obtained' do - it 'takes the lease but does not release it', :aggregate_failures do - expect_to_obtain_exclusive_lease(lease_key, 'uuid', timeout: described_class::LEASE_TIMEOUT) - - subject - - expect(service.exclusive_lease.exists?).to be_truthy - end - - it 'schedules a job in the future', :aggregate_failures do - expect(UpdateHighestRoleWorker).to receive(:perform_in).with(described_class::DELAY, user.id).and_call_original - - Sidekiq::Testing.fake! do - expect { subject }.to change(UpdateHighestRoleWorker.jobs, :size).by(1) - end - end - end - - context 'when lease cannot be obtained' do - it 'only schedules one job' do - Sidekiq::Testing.fake! do - stub_exclusive_lease_taken(lease_key, timeout: described_class::LEASE_TIMEOUT) - - expect { subject }.not_to change(UpdateHighestRoleWorker.jobs, :size) - end - end - end - end -end diff --git a/spec/services/projects/alerting/notify_service_spec.rb b/spec/services/projects/alerting/notify_service_spec.rb index 289d812f498..f08ecd397ec 100644 --- a/spec/services/projects/alerting/notify_service_spec.rb +++ b/spec/services/projects/alerting/notify_service_spec.rb @@ -20,7 +20,7 @@ describe Projects::Alerting::NotifyService do .exactly(amount).times Sidekiq::Testing.inline! do - expect(subject.status).to eq(:success) + expect(subject).to be_success end end end @@ -36,7 +36,7 @@ describe Projects::Alerting::NotifyService do expect(notification_service) .to receive_message_chain(:async, :prometheus_alerts_fired) - expect(subject.status).to eq(:success) + expect(subject).to be_success end end @@ -45,7 +45,7 @@ describe Projects::Alerting::NotifyService do expect(IncidentManagement::ProcessAlertWorker) .not_to receive(:perform_async) - expect(subject.status).to eq(:success) + expect(subject).to be_success end end @@ -54,7 +54,7 @@ describe Projects::Alerting::NotifyService do expect(IncidentManagement::ProcessAlertWorker) .not_to receive(:perform_async) - expect(subject.status).to eq(:error) + expect(subject).to be_error expect(subject.http_status).to eq(http_status) end end @@ -102,7 +102,7 @@ describe Projects::Alerting::NotifyService do .and_raise(Gitlab::Alerting::NotificationPayloadParser::BadPayloadError) end - it_behaves_like 'does not process incident issues due to error', http_status: 400 + it_behaves_like 'does not process incident issues due to error', http_status: :bad_request end end @@ -114,13 +114,13 @@ describe Projects::Alerting::NotifyService do end context 'with invalid token' do - it_behaves_like 'does not process incident issues due to error', http_status: 401 + it_behaves_like 'does not process incident issues due to error', http_status: :unauthorized end context 'with deactivated Alerts Service' do let!(:alerts_service) { create(:alerts_service, :inactive, project: project) } - it_behaves_like 'does not process incident issues due to error', http_status: 403 + it_behaves_like 'does not process incident issues due to error', http_status: :forbidden end end end diff --git a/spec/services/projects/import_export/export_service_spec.rb b/spec/services/projects/import_export/export_service_spec.rb index 1315ae26322..e00507d1827 100644 --- a/spec/services/projects/import_export/export_service_spec.rb +++ b/spec/services/projects/import_export/export_service_spec.rb @@ -26,28 +26,10 @@ describe Projects::ImportExport::ExportService do service.execute end - context 'when :streaming_serializer feature is enabled' do - before do - stub_feature_flags(streaming_serializer: true) - end - - it 'saves the models' do - expect(Gitlab::ImportExport::Project::TreeSaver).to receive(:new).and_call_original - - service.execute - end - end + it 'saves the models' do + expect(Gitlab::ImportExport::Project::TreeSaver).to receive(:new).and_call_original - context 'when :streaming_serializer feature is disabled' do - before do - stub_feature_flags(streaming_serializer: false) - end - - it 'saves the models' do - expect(Gitlab::ImportExport::Project::LegacyTreeSaver).to receive(:new).and_call_original - - service.execute - end + service.execute end it 'saves the uploads' do diff --git a/spec/services/projects/prometheus/alerts/notify_service_spec.rb b/spec/services/projects/prometheus/alerts/notify_service_spec.rb index ce850e65329..dce96dda1e3 100644 --- a/spec/services/projects/prometheus/alerts/notify_service_spec.rb +++ b/spec/services/projects/prometheus/alerts/notify_service_spec.rb @@ -30,7 +30,7 @@ describe Projects::Prometheus::Alerts::NotifyService do expect(notification_service) .to receive_message_chain(:async, :prometheus_alerts_fired) - expect(subject).to eq(true) + expect(subject).to be_success end end @@ -44,7 +44,7 @@ describe Projects::Prometheus::Alerts::NotifyService do .exactly(amount).times Sidekiq::Testing.inline! do - expect(subject).to eq(true) + expect(subject).to be_success end end end @@ -54,7 +54,7 @@ describe Projects::Prometheus::Alerts::NotifyService do expect(IncidentManagement::ProcessPrometheusAlertWorker) .not_to receive(:perform_async) - expect(subject).to eq(true) + expect(subject).to be_success end end @@ -69,7 +69,7 @@ describe Projects::Prometheus::Alerts::NotifyService do expect(create_events_service) .to receive(:execute) - expect(subject).to eq(true) + expect(subject).to be_success end end @@ -78,7 +78,7 @@ describe Projects::Prometheus::Alerts::NotifyService do it_behaves_like 'persists events' end - shared_examples 'no notifications' do + shared_examples 'no notifications' do |http_status:| let(:notification_service) { spy } let(:create_events_service) { spy } @@ -86,7 +86,8 @@ describe Projects::Prometheus::Alerts::NotifyService do expect(notification_service).not_to receive(:async) expect(create_events_service).not_to receive(:execute) - expect(subject).to eq(false) + expect(subject).to be_error + expect(subject.http_status).to eq(http_status) end end @@ -130,7 +131,7 @@ describe Projects::Prometheus::Alerts::NotifyService do when :success it_behaves_like 'notifies alerts' when :failure - it_behaves_like 'no notifications' + it_behaves_like 'no notifications', http_status: :unauthorized else raise "invalid result: #{result.inspect}" end @@ -140,7 +141,7 @@ describe Projects::Prometheus::Alerts::NotifyService do context 'without project specific cluster' do let!(:cluster) { create(:cluster, enabled: true) } - it_behaves_like 'no notifications' + it_behaves_like 'no notifications', http_status: :unauthorized end context 'with manual prometheus installation' do @@ -171,7 +172,7 @@ describe Projects::Prometheus::Alerts::NotifyService do when :success it_behaves_like 'notifies alerts' when :failure - it_behaves_like 'no notifications' + it_behaves_like 'no notifications', http_status: :unauthorized else raise "invalid result: #{result.inspect}" end @@ -193,7 +194,7 @@ describe Projects::Prometheus::Alerts::NotifyService do expect_any_instance_of(NotificationService) .not_to receive(:async) - expect(subject).to eq(true) + expect(subject).to be_success end end @@ -211,7 +212,7 @@ describe Projects::Prometheus::Alerts::NotifyService do it 'does not send notification' do expect(NotificationService).not_to receive(:new) - expect(subject).to eq(true) + expect(subject).to be_success end end end @@ -260,19 +261,19 @@ describe Projects::Prometheus::Alerts::NotifyService do context 'without version' do let(:payload) { {} } - it_behaves_like 'no notifications' + it_behaves_like 'no notifications', http_status: :unprocessable_entity end context 'when version is not "4"' do let(:payload) { { 'version' => '5' } } - it_behaves_like 'no notifications' + it_behaves_like 'no notifications', http_status: :unprocessable_entity end context 'with missing alerts' do let(:payload) { { 'version' => '4' } } - it_behaves_like 'no notifications' + it_behaves_like 'no notifications', http_status: :unauthorized end context 'when the payload is too big' do @@ -283,7 +284,7 @@ describe Projects::Prometheus::Alerts::NotifyService do allow(Gitlab::Utils::DeepSize).to receive(:new).and_return(deep_size_object) end - it_behaves_like 'no notifications' + it_behaves_like 'no notifications', http_status: :bad_request it 'does not process issues' do expect(IncidentManagement::ProcessPrometheusAlertWorker) -- cgit v1.2.3