diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-05 18:09:58 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-05 18:09:58 +0300 |
commit | d298c12de58b4d0a28358d38ed3f5762ed1550a0 (patch) | |
tree | cceec04d4312aadd4ef315fe851ff3cab4faca77 /spec/models/error_tracking | |
parent | e67e43e958982189b5ba3b816744ab162a34dd4b (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models/error_tracking')
-rw-r--r-- | spec/models/error_tracking/project_error_tracking_setting_spec.rb | 106 |
1 files changed, 52 insertions, 54 deletions
diff --git a/spec/models/error_tracking/project_error_tracking_setting_spec.rb b/spec/models/error_tracking/project_error_tracking_setting_spec.rb index 0685144dea6..30e73d84cfb 100644 --- a/spec/models/error_tracking/project_error_tracking_setting_spec.rb +++ b/spec/models/error_tracking/project_error_tracking_setting_spec.rb @@ -187,9 +187,38 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do end end + describe '#reactive_cache_limit_enabled?' do + subject { setting.reactive_cache_limit_enabled? } + + it { is_expected.to eq(true) } + + context 'when feature flag disabled' do + before do + stub_feature_flags(error_tracking_sentry_limit: false) + end + + it { is_expected.to eq(false) } + end + end + describe '#sentry_client' do - it 'returns sentry client' do - expect(subject.sentry_client).to be_a(ErrorTracking::SentryClient) + subject { setting.sentry_client } + + it { is_expected.to be_a(ErrorTracking::SentryClient) } + it { is_expected.to have_attributes(url: setting.api_url, token: setting.token) } + + describe '#validate_size_guarded_by_feature_flag?' do + subject { setting.sentry_client.validate_size_guarded_by_feature_flag? } + + it { is_expected.to eq(true) } + + context 'when feature flag disabled' do + before do + stub_feature_flags(error_tracking_sentry_limit: false) + end + + it { is_expected.to eq(false) } + end end end @@ -222,70 +251,39 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do end end - context 'when sentry client raises ErrorTracking::SentryClient::Error' do - before do - synchronous_reactive_cache(subject) - - allow(subject).to receive(:sentry_client).and_return(sentry_client) - allow(sentry_client).to receive(:list_issues).with(opts) - .and_raise(ErrorTracking::SentryClient::Error, 'error message') - end - - it 'returns error' do - expect(result).to eq( - error: 'error message', - error_type: ErrorTracking::ProjectErrorTrackingSetting::SENTRY_API_ERROR_TYPE_NON_20X_RESPONSE - ) - end - end - - context 'when sentry client raises ErrorTracking::SentryClient::MissingKeysError' do - before do - synchronous_reactive_cache(subject) - - allow(subject).to receive(:sentry_client).and_return(sentry_client) - allow(sentry_client).to receive(:list_issues).with(opts) - .and_raise(ErrorTracking::SentryClient::MissingKeysError, - 'Sentry API response is missing keys. key not found: "id"') - end - - it 'returns error' do - expect(result).to eq( - error: 'Sentry API response is missing keys. key not found: "id"', - error_type: ErrorTracking::ProjectErrorTrackingSetting::SENTRY_API_ERROR_TYPE_MISSING_KEYS - ) - end - end + describe 'client errors' do + using RSpec::Parameterized::TableSyntax - context 'when sentry client raises ErrorTracking::SentryClient::ResponseInvalidSizeError' do - let(:error_msg) { "Sentry API response is too big. Limit is #{Gitlab::Utils::DeepSize.human_default_max_size}." } + sc = ErrorTracking::SentryClient + pets = described_class + msg = 'something' before do synchronous_reactive_cache(subject) allow(subject).to receive(:sentry_client).and_return(sentry_client) - allow(sentry_client).to receive(:list_issues).with(opts) - .and_raise(ErrorTracking::SentryClient::ResponseInvalidSizeError, error_msg) end - it 'returns error' do - expect(result).to eq( - error: error_msg, - error_type: ErrorTracking::ProjectErrorTrackingSetting::SENTRY_API_ERROR_INVALID_SIZE - ) + where(:exception, :error_type, :error_message) do + sc::Error | pets::SENTRY_API_ERROR_TYPE_NON_20X_RESPONSE | msg + sc::MissingKeysError | pets::SENTRY_API_ERROR_TYPE_MISSING_KEYS | msg + sc::ResponseInvalidSizeError | pets::SENTRY_API_ERROR_INVALID_SIZE | msg + sc::BadRequestError | pets::SENTRY_API_ERROR_TYPE_BAD_REQUEST | msg + StandardError | nil | 'Unexpected Error' end - end - context 'when sentry client raises StandardError' do - before do - synchronous_reactive_cache(subject) + with_them do + it 'returns an error' do + allow(sentry_client).to receive(:list_issues).with(opts) + .and_raise(exception, msg) - allow(subject).to receive(:sentry_client).and_return(sentry_client) - allow(sentry_client).to receive(:list_issues).with(opts).and_raise(StandardError) - end + expected_result = { + error: error_message, + error_type: error_type + }.compact - it 'returns error' do - expect(result).to eq(error: 'Unexpected Error') + expect(result).to eq(expected_result) + end end end end |