diff options
| author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-17 06:09:21 +0000 |
|---|---|---|
| committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-17 06:09:21 +0000 |
| commit | 3c97422b098235bca250f738922dab9c861f0ee7 (patch) | |
| tree | 5b3a1b25c5e203b6fb9ab569c578d745f93aff0a /spec | |
| parent | 38c3d3255398d615cf93867cb82902c3d2cb65a5 (diff) | |
| download | gitlab-ce-3c97422b098235bca250f738922dab9c861f0ee7.tar.gz | |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
4 files changed, 24 insertions, 56 deletions
diff --git a/spec/graphql/types/ci/pipeline_type_spec.rb b/spec/graphql/types/ci/pipeline_type_spec.rb index d435e337ad7..2a1e030480d 100644 --- a/spec/graphql/types/ci/pipeline_type_spec.rb +++ b/spec/graphql/types/ci/pipeline_type_spec.rb @@ -12,7 +12,7 @@ RSpec.describe Types::Ci::PipelineType do id iid sha before_sha status detailed_status config_source duration coverage created_at updated_at started_at finished_at committed_at stages user retryable cancelable jobs source_job downstream - upstream path project active user_permissions + upstream path project active user_permissions warnings ] if Gitlab.ee? diff --git a/spec/lib/gitlab/url_blocker_spec.rb b/spec/lib/gitlab/url_blocker_spec.rb index 20a8f2f6a41..4f274387195 100644 --- a/spec/lib/gitlab/url_blocker_spec.rb +++ b/spec/lib/gitlab/url_blocker_spec.rb @@ -167,10 +167,8 @@ RSpec.describe Gitlab::UrlBlocker, :stub_invalid_dns_only do subject { described_class.validate!(import_url, dns_rebind_protection: dns_rebind_protection) } before do - skip 'timeout is not available' unless timeout_available? - stub_env('RSPEC_ALLOW_INVALID_URLS', 'false') - stub_const("#{described_class}::GETADDRINFO_TIMEOUT_SECONDS", 0) + allow(Addrinfo).to receive(:getaddrinfo).and_raise(SocketError) end context 'with dns rebinding enabled' do @@ -189,17 +187,6 @@ RSpec.describe Gitlab::UrlBlocker, :stub_invalid_dns_only do let(:expected_hostname) { nil } end end - - # Detect whether the timeout option is available. - # - # See https://bugs.ruby-lang.org/issues/15553 - def timeout_available? - Addrinfo.getaddrinfo('localhost', nil, timeout: 0) - - false - rescue SocketError - true - end end end 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 fb1a23996e3..288a33b71cd 100644 --- a/spec/services/alert_management/process_prometheus_alert_service_spec.rb +++ b/spec/services/alert_management/process_prometheus_alert_service_spec.rb @@ -68,36 +68,29 @@ RSpec.describe AlertManagement::ProcessPrometheusAlertService do let!(:alert) { create(:alert_management_alert, :resolved, project: project, fingerprint: fingerprint) } it_behaves_like 'creates an alert management alert' + it_behaves_like 'Alert Notification Service sends notification email' end context 'existing alert is ignored' do let!(:alert) { create(:alert_management_alert, :ignored, project: project, fingerprint: fingerprint) } it_behaves_like 'adds an alert management alert event' + it_behaves_like 'Alert Notification Service sends no notifications' end - context 'two existing alerts, one resolved one open' do - let!(:resolved_alert) { create(:alert_management_alert, :resolved, project: project, fingerprint: fingerprint) } - let!(:alert) { create(:alert_management_alert, project: project, fingerprint: fingerprint) } + context 'existing alert is acknowledged' do + let!(:alert) { create(:alert_management_alert, :acknowledged, project: project, fingerprint: fingerprint) } it_behaves_like 'adds an alert management alert event' + it_behaves_like 'Alert Notification Service sends no notifications' end - context 'when status change did not succeed' do - before do - allow(AlertManagement::Alert).to receive(:for_fingerprint).and_return([alert]) - allow(alert).to receive(:trigger).and_return(false) - end - - it 'writes a warning to the log' do - expect(Gitlab::AppLogger).to receive(:warn).with( - message: 'Unable to update AlertManagement::Alert status to triggered', - project_id: project.id, - alert_id: alert.id - ) + context 'two existing alerts, one resolved one open' do + let!(:resolved_alert) { create(:alert_management_alert, :resolved, project: project, fingerprint: fingerprint) } + let!(:alert) { create(:alert_management_alert, project: project, fingerprint: fingerprint) } - execute - end + it_behaves_like 'adds an alert management alert event' + it_behaves_like 'Alert Notification Service sends notification email' end context 'when auto-creation of issues is disabled' do @@ -109,11 +102,7 @@ RSpec.describe AlertManagement::ProcessPrometheusAlertService do context 'when emails are disabled' do let(:send_email) { false } - it 'does not send notification' do - expect(NotificationService).not_to receive(:new) - - expect(subject).to be_success - end + it_behaves_like 'Alert Notification Service sends no notifications' end end @@ -136,11 +125,7 @@ RSpec.describe AlertManagement::ProcessPrometheusAlertService do context 'when emails are disabled' do let(:send_email) { false } - it 'does not send notification' do - expect(NotificationService).not_to receive(:new) - - expect(subject).to be_success - end + it_behaves_like 'Alert Notification Service sends no notifications' end end @@ -235,11 +220,7 @@ RSpec.describe AlertManagement::ProcessPrometheusAlertService do context 'when emails are disabled' do let(:send_email) { false } - it 'does not send notification' do - expect(NotificationService).not_to receive(:new) - - expect(subject).to be_success - end + it_behaves_like 'Alert Notification Service sends no notifications' end end diff --git a/spec/support/shared_examples/alert_notification_service_shared_examples.rb b/spec/support/shared_examples/alert_notification_service_shared_examples.rb index 1568e4357a1..7bd6df8c608 100644 --- a/spec/support/shared_examples/alert_notification_service_shared_examples.rb +++ b/spec/support/shared_examples/alert_notification_service_shared_examples.rb @@ -3,7 +3,7 @@ RSpec.shared_examples 'Alert Notification Service sends notification email' do let(:notification_service) { spy } - it 'sends a notification for firing alerts only' do + it 'sends a notification' do expect(NotificationService) .to receive(:new) .and_return(notification_service) @@ -15,15 +15,15 @@ RSpec.shared_examples 'Alert Notification Service sends notification email' do end end -RSpec.shared_examples 'Alert Notification Service sends no notifications' do |http_status:| - let(:notification_service) { spy } - let(:create_events_service) { spy } - +RSpec.shared_examples 'Alert Notification Service sends no notifications' do |http_status: nil| it 'does not notify' do - expect(notification_service).not_to receive(:async) - expect(create_events_service).not_to receive(:execute) + expect(NotificationService).not_to receive(:new) - expect(subject).to be_error - expect(subject.http_status).to eq(http_status) + if http_status.present? + expect(subject).to be_error + expect(subject.http_status).to eq(http_status) + else + expect(subject).to be_success + end end end |
