diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-09-08 21:10:02 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-09-08 21:10:02 +0300 |
commit | 375b68fe813abba5e362aa6054eae7b325e92e03 (patch) | |
tree | 3d02fc54f6c38beb92f6e592452dd5f5884fab0b /spec | |
parent | 132b8909c81349a88317a00b94c1de97e2db4b74 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/factories/packages/nuget/symbol.rb | 11 | ||||
-rw-r--r-- | spec/features/projects/jobs_spec.rb | 4 | ||||
-rw-r--r-- | spec/fixtures/packages/nuget/symbol/package.pdb | bin | 0 -> 10588 bytes | |||
-rw-r--r-- | spec/frontend/jobs/components/job/job_sidebar_details_container_spec.js | 3 | ||||
-rw-r--r-- | spec/frontend/jobs/components/job/stages_dropdown_spec.js | 4 | ||||
-rw-r--r-- | spec/graphql/resolvers/branch_commit_resolver_spec.rb | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/metrics/samplers/database_sampler_spec.rb | 78 | ||||
-rw-r--r-- | spec/models/concerns/routable_spec.rb | 49 | ||||
-rw-r--r-- | spec/models/packages/nuget/symbol_spec.rb | 70 | ||||
-rw-r--r-- | spec/models/packages/package_spec.rb | 1 | ||||
-rw-r--r-- | spec/uploaders/packages/nuget/symbol_uploader_spec.rb | 28 |
11 files changed, 177 insertions, 73 deletions
diff --git a/spec/factories/packages/nuget/symbol.rb b/spec/factories/packages/nuget/symbol.rb new file mode 100644 index 00000000000..7ab1e026cda --- /dev/null +++ b/spec/factories/packages/nuget/symbol.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :nuget_symbol, class: 'Packages::Nuget::Symbol' do + package { association(:nuget_package) } + file { fixture_file_upload('spec/fixtures/packages/nuget/symbol/package.pdb') } + file_path { 'lib/net7.0/package.pdb' } + size { 100.bytes } + sequence(:signature) { |n| "b91a152048fc4b3883bf3cf73fbc03f#{n}FFFFFFFF" } + end +end diff --git a/spec/features/projects/jobs_spec.rb b/spec/features/projects/jobs_spec.rb index 5a8cee5ef6e..67486b545c9 100644 --- a/spec/features/projects/jobs_spec.rb +++ b/spec/features/projects/jobs_spec.rb @@ -93,7 +93,7 @@ RSpec.describe 'Jobs', :clean_gitlab_redis_shared_state, feature_category: :grou visit project_job_path(project, job) within '.js-pipeline-info' do - expect(page).to have_content("Pipeline ##{pipeline.id} #{pipeline.status} for #{pipeline.ref}") + expect(page).to have_content("Pipeline ##{pipeline.id} for #{pipeline.ref}") end end @@ -239,7 +239,7 @@ RSpec.describe 'Jobs', :clean_gitlab_redis_shared_state, feature_category: :grou href = new_project_issue_path(project, options) - page.within('aside.right-sidebar') do + page.within('.build-sidebar') do expect(find('[data-testid="job-new-issue"]')['href']).to include(href) end end diff --git a/spec/fixtures/packages/nuget/symbol/package.pdb b/spec/fixtures/packages/nuget/symbol/package.pdb Binary files differnew file mode 100644 index 00000000000..dc82bf418a2 --- /dev/null +++ b/spec/fixtures/packages/nuget/symbol/package.pdb diff --git a/spec/frontend/jobs/components/job/job_sidebar_details_container_spec.js b/spec/frontend/jobs/components/job/job_sidebar_details_container_spec.js index 0b704890d57..c1028f3929d 100644 --- a/spec/frontend/jobs/components/job/job_sidebar_details_container_spec.js +++ b/spec/frontend/jobs/components/job/job_sidebar_details_container_spec.js @@ -53,7 +53,6 @@ describe('Job Sidebar Details Container', () => { ['erased_at', 'Erased: 3 weeks ago'], ['finished_at', 'Finished: 3 weeks ago'], ['queued_duration', 'Queued: 9 seconds'], - ['id', 'Job ID: #4757'], ['runner', 'Runner: #1 (ABCDEFGH) local ci runner'], ['coverage', 'Coverage: 20%'], ])('uses %s to render job-%s', async (detail, value) => { @@ -78,7 +77,7 @@ describe('Job Sidebar Details Container', () => { createWrapper(); await store.dispatch('receiveJobSuccess', job); - expect(findAllDetailsRow()).toHaveLength(8); + expect(findAllDetailsRow()).toHaveLength(7); }); describe('duration row', () => { diff --git a/spec/frontend/jobs/components/job/stages_dropdown_spec.js b/spec/frontend/jobs/components/job/stages_dropdown_spec.js index 780193b33d0..c42edc62183 100644 --- a/spec/frontend/jobs/components/job/stages_dropdown_spec.js +++ b/spec/frontend/jobs/components/job/stages_dropdown_spec.js @@ -3,7 +3,7 @@ import { shallowMount } from '@vue/test-utils'; import { Mousetrap } from '~/lib/mousetrap'; import { extendedWrapper } from 'helpers/vue_test_utils_helper'; import StagesDropdown from '~/jobs/components/job/sidebar/stages_dropdown.vue'; -import CiBadgeLink from '~/vue_shared/components/ci_badge_link.vue'; +import CiIcon from '~/vue_shared/components/ci_icon.vue'; import * as copyToClipboard from '~/behaviors/copy_to_clipboard'; import { mockPipelineWithoutRef, @@ -15,7 +15,7 @@ import { describe('Stages Dropdown', () => { let wrapper; - const findStatus = () => wrapper.findComponent(CiBadgeLink); + const findStatus = () => wrapper.findComponent(CiIcon); const findDropdown = () => wrapper.findComponent(GlDisclosureDropdown); const findSelectedStageText = () => findDropdown().props('toggleText'); diff --git a/spec/graphql/resolvers/branch_commit_resolver_spec.rb b/spec/graphql/resolvers/branch_commit_resolver_spec.rb index 3d5702539fa..f901306a355 100644 --- a/spec/graphql/resolvers/branch_commit_resolver_spec.rb +++ b/spec/graphql/resolvers/branch_commit_resolver_spec.rb @@ -32,7 +32,7 @@ RSpec.describe Resolvers::BranchCommitResolver do commit_a = repository.commits('master', limit: 1).last commit_b = repository.commits('spooky-stuff', limit: 1).last - commits = batch_sync(max_queries: 1) do + commits = batch_sync(max_queries: 2) do [ resolve(described_class, obj: branch), resolve(described_class, obj: repository.find_branch('spooky-stuff')) diff --git a/spec/lib/gitlab/metrics/samplers/database_sampler_spec.rb b/spec/lib/gitlab/metrics/samplers/database_sampler_spec.rb index 57790ad78a8..85e8b366f29 100644 --- a/spec/lib/gitlab/metrics/samplers/database_sampler_spec.rb +++ b/spec/lib/gitlab/metrics/samplers/database_sampler_spec.rb @@ -8,6 +8,32 @@ RSpec.describe Gitlab::Metrics::Samplers::DatabaseSampler do it_behaves_like 'metrics sampler', 'DATABASE_SAMPLER' describe '#sample' do + let(:main_load_balancer) do + double(:main_load_balancer, host_list: main_host_list, configuration: main_configuration, primary_only?: false) + end + + let(:main_configuration) { double(:configuration, connection_specification_name: 'ActiveRecord::Base') } + let(:main_host_list) { double(:host_list, hosts: [main_replica_host]) } + let(:main_replica_host) { double(:host, pool: main_replica_pool, host: 'main-replica-host', port: 2345) } + let(:main_replica_pool) do + double(:main_replica_pool, db_config: double(:main_replica_db_config, name: 'main_replica'), stat: stats) + end + + let(:stats) do + { size: 123, connections: 100, busy: 10, dead: 5, idle: 85, waiting: 1 } + end + + let(:ci_load_balancer) do + double(:ci_load_balancer, host_list: ci_host_list, configuration: ci_configuration, primary_only?: false) + end + + let(:ci_configuration) { double(:configuration, connection_specification_name: 'Ci::ApplicationRecord') } + let(:ci_host_list) { double(:host_list, hosts: [ci_replica_host]) } + let(:ci_replica_host) { double(:host, pool: ci_replica_pool, host: 'ci-replica-host', port: 3456) } + let(:ci_replica_pool) do + double(:ci_replica_pool, db_config: double(:ci_replica_db_config, name: 'ci_replica'), stat: stats) + end + let(:main_labels) do { class: 'ActiveRecord::Base', @@ -62,35 +88,9 @@ RSpec.describe Gitlab::Metrics::Samplers::DatabaseSampler do end context 'when replica hosts are configured' do - let(:main_load_balancer) { ApplicationRecord.load_balancer } - let(:main_replica_host) { main_load_balancer.host } - - let(:ci_load_balancer) { double(:load_balancer, host_list: ci_host_list, configuration: configuration) } - let(:configuration) { double(:configuration, connection_specification_name: 'Ci::ApplicationRecord') } - let(:ci_host_list) { double(:host_list, hosts: [ci_replica_host]) } - let(:ci_replica_host) { double(:host, connection: ci_connection) } - let(:ci_connection) { double(:connection, pool: Ci::ApplicationRecord.connection_pool) } - before do allow(Gitlab::Database::LoadBalancing).to receive(:each_load_balancer) .and_return([main_load_balancer, ci_load_balancer].to_enum) - - allow(main_load_balancer).to receive(:primary_only?).and_return(false) - allow(ci_load_balancer).to receive(:primary_only?).and_return(false) - - allow(main_replica_host).to receive(:host).and_return('main-replica-host') - allow(ci_replica_host).to receive(:host).and_return('ci-replica-host') - - allow(main_replica_host).to receive(:port).and_return(2345) - allow(ci_replica_host).to receive(:port).and_return(3456) - - allow(Gitlab::Database).to receive(:db_config_name) - .with(main_replica_host.connection) - .and_return('main_replica') - - allow(Gitlab::Database).to receive(:db_config_name) - .with(ci_replica_host.connection) - .and_return('ci_replica') end it 'samples connection pool statistics for primaries and replicas' do @@ -117,35 +117,9 @@ RSpec.describe Gitlab::Metrics::Samplers::DatabaseSampler do end context 'when the base model has replica connections' do - let(:main_load_balancer) { ApplicationRecord.load_balancer } - let(:main_replica_host) { main_load_balancer.host } - - let(:ci_load_balancer) { double(:load_balancer, host_list: ci_host_list, configuration: configuration) } - let(:configuration) { double(:configuration, connection_specification_name: 'Ci::ApplicationRecord') } - let(:ci_host_list) { double(:host_list, hosts: [ci_replica_host]) } - let(:ci_replica_host) { double(:host, connection: ci_connection) } - let(:ci_connection) { double(:connection, pool: Ci::ApplicationRecord.connection_pool) } - before do allow(Gitlab::Database::LoadBalancing).to receive(:each_load_balancer) .and_return([main_load_balancer, ci_load_balancer].to_enum) - - allow(main_load_balancer).to receive(:primary_only?).and_return(false) - allow(ci_load_balancer).to receive(:primary_only?).and_return(false) - - allow(main_replica_host).to receive(:host).and_return('main-replica-host') - allow(ci_replica_host).to receive(:host).and_return('ci-replica-host') - - allow(main_replica_host).to receive(:port).and_return(2345) - allow(ci_replica_host).to receive(:port).and_return(3456) - - allow(Gitlab::Database).to receive(:db_config_name) - .with(main_replica_host.connection) - .and_return('main_replica') - - allow(Gitlab::Database).to receive(:db_config_name) - .with(ci_replica_host.connection) - .and_return('ci_replica') end it 'still records the replica metrics' do diff --git a/spec/models/concerns/routable_spec.rb b/spec/models/concerns/routable_spec.rb index 0bbe3dea812..64812454b1a 100644 --- a/spec/models/concerns/routable_spec.rb +++ b/spec/models/concerns/routable_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' RSpec.shared_examples 'routable resource' do - describe '.find_by_full_path', :aggregate_failures do + shared_examples_for '.find_by_full_path' do it 'finds records by their full path' do expect(described_class.find_by_full_path(record.full_path)).to eq(record) expect(described_class.find_by_full_path(record.full_path.upcase)).to eq(record) @@ -13,16 +13,6 @@ RSpec.shared_examples 'routable resource' do expect(described_class.find_by_full_path('unknown')).to be_nil end - it 'includes route information when loading a record' do - control_count = ActiveRecord::QueryRecorder.new do - described_class.find_by_full_path(record.full_path) - end.count - - expect do - described_class.find_by_full_path(record.full_path).route - end.not_to exceed_all_query_limit(control_count) - end - context 'when path is a negative number' do it 'returns nil' do expect(described_class.find_by_full_path(-1)).to be_nil @@ -56,6 +46,26 @@ RSpec.shared_examples 'routable resource' do end end end + + it_behaves_like '.find_by_full_path', :aggregate_failures + + context 'when the `optimize_routable` feature flag is turned OFF' do + before do + stub_feature_flags(optimize_routable: false) + end + + it_behaves_like '.find_by_full_path', :aggregate_failures + + it 'includes route information when loading a record' do + control_count = ActiveRecord::QueryRecorder.new do + described_class.find_by_full_path(record.full_path) + end.count + + expect do + described_class.find_by_full_path(record.full_path).route + end.not_to exceed_all_query_limit(control_count) + end + end end RSpec.shared_examples 'routable resource with parent' do @@ -93,7 +103,7 @@ RSpec.shared_examples 'routable resource with parent' do end end -RSpec.describe Group, 'Routable', :with_clean_rails_cache do +RSpec.describe Group, 'Routable', :with_clean_rails_cache, feature_category: :groups_and_projects do let_it_be_with_reload(:group) { create(:group, name: 'foo') } let_it_be(:nested_group) { create(:group, parent: group) } @@ -223,7 +233,7 @@ RSpec.describe Group, 'Routable', :with_clean_rails_cache do end end -RSpec.describe Project, 'Routable', :with_clean_rails_cache do +RSpec.describe Project, 'Routable', :with_clean_rails_cache, feature_category: :groups_and_projects do let_it_be(:namespace) { create(:namespace) } let_it_be(:project) { create(:project, namespace: namespace) } @@ -235,9 +245,20 @@ RSpec.describe Project, 'Routable', :with_clean_rails_cache do expect(project.route).not_to be_nil expect(project.route.namespace).to eq(project.project_namespace) end + + describe '.find_by_full_path' do + it 'does not return a record if the sources are different, but the IDs match' do + group = create(:group, id: 1992) + project = create(:project, id: 1992) + + record = described_class.where(id: project.id).find_by_full_path(group.full_path) + + expect(record).to be_nil + end + end end -RSpec.describe Namespaces::ProjectNamespace, 'Routable', :with_clean_rails_cache do +RSpec.describe Namespaces::ProjectNamespace, 'Routable', :with_clean_rails_cache, feature_category: :groups_and_projects do let_it_be(:group) { create(:group) } it 'skips route creation for the resource' do diff --git a/spec/models/packages/nuget/symbol_spec.rb b/spec/models/packages/nuget/symbol_spec.rb new file mode 100644 index 00000000000..52e95c11939 --- /dev/null +++ b/spec/models/packages/nuget/symbol_spec.rb @@ -0,0 +1,70 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Packages::Nuget::Symbol, type: :model, feature_category: :package_registry do + subject(:symbol) { create(:nuget_symbol) } + + it { is_expected.to be_a FileStoreMounter } + + describe 'relationships' do + it { is_expected.to belong_to(:package).inverse_of(:nuget_symbols) } + end + + describe 'validations' do + it { is_expected.to validate_presence_of(:file) } + it { is_expected.to validate_presence_of(:file_path) } + it { is_expected.to validate_presence_of(:signature) } + it { is_expected.to validate_presence_of(:object_storage_key) } + it { is_expected.to validate_presence_of(:size) } + it { is_expected.to validate_uniqueness_of(:signature).scoped_to(:file_path) } + it { is_expected.to validate_uniqueness_of(:object_storage_key).case_insensitive } + end + + describe 'delegations' do + it { is_expected.to delegate_method(:project_id).to(:package) } + end + + describe 'callbacks' do + describe 'before_validation' do + describe '#set_object_storage_key' do + context 'when signature and project_id are present' do + it 'sets the object_storage_key' do + expected_key = Gitlab::HashedPath.new( + 'packages', 'nuget', symbol.package_id, 'symbols', OpenSSL::Digest::SHA256.hexdigest(symbol.signature), + root_hash: symbol.project_id + ).to_s + + symbol.valid? + + expect(symbol.object_storage_key).to eq(expected_key) + end + end + + context 'when signature is not present' do + subject(:symbol) { build(:nuget_symbol, signature: nil) } + + it 'does not set the object_storage_key' do + symbol.valid? + + expect(symbol.object_storage_key).to be_nil + end + end + + context 'when project_id is not present' do + subject(:symbol) { build(:nuget_symbol) } + + before do + allow(symbol).to receive(:project_id).and_return(nil) + end + + it 'does not set the object_storage_key' do + symbol.valid? + + expect(symbol.object_storage_key).to be_nil + end + end + end + end + end +end diff --git a/spec/models/packages/package_spec.rb b/spec/models/packages/package_spec.rb index 74ad2925058..e113218e828 100644 --- a/spec/models/packages/package_spec.rb +++ b/spec/models/packages/package_spec.rb @@ -25,6 +25,7 @@ RSpec.describe Packages::Package, type: :model, feature_category: :package_regis it { is_expected.to have_one(:rubygems_metadatum).inverse_of(:package) } it { is_expected.to have_one(:npm_metadatum).inverse_of(:package) } it { is_expected.to have_one(:rpm_metadatum).inverse_of(:package) } + it { is_expected.to have_many(:nuget_symbols).inverse_of(:package) } end describe '.with_debian_codename' do diff --git a/spec/uploaders/packages/nuget/symbol_uploader_spec.rb b/spec/uploaders/packages/nuget/symbol_uploader_spec.rb new file mode 100644 index 00000000000..bdcb5245c1c --- /dev/null +++ b/spec/uploaders/packages/nuget/symbol_uploader_spec.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Packages::Nuget::SymbolUploader, feature_category: :package_registry do + let(:object_storage_key) { 'object/storage/key' } + let(:symbol) { build_stubbed(:nuget_symbol, object_storage_key: object_storage_key) } + + subject { described_class.new(symbol, :file) } + + describe '#store_dir' do + it 'uses the object_storage_key' do + expect(subject.store_dir).to eq(object_storage_key) + end + + context 'without the object_storage_key' do + let(:object_storage_key) { nil } + + it 'raises the error' do + expect { subject.store_dir } + .to raise_error( + described_class::ObjectNotReadyError, + 'Packages::Nuget::Symbol model not ready' + ) + end + end + end +end |