diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-01 18:08:40 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-01 18:08:40 +0300 |
commit | cdd826bc3ad3e6f234f96a861efa129dba5e2502 (patch) | |
tree | b159419c3a731637f35e95fe62f30ad437356996 /spec | |
parent | e4a0b94a64dc5bd8f48430cd5cdf9aaa10927e75 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
18 files changed, 210 insertions, 76 deletions
diff --git a/spec/factories/go_module_versions.rb b/spec/factories/go_module_versions.rb index 145e6c95921..bdbd5a4423a 100644 --- a/spec/factories/go_module_versions.rb +++ b/spec/factories/go_module_versions.rb @@ -5,12 +5,10 @@ FactoryBot.define do skip_create initialize_with do - p = attributes[:params] - s = Packages::SemVer.parse(p.semver, prefixed: true) + s = Packages::SemVer.parse(semver, prefixed: true) + raise ArgumentError, "invalid sematic version: #{semver.inspect}" if !s && semver - raise ArgumentError, "invalid sematic version: '#{p.semver}'" if !s && p.semver - - new(p.mod, p.type, p.commit, name: p.name, semver: s, ref: p.ref) + new(mod, type, commit, name: name, semver: s, ref: ref) end mod { association(:go_module) } @@ -20,8 +18,6 @@ FactoryBot.define do semver { nil } ref { nil } - params { OpenStruct.new(mod: mod, type: type, commit: commit, name: name, semver: semver, ref: ref) } - trait :tagged do ref { mod.project.repository.find_tag(name) } commit { ref.dereferenced_target } @@ -36,8 +32,8 @@ FactoryBot.define do .max_by(&:to_s) .to_s end - - params { OpenStruct.new(mod: mod, type: :ref, commit: commit, semver: name, ref: ref) } + type { :ref } + semver { name } end end end diff --git a/spec/features/merge_request/user_merges_merge_request_spec.rb b/spec/features/merge_request/user_merges_merge_request_spec.rb index d1be93cae02..a861ca2eea5 100644 --- a/spec/features/merge_request/user_merges_merge_request_spec.rb +++ b/spec/features/merge_request/user_merges_merge_request_spec.rb @@ -10,7 +10,7 @@ RSpec.describe "User merges a merge request", :js do end shared_examples "fast forward merge a merge request" do - it "merges a merge request", :sidekiq_might_not_need_inline do + it "merges a merge request", :sidekiq_inline do expect(page).to have_content("Fast-forward merge without a merge commit").and have_button("Merge") page.within(".mr-state-widget") do @@ -42,4 +42,23 @@ RSpec.describe "User merges a merge request", :js do it_behaves_like "fast forward merge a merge request" end end + + context 'sidebar merge requests counter' do + let(:project) { create(:project, :public, :repository) } + let!(:merge_request) { create(:merge_request, source_project: project) } + + it 'decrements the open MR count', :sidekiq_inline do + create(:merge_request, source_project: project, source_branch: 'branch-1') + + visit(merge_request_path(merge_request)) + + expect(page).to have_css('.js-merge-counter', text: '2') + + page.within(".mr-state-widget") do + click_button("Merge") + end + + expect(page).to have_css('.js-merge-counter', text: '1') + end + end end diff --git a/spec/frontend/clusters_list/components/agent_table_spec.js b/spec/frontend/clusters_list/components/agent_table_spec.js index db723622a51..a466a35428a 100644 --- a/spec/frontend/clusters_list/components/agent_table_spec.js +++ b/spec/frontend/clusters_list/components/agent_table_spec.js @@ -9,7 +9,7 @@ import timeagoMixin from '~/vue_shared/mixins/timeago'; import { clusterAgents, connectedTimeNow, connectedTimeInactive } from './mock_data'; const defaultConfigHelpUrl = - '/help/user/clusters/agent/install/index#create-an-agent-without-configuration-file'; + '/help/user/clusters/agent/install/index#create-an-agent-configuration-file'; const provideData = { gitlabVersion: '14.8', diff --git a/spec/frontend/environments/graphql/mock_data.js b/spec/frontend/environments/graphql/mock_data.js index 1b7b35702de..7e436476a8f 100644 --- a/spec/frontend/environments/graphql/mock_data.js +++ b/spec/frontend/environments/graphql/mock_data.js @@ -543,6 +543,7 @@ export const resolvedEnvironment = { externalUrl: 'https://example.org', environmentType: 'review', nameWithoutType: 'hello', + tier: 'development', lastDeployment: { id: 78, iid: 24, @@ -551,6 +552,7 @@ export const resolvedEnvironment = { status: 'success', createdAt: '2022-01-07T15:47:27.415Z', deployedAt: '2022-01-07T15:47:32.450Z', + tierInYaml: 'staging', tag: false, isLast: true, user: { diff --git a/spec/frontend/environments/new_environment_item_spec.js b/spec/frontend/environments/new_environment_item_spec.js index 1d7a33fb95b..cf0c8a7e7ca 100644 --- a/spec/frontend/environments/new_environment_item_spec.js +++ b/spec/frontend/environments/new_environment_item_spec.js @@ -73,6 +73,34 @@ describe('~/environments/components/new_environment_item.vue', () => { expect(name.text()).toHaveLength(80); }); + describe('tier', () => { + it('displays the tier of the environment when defined in yaml', () => { + wrapper = createWrapper({ apolloProvider: createApolloProvider() }); + + const tier = wrapper.findByTitle(s__('Environment|Deployment tier')); + + expect(tier.text()).toBe(resolvedEnvironment.lastDeployment.tierInYaml); + }); + + it('does not display the tier if not defined in yaml', () => { + const environment = { + ...resolvedEnvironment, + lastDeployment: { + ...resolvedEnvironment.lastDeployment, + tierInYaml: null, + }, + }; + wrapper = createWrapper({ + propsData: { environment }, + apolloProvider: createApolloProvider(), + }); + + const tier = wrapper.findByTitle(s__('Environment|Deployment tier')); + + expect(tier.exists()).toBe(false); + }); + }); + describe('url', () => { it('shows a link for the url if one is present', () => { wrapper = createWrapper({ apolloProvider: createApolloProvider() }); diff --git a/spec/frontend/issues/list/components/issue_card_time_info_spec.js b/spec/frontend/issues/list/components/issue_card_time_info_spec.js index c6abf7d20a3..c3f13ca6f9a 100644 --- a/spec/frontend/issues/list/components/issue_card_time_info_spec.js +++ b/spec/frontend/issues/list/components/issue_card_time_info_spec.js @@ -1,6 +1,7 @@ import { GlIcon, GlLink } from '@gitlab/ui'; import { shallowMount } from '@vue/test-utils'; import { useFakeDate } from 'helpers/fake_date'; +import { IssuableStatus } from '~/issues/constants'; import IssueCardTimeInfo from '~/issues/list/components/issue_card_time_info.vue'; describe('CE IssueCardTimeInfo component', () => { @@ -24,7 +25,7 @@ describe('CE IssueCardTimeInfo component', () => { const findDueDate = () => wrapper.find('[data-testid="issuable-due-date"]'); const mountComponent = ({ - closedAt = null, + state = IssuableStatus.Open, dueDate = issue.dueDate, milestoneDueDate = issue.milestone.dueDate, milestoneStartDate = issue.milestone.startDate, @@ -38,7 +39,7 @@ describe('CE IssueCardTimeInfo component', () => { dueDate: milestoneDueDate, startDate: milestoneStartDate, }, - closedAt, + state, dueDate, }, }, @@ -101,7 +102,7 @@ describe('CE IssueCardTimeInfo component', () => { it('does not render in red', () => { wrapper = mountComponent({ dueDate: '2020-10-10', - closedAt: '2020-09-05T13:06:25Z', + state: IssuableStatus.Closed, }); expect(findDueDate().classes()).not.toContain('gl-text-red-500'); diff --git a/spec/frontend/issues/list/mock_data.js b/spec/frontend/issues/list/mock_data.js index c883b20682e..b1a135ceb18 100644 --- a/spec/frontend/issues/list/mock_data.js +++ b/spec/frontend/issues/list/mock_data.js @@ -21,7 +21,6 @@ export const getIssuesQueryResponse = { __typename: 'Issue', id: 'gid://gitlab/Issue/123456', iid: '789', - closedAt: null, confidential: false, createdAt: '2021-05-22T04:08:01Z', downvotes: 2, @@ -30,6 +29,7 @@ export const getIssuesQueryResponse = { humanTimeEstimate: null, mergeRequestsCount: false, moved: false, + state: 'opened', title: 'Issue title', updatedAt: '2021-05-22T04:08:01Z', upvotes: 3, diff --git a/spec/lib/gitlab/background_migration/encrypt_static_object_token_spec.rb b/spec/lib/gitlab/background_migration/encrypt_static_object_token_spec.rb index 94d9f4509a7..4e7b97d33f6 100644 --- a/spec/lib/gitlab/background_migration/encrypt_static_object_token_spec.rb +++ b/spec/lib/gitlab/background_migration/encrypt_static_object_token_spec.rb @@ -39,6 +39,14 @@ RSpec.describe Gitlab::BackgroundMigration::EncryptStaticObjectToken do expect(new_state[user_with_encrypted_token.id]).to match_array([nil, 'encrypted']) end + context 'when id range does not include existing user ids' do + let(:arguments) { [non_existing_record_id, non_existing_record_id.succ] } + + it_behaves_like 'marks background migration job records' do + subject { described_class.new } + end + end + private def create_user!(name:, token: nil, encrypted_token: nil) diff --git a/spec/lib/gitlab/database/each_database_spec.rb b/spec/lib/gitlab/database/each_database_spec.rb index d46c1ca8681..191f7017b4c 100644 --- a/spec/lib/gitlab/database/each_database_spec.rb +++ b/spec/lib/gitlab/database/each_database_spec.rb @@ -58,6 +58,15 @@ RSpec.describe Gitlab::Database::EachDatabase do end end end + + context 'when shared connections are not included' do + it 'only yields the unshared connections' do + expect(Gitlab::Database).to receive(:db_config_share_with).twice.and_return(nil, 'main') + + expect { |b| described_class.each_database_connection(include_shared: false, &b) } + .to yield_successive_args([ActiveRecord::Base.connection, 'main']) + end + end end describe '.each_model_connection' do diff --git a/spec/models/deployment_spec.rb b/spec/models/deployment_spec.rb index 47c246d12cc..973eedf043e 100644 --- a/spec/models/deployment_spec.rb +++ b/spec/models/deployment_spec.rb @@ -1055,6 +1055,40 @@ RSpec.describe Deployment do end end + describe '#tier_in_yaml' do + context 'when deployable is nil' do + before do + subject.deployable = nil + end + + it 'returns nil' do + expect(subject.tier_in_yaml).to be_nil + end + end + + context 'when deployable is present' do + context 'when tier is specified' do + let(:deployable) { create(:ci_build, :success, :environment_with_deployment_tier) } + + before do + subject.deployable = deployable + end + + it 'returns the tier' do + expect(subject.tier_in_yaml).to eq('testing') + end + + context 'when tier is not specified' do + let(:deployable) { create(:ci_build, :success) } + + it 'returns nil' do + expect(subject.tier_in_yaml).to be_nil + end + end + end + end + end + describe '.fast_destroy_all' do it 'cleans path_refs for destroyed environments' do project = create(:project, :repository) 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 d700eb5eaf7..2939a40a84f 100644 --- a/spec/models/error_tracking/project_error_tracking_setting_spec.rb +++ b/spec/models/error_tracking/project_error_tracking_setting_spec.rb @@ -8,6 +8,8 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do let_it_be(:project) { create(:project) } + let(:sentry_client) { instance_double(ErrorTracking::SentryClient) } + subject(:setting) { build(:project_error_tracking_setting, project: project) } describe 'Associations' do @@ -48,7 +50,7 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do expect(subject.errors.messages[:project]).to include('is a required field') end - context 'presence validations' do + describe 'presence validations' do using RSpec::Parameterized::TableSyntax valid_api_url = 'http://example.com/api/0/projects/org-slug/proj-slug/' @@ -83,12 +85,12 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do describe 'after_save :create_client_key!' do subject { build(:project_error_tracking_setting, :integrated, project: project) } - context 'no client key yet' do + context 'without client key' do it 'creates a new client key' do expect { subject.save! }.to change { ErrorTracking::ClientKey.count }.by(1) end - context 'sentry backend' do + context 'with sentry backend' do before do subject.integrated = false end @@ -98,7 +100,7 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do end end - context 'feature disabled' do + context 'when feature disabled' do before do subject.enabled = false end @@ -109,7 +111,7 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do end end - context 'client key already exists' do + context 'when client key already exists' do let!(:client_key) { create(:error_tracking_client_key, project: project) } it 'does not create a new client key' do @@ -122,13 +124,13 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do describe '.extract_sentry_external_url' do subject { described_class.extract_sentry_external_url(sentry_url) } - describe 'when passing a URL' do + context 'when passing a URL' do let(:sentry_url) { 'https://sentrytest.gitlab.com/api/0/projects/sentry-org/sentry-project' } it { is_expected.to eq('https://sentrytest.gitlab.com/sentry-org/sentry-project') } end - describe 'when passing nil' do + context 'when passing nil' do let(:sentry_url) { nil } it { is_expected.to be_nil } @@ -159,23 +161,15 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do describe '#list_sentry_issues' do let(:issues) { [:list, :of, :issues] } - - let(:opts) do - { issue_status: 'unresolved', limit: 10 } - end - - let(:result) do - subject.list_sentry_issues(**opts) - end + let(:result) { subject.list_sentry_issues(**opts) } + let(:opts) { { issue_status: 'unresolved', limit: 10 } } context 'when cached' do - let(:sentry_client) { spy(:sentry_client) } - before do stub_reactive_cache(subject, issues, opts) synchronous_reactive_cache(subject) - expect(subject).to receive(:sentry_client).and_return(sentry_client) + allow(subject).to receive(:sentry_client).and_return(sentry_client) end it 'returns cached issues' do @@ -195,8 +189,6 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do end context 'when sentry client raises ErrorTracking::SentryClient::Error' do - let(:sentry_client) { spy(:sentry_client) } - before do synchronous_reactive_cache(subject) @@ -214,14 +206,13 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do end context 'when sentry client raises ErrorTracking::SentryClient::MissingKeysError' do - let(:sentry_client) { spy(:sentry_client) } - 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"') + .and_raise(ErrorTracking::SentryClient::MissingKeysError, + 'Sentry API response is missing keys. key not found: "id"') end it 'returns error' do @@ -233,8 +224,7 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do end context 'when sentry client raises ErrorTracking::SentryClient::ResponseInvalidSizeError' do - let(:sentry_client) { spy(:sentry_client) } - let(:error_msg) {"Sentry API response is too big. Limit is #{Gitlab::Utils::DeepSize.human_default_max_size}."} + let(:error_msg) { "Sentry API response is too big. Limit is #{Gitlab::Utils::DeepSize.human_default_max_size}." } before do synchronous_reactive_cache(subject) @@ -253,8 +243,6 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do end context 'when sentry client raises StandardError' do - let(:sentry_client) { spy(:sentry_client) } - before do synchronous_reactive_cache(subject) @@ -270,7 +258,6 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do describe '#list_sentry_projects' do let(:projects) { [:list, :of, :projects] } - let(:sentry_client) { spy(:sentry_client) } it 'calls sentry client' do expect(subject).to receive(:sentry_client).and_return(sentry_client) @@ -284,19 +271,17 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do describe '#issue_details' do let(:issue) { build(:error_tracking_sentry_detailed_error) } - let(:sentry_client) { double('sentry_client', issue_details: issue) } let(:commit_id) { issue.first_release_version } - - let(:result) do - subject.issue_details - end + let(:result) { subject.issue_details(opts) } + let(:opts) { { issue_id: 1 } } context 'when cached' do before do stub_reactive_cache(subject, issue, {}) synchronous_reactive_cache(subject) - expect(subject).to receive(:sentry_client).and_return(sentry_client) + allow(subject).to receive(:sentry_client).and_return(sentry_client) + allow(sentry_client).to receive(:issue_details).with(opts).and_return(issue) end it { expect(result).to eq(issue: issue) } @@ -314,15 +299,15 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do end context 'when repo commit matches first relase version' do - let(:commit) { double('commit', id: commit_id) } - let(:repository) { double('repository', commit: commit) } + let(:commit) { instance_double(Commit, id: commit_id) } + let(:repository) { instance_double(Repository, commit: commit) } before do - expect(project).to receive(:repository).and_return(repository) + allow(project).to receive(:repository).and_return(repository) end it { expect(result[:issue].gitlab_commit).to eq(commit_id) } - it { expect(result[:issue].gitlab_commit_path).to eq("/#{project.namespace.path}/#{project.path}/-/commit/#{commit_id}") } + it { expect(result[:issue].gitlab_commit_path).to eq(project_commit_path(project, commit_id)) } end end @@ -333,19 +318,15 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do end describe '#update_issue' do - let(:opts) do - { status: 'resolved' } - end + let(:result) { subject.update_issue(**opts) } + let(:opts) { { issue_id: 1, params: {} } } - let(:result) do - subject.update_issue(**opts) + before do + allow(subject).to receive(:sentry_client).and_return(sentry_client) end - let(:sentry_client) { spy(:sentry_client) } - - context 'successful call to sentry' do + context 'when sentry response is successful' do before do - allow(subject).to receive(:sentry_client).and_return(sentry_client) allow(sentry_client).to receive(:update_issue).with(opts).and_return(true) end @@ -354,9 +335,8 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do end end - context 'sentry raises an error' do + context 'when sentry raises an error' do before do - allow(subject).to receive(:sentry_client).and_return(sentry_client) allow(sentry_client).to receive(:update_issue).with(opts).and_raise(StandardError) end @@ -366,7 +346,7 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do end end - context 'slugs' do + describe 'slugs' do shared_examples_for 'slug from api_url' do |method, slug| context 'when api_url is correct' do before do @@ -393,9 +373,9 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do it_behaves_like 'slug from api_url', :organization_slug, 'org-slug' end - context 'names from api_url' do + describe 'names from api_url' do shared_examples_for 'name from api_url' do |name, titleized_slug| - context 'name is present in DB' do + context 'when name is present in DB' do it 'returns name from DB' do subject[name] = 'Sentry name' subject.api_url = 'http://gitlab.com/api/0/projects/org-slug/project-slug' @@ -404,7 +384,7 @@ RSpec.describe ErrorTracking::ProjectErrorTrackingSetting do end end - context 'name is null in DB' do + context 'when name is null in DB' do it 'titleizes and returns slug from api_url' do subject[name] = nil subject.api_url = 'http://gitlab.com/api/0/projects/org-slug/project-slug' diff --git a/spec/requests/api/issue_links_spec.rb b/spec/requests/api/issue_links_spec.rb index 14e32e48b2b..81dd4c3dfa0 100644 --- a/spec/requests/api/issue_links_spec.rb +++ b/spec/requests/api/issue_links_spec.rb @@ -205,16 +205,30 @@ RSpec.describe API::IssueLinks do end context 'when user has ability to delete the issue link' do + let_it_be(:target_issue) { create(:issue, project: project) } + + before do + project.add_reporter(user) + end + it 'returns 200' do - target_issue = create(:issue, project: project) issue_link = create(:issue_link, source: issue, target: target_issue) - project.add_reporter(user) delete api("/projects/#{project.id}/issues/#{issue.iid}/links/#{issue_link.id}", user) expect(response).to have_gitlab_http_status(:ok) expect(response).to match_response_schema('public_api/v4/issue_link') end + + it 'returns 404 when the issue link does not belong to the specified issue' do + other_issue = create(:issue, project: project) + issue_link = create(:issue_link, source: other_issue, target: target_issue) + + delete api("/projects/#{project.id}/issues/#{issue.iid}/links/#{issue_link.id}", user) + + expect(response).to have_gitlab_http_status(:not_found) + expect(json_response['message']).to eq('404 Not found') + end end end end diff --git a/spec/serializers/deployment_entity_spec.rb b/spec/serializers/deployment_entity_spec.rb index 1dacc9513ee..500d5718bf1 100644 --- a/spec/serializers/deployment_entity_spec.rb +++ b/spec/serializers/deployment_entity_spec.rb @@ -9,7 +9,7 @@ RSpec.describe DeploymentEntity do let(:project) { create(:project, :repository) } let(:request) { double('request') } let(:deployment) { create(:deployment, deployable: build, project: project) } - let(:build) { create(:ci_build, :manual, pipeline: pipeline) } + let(:build) { create(:ci_build, :manual, :environment_with_deployment_tier, pipeline: pipeline) } let(:pipeline) { create(:ci_pipeline, project: project, user: user) } let(:entity) { described_class.new(deployment, request: request) } @@ -46,6 +46,10 @@ RSpec.describe DeploymentEntity do expect(subject).to include(:is_last) end + it 'exposes deployment tier in yaml' do + expect(subject).to include(:tier_in_yaml) + end + context 'when deployable is nil' do let(:entity) { described_class.new(deployment, request: request, deployment_details: false) } let(:deployment) { create(:deployment, deployable: nil, project: project) } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e9f2da93016..1e137ad6fc2 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -237,6 +237,7 @@ RSpec.configure do |config| # Enable all features by default for testing # Reset any changes in after hook. stub_all_feature_flags + stub_feature_flags(main_branch_over_master: false) TestEnv.seed_db end diff --git a/spec/support/shared_examples/models/issuable_link_shared_examples.rb b/spec/support/shared_examples/models/issuable_link_shared_examples.rb index ca98c2597a2..9892e66b582 100644 --- a/spec/support/shared_examples/models/issuable_link_shared_examples.rb +++ b/spec/support/shared_examples/models/issuable_link_shared_examples.rb @@ -55,6 +55,19 @@ RSpec.shared_examples 'issuable link' do end end + describe 'scopes' do + describe '.for_source_or_target' do + it 'returns only links where id is either source or target id' do + link1 = create(issuable_link_factory, source: issuable_link.source) + link2 = create(issuable_link_factory, target: issuable_link.source) + # unrelated link, should not be included in result list + create(issuable_link_factory) # rubocop: disable Rails/SaveBang + + expect(described_class.for_source_or_target(issuable_link.source_id)).to match_array([issuable_link, link1, link2]) + end + end + end + describe '.link_type' do it { is_expected.to define_enum_for(:link_type).with_values(relates_to: 0, blocks: 1) } diff --git a/spec/tasks/gitlab/db/validate_config_rake_spec.rb b/spec/tasks/gitlab/db/validate_config_rake_spec.rb index 4924ecc0ec9..7b2f37414a0 100644 --- a/spec/tasks/gitlab/db/validate_config_rake_spec.rb +++ b/spec/tasks/gitlab/db/validate_config_rake_spec.rb @@ -53,6 +53,18 @@ RSpec.describe 'gitlab:db:validate_config', :silence_stdout do expect { run_rake_task('gitlab:db:validate_config') }.not_to output(/Database config validation failure/).to_stderr expect { run_rake_task('gitlab:db:validate_config') }.not_to raise_error end + + context 'when finding the initializer fails' do + where(:raised_error) { [ActiveRecord::NoDatabaseError, ActiveRecord::ConnectionNotEstablished, PG::ConnectionBad] } + with_them do + it "does not raise an error for #{params[:raised_error]}" do + allow(ActiveRecord::Base.connection).to receive(:select_one).and_raise(raised_error) # rubocop: disable Database/MultipleDatabases + + expect { run_rake_task('gitlab:db:validate_config') }.not_to output(/Database config validation failure/).to_stderr + expect { run_rake_task('gitlab:db:validate_config') }.not_to raise_error + end + end + end end shared_examples 'raises an error' do |match| diff --git a/spec/tasks/gitlab/setup_rake_spec.rb b/spec/tasks/gitlab/setup_rake_spec.rb index 6e4d5087517..6b4dde22dca 100644 --- a/spec/tasks/gitlab/setup_rake_spec.rb +++ b/spec/tasks/gitlab/setup_rake_spec.rb @@ -22,7 +22,11 @@ RSpec.describe 'gitlab:setup namespace rake tasks', :silence_stdout do let(:server_service1) { double(:server_service) } let(:server_service2) { double(:server_service) } - let(:connections) { Gitlab::Database.database_base_models.values.map(&:connection) } + let(:connections) do + Gitlab::Database.database_base_models.values.filter_map do |model| + model.connection if Gitlab::Database.db_config_share_with(model.connection_db_config).nil? + end + end before do allow(Gitlab).to receive_message_chain('config.repositories.storages').and_return(storages) @@ -119,6 +123,10 @@ RSpec.describe 'gitlab:setup namespace rake tasks', :silence_stdout do end def expect_connections_to_be_terminated + expect(Gitlab::Database::EachDatabase).to receive(:each_database_connection) + .with(include_shared: false) + .and_call_original + expect(connections).to all(receive(:execute).with(/SELECT pg_terminate_backend/)) end diff --git a/spec/workers/container_registry/migration/enqueuer_worker_spec.rb b/spec/workers/container_registry/migration/enqueuer_worker_spec.rb index ca839dc4bcb..00fab58992a 100644 --- a/spec/workers/container_registry/migration/enqueuer_worker_spec.rb +++ b/spec/workers/container_registry/migration/enqueuer_worker_spec.rb @@ -64,7 +64,8 @@ RSpec.describe ContainerRegistry::Migration::EnqueuerWorker, :aggregate_failures expect_log_extra_metadata( import_type: 'next', container_repository_id: container_repository.id, - container_repository_path: container_repository.path + container_repository_path: container_repository.path, + container_repository_migration_state: 'pre_importing' ) subject @@ -135,7 +136,8 @@ RSpec.describe ContainerRegistry::Migration::EnqueuerWorker, :aggregate_failures expect_log_extra_metadata( import_type: 'retry', container_repository_id: aborted_repository.id, - container_repository_path: aborted_repository.path + container_repository_path: aborted_repository.path, + container_repository_migration_state: 'importing' ) subject @@ -158,7 +160,8 @@ RSpec.describe ContainerRegistry::Migration::EnqueuerWorker, :aggregate_failures expect_log_extra_metadata( import_type: 'retry', container_repository_id: aborted_repository.id, - container_repository_path: aborted_repository.path + container_repository_path: aborted_repository.path, + container_repository_migration_state: 'import_aborted' ) subject @@ -189,6 +192,7 @@ RSpec.describe ContainerRegistry::Migration::EnqueuerWorker, :aggregate_failures import_type: 'next', container_repository_id: container_repository.id, container_repository_path: container_repository.path, + container_repository_migration_state: 'import_skipped', tags_count_too_high: true, max_tags_count_setting: 2 ) @@ -212,7 +216,8 @@ RSpec.describe ContainerRegistry::Migration::EnqueuerWorker, :aggregate_failures expect_log_extra_metadata( import_type: 'next', container_repository_id: container_repository.id, - container_repository_path: container_repository.path + container_repository_path: container_repository.path, + container_repository_migration_state: 'import_aborted' ) expect(Gitlab::ErrorTracking).to receive(:log_exception).with( |