diff options
Diffstat (limited to 'spec/lib')
12 files changed, 100 insertions, 80 deletions
diff --git a/spec/lib/gitlab/background_migration/backfill_project_repositories_spec.rb b/spec/lib/gitlab/background_migration/backfill_project_repositories_spec.rb index d601b0f064d..510a0074554 100644 --- a/spec/lib/gitlab/background_migration/backfill_project_repositories_spec.rb +++ b/spec/lib/gitlab/background_migration/backfill_project_repositories_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' # rubocop:disable RSpec/FactoriesInMigrationSpecs -describe Gitlab::BackgroundMigration::BackfillProjectRepositories, schema: :latest do +describe Gitlab::BackgroundMigration::BackfillProjectRepositories do let(:group) { create(:group, name: 'foo', path: 'foo') } describe described_class::ShardFinder do diff --git a/spec/lib/gitlab/background_migration/legacy_upload_mover_spec.rb b/spec/lib/gitlab/background_migration/legacy_upload_mover_spec.rb index ff82a6580df..850ef48d44a 100644 --- a/spec/lib/gitlab/background_migration/legacy_upload_mover_spec.rb +++ b/spec/lib/gitlab/background_migration/legacy_upload_mover_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' # rubocop: disable RSpec/FactoriesInMigrationSpecs -describe Gitlab::BackgroundMigration::LegacyUploadMover, schema: :latest do +describe Gitlab::BackgroundMigration::LegacyUploadMover do let(:test_dir) { FileUploader.options['storage_path'] } let(:filename) { 'image.png' } diff --git a/spec/lib/gitlab/background_migration/legacy_uploads_migrator_spec.rb b/spec/lib/gitlab/background_migration/legacy_uploads_migrator_spec.rb index 0c0ce3acf0e..85187d039c1 100644 --- a/spec/lib/gitlab/background_migration/legacy_uploads_migrator_spec.rb +++ b/spec/lib/gitlab/background_migration/legacy_uploads_migrator_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' # rubocop: disable RSpec/FactoriesInMigrationSpecs -describe Gitlab::BackgroundMigration::LegacyUploadsMigrator, schema: :latest do +describe Gitlab::BackgroundMigration::LegacyUploadsMigrator do let(:test_dir) { FileUploader.options['storage_path'] } let!(:hashed_project) { create(:project) } diff --git a/spec/lib/gitlab/background_migration/merge_request_assignees_migration_progress_check_spec.rb b/spec/lib/gitlab/background_migration/merge_request_assignees_migration_progress_check_spec.rb index 0d8fc3e7c53..eecd290e3ca 100644 --- a/spec/lib/gitlab/background_migration/merge_request_assignees_migration_progress_check_spec.rb +++ b/spec/lib/gitlab/background_migration/merge_request_assignees_migration_progress_check_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::BackgroundMigration::MergeRequestAssigneesMigrationProgressCheck, schema: :latest do +describe Gitlab::BackgroundMigration::MergeRequestAssigneesMigrationProgressCheck do context 'rescheduling' do context 'when there are ongoing and no dead jobs' do it 'reschedules check' do diff --git a/spec/lib/gitlab/background_migration_spec.rb b/spec/lib/gitlab/background_migration_spec.rb index cff6a42d242..71959f54b38 100644 --- a/spec/lib/gitlab/background_migration_spec.rb +++ b/spec/lib/gitlab/background_migration_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::BackgroundMigration, schema: :latest do +describe Gitlab::BackgroundMigration do describe '.queue' do it 'returns background migration worker queue' do expect(described_class.queue) diff --git a/spec/lib/gitlab/bitbucket_import/importer_spec.rb b/spec/lib/gitlab/bitbucket_import/importer_spec.rb index b0d07c6e0b0..b95175efc0c 100644 --- a/spec/lib/gitlab/bitbucket_import/importer_spec.rb +++ b/spec/lib/gitlab/bitbucket_import/importer_spec.rb @@ -80,8 +80,7 @@ describe Gitlab::BitbucketImport::Importer do end let(:importer) { described_class.new(project) } - let(:gitlab_shell) { double } - + let(:sample) { RepoHelpers.sample_compare } let(:issues_statuses_sample_data) do { count: sample_issues_statuses.count, @@ -89,12 +88,6 @@ describe Gitlab::BitbucketImport::Importer do } end - let(:sample) { RepoHelpers.sample_compare } - - before do - allow(importer).to receive(:gitlab_shell) { gitlab_shell } - end - subject { described_class.new(project) } describe '#import_pull_requests' do @@ -316,7 +309,7 @@ describe Gitlab::BitbucketImport::Importer do describe 'wiki import' do it 'is skipped when the wiki exists' do expect(project.wiki).to receive(:repository_exists?) { true } - expect(importer.gitlab_shell).not_to receive(:import_wiki_repository) + expect(project.wiki.repository).not_to receive(:import_repository) importer.execute @@ -325,7 +318,7 @@ describe Gitlab::BitbucketImport::Importer do it 'imports to the project disk_path' do expect(project.wiki).to receive(:repository_exists?) { false } - expect(importer.gitlab_shell).to receive(:import_wiki_repository) + expect(project.wiki.repository).to receive(:import_repository) importer.execute diff --git a/spec/lib/gitlab/git/repository_spec.rb b/spec/lib/gitlab/git/repository_spec.rb index a2326728679..b706cad612a 100644 --- a/spec/lib/gitlab/git/repository_spec.rb +++ b/spec/lib/gitlab/git/repository_spec.rb @@ -2138,6 +2138,33 @@ describe Gitlab::Git::Repository, :seed_helper do end end + describe '#import_repository' do + let_it_be(:project) { create(:project) } + + let(:repository) { project.repository } + let(:url) { 'http://invalid.invalid' } + + it 'raises an error if a relative path is provided' do + expect { repository.import_repository('/foo') }.to raise_error(ArgumentError, /disk path/) + end + + it 'raises an error if an absolute path is provided' do + expect { repository.import_repository('./foo') }.to raise_error(ArgumentError, /disk path/) + end + + it 'delegates to Gitaly' do + expect_next_instance_of(Gitlab::GitalyClient::RepositoryService) do |svc| + expect(svc).to receive(:import_repository).with(url).and_return(nil) + end + + repository.import_repository(url) + end + + it_behaves_like 'wrapping gRPC errors', Gitlab::GitalyClient::RepositoryService, :import_repository do + subject { repository.import_repository('http://invalid.invalid') } + end + end + describe '#replicate' do let(:new_repository) do Gitlab::Git::Repository.new('test_second_storage', TEST_REPO_PATH, '', 'group/project') diff --git a/spec/lib/gitlab/github_import/importer/repository_importer_spec.rb b/spec/lib/gitlab/github_import/importer/repository_importer_spec.rb index c65b28fafbf..e26ac7bf81e 100644 --- a/spec/lib/gitlab/github_import/importer/repository_importer_spec.rb +++ b/spec/lib/gitlab/github_import/importer/repository_importer_spec.rb @@ -11,10 +11,15 @@ describe Gitlab::GithubImport::Importer::RepositoryImporter do double( :wiki, disk_path: 'foo.wiki', - full_path: 'group/foo.wiki' + full_path: 'group/foo.wiki', + repository: wiki_repository ) end + let(:wiki_repository) do + double(:wiki_repository) + end + let(:project) do double( :project, @@ -221,17 +226,19 @@ describe Gitlab::GithubImport::Importer::RepositoryImporter do describe '#import_wiki_repository' do it 'imports the wiki repository' do - expect(importer.gitlab_shell) + expect(wiki_repository) .to receive(:import_repository) - .with('foo', 'foo.wiki', 'foo.wiki.git', 'group/foo.wiki') + .with(importer.wiki_url) + .and_return(true) expect(importer.import_wiki_repository).to eq(true) end it 'marks the import as failed and creates an empty repo if an error was raised' do - expect(importer.gitlab_shell) + expect(wiki_repository) .to receive(:import_repository) - .and_raise(Gitlab::Shell::Error) + .with(importer.wiki_url) + .and_raise(Gitlab::Git::CommandError) expect(importer) .to receive(:fail_import) diff --git a/spec/lib/gitlab/legacy_github_import/importer_spec.rb b/spec/lib/gitlab/legacy_github_import/importer_spec.rb index 23df970957a..af0bffa91a5 100644 --- a/spec/lib/gitlab/legacy_github_import/importer_spec.rb +++ b/spec/lib/gitlab/legacy_github_import/importer_spec.rb @@ -45,7 +45,7 @@ describe Gitlab::LegacyGithubImport::Importer do allow(Rails).to receive(:cache).and_return(ActiveSupport::Cache::MemoryStore.new) allow_any_instance_of(Octokit::Client).to receive(:rate_limit!).and_raise(Octokit::NotFound) - allow_any_instance_of(Gitlab::Shell).to receive(:import_repository).and_raise(Gitlab::Shell::Error) + allow(project.wiki.repository).to receive(:import_repository).and_raise(Gitlab::Git::CommandError) allow_any_instance_of(Octokit::Client).to receive(:user).and_return(octocat) allow_any_instance_of(Octokit::Client).to receive(:labels).and_return([label1, label2]) @@ -169,7 +169,7 @@ describe Gitlab::LegacyGithubImport::Importer do errors: [ { type: :label, url: "#{api_root}/repos/octocat/Hello-World/labels/bug", errors: "Validation failed: Title can't be blank, Title is invalid" }, { type: :issue, url: "#{api_root}/repos/octocat/Hello-World/issues/1348", errors: "Validation failed: Title can't be blank" }, - { type: :wiki, errors: "Gitlab::Shell::Error" } + { type: :wiki, errors: "Gitlab::Git::CommandError" } ] } diff --git a/spec/lib/gitlab/shell_spec.rb b/spec/lib/gitlab/shell_spec.rb index 3ea9f71d3a6..e4c33863ac2 100644 --- a/spec/lib/gitlab/shell_spec.rb +++ b/spec/lib/gitlab/shell_spec.rb @@ -9,7 +9,6 @@ describe Gitlab::Shell do let(:gitlab_shell) { described_class.new } it { is_expected.to respond_to :remove_repository } - it { is_expected.to respond_to :fork_repository } describe '.url_to_repo' do let(:full_path) { 'diaspora/disaspora-rails' } @@ -95,52 +94,6 @@ describe Gitlab::Shell do expect(TestEnv.storage_dir_exists?(project2.repository_storage, "#{project2.disk_path}.git")).to be(true) end end - - describe '#fork_repository' do - let(:target_project) { create(:project) } - - subject do - gitlab_shell.fork_repository(project, target_project) - end - - it 'returns true when the command succeeds' do - expect_any_instance_of(Gitlab::GitalyClient::RepositoryService).to receive(:fork_repository) - .with(repository.raw_repository) { :gitaly_response_object } - - is_expected.to be_truthy - end - - it 'return false when the command fails' do - expect_any_instance_of(Gitlab::GitalyClient::RepositoryService).to receive(:fork_repository) - .with(repository.raw_repository) { raise GRPC::BadStatus, 'bla' } - - is_expected.to be_falsy - end - end - - describe '#import_repository' do - let(:import_url) { 'https://gitlab.com/gitlab-org/gitlab-foss.git' } - - context 'with gitaly' do - it 'returns true when the command succeeds' do - expect_any_instance_of(Gitlab::GitalyClient::RepositoryService).to receive(:import_repository).with(import_url) - - result = gitlab_shell.import_repository(project.repository_storage, project.disk_path, import_url, project.full_path) - - expect(result).to be_truthy - end - - it 'raises an exception when the command fails' do - expect_any_instance_of(Gitlab::GitalyClient::RepositoryService).to receive(:import_repository) - .with(import_url) { raise GRPC::BadStatus, 'bla' } - expect_any_instance_of(Gitlab::Shell::GitalyGitlabProjects).to receive(:output) { 'error'} - - expect do - gitlab_shell.import_repository(project.repository_storage, project.disk_path, import_url, project.full_path) - end.to raise_error(Gitlab::Shell::Error, "error") - end - end - end end describe 'namespace actions' do diff --git a/spec/lib/gitlab/sidekiq_cluster/cli_spec.rb b/spec/lib/gitlab/sidekiq_cluster/cli_spec.rb index 8b31b8ade68..5bda8ff8c72 100644 --- a/spec/lib/gitlab/sidekiq_cluster/cli_spec.rb +++ b/spec/lib/gitlab/sidekiq_cluster/cli_spec.rb @@ -36,11 +36,13 @@ describe Gitlab::SidekiqCluster::CLI do end it 'allows the special * selector' do + worker_queues = %w(foo bar baz) + + expect(Gitlab::SidekiqConfig::CliMethods) + .to receive(:worker_queues).and_return(worker_queues) + expect(Gitlab::SidekiqCluster) - .to receive(:start).with( - [Gitlab::SidekiqConfig::CliMethods.worker_queues], - default_options - ) + .to receive(:start).with([worker_queues], default_options) cli.run(%w(*)) end @@ -157,15 +159,17 @@ describe Gitlab::SidekiqCluster::CLI do .with([['chat_notification'], ['project_export']], default_options) .and_return([]) - cli.run(%w(--experimental-queue-selector feature_category=chatops&urgency=high resource_boundary=memory&feature_category=importers)) + cli.run(%w(--experimental-queue-selector feature_category=chatops&has_external_dependencies=true resource_boundary=memory&feature_category=importers)) end it 'allows the special * selector' do + worker_queues = %w(foo bar baz) + + expect(Gitlab::SidekiqConfig::CliMethods) + .to receive(:worker_queues).and_return(worker_queues) + expect(Gitlab::SidekiqCluster) - .to receive(:start).with( - [Gitlab::SidekiqConfig::CliMethods.worker_queues], - default_options - ) + .to receive(:start).with([worker_queues], default_options) cli.run(%w(--experimental-queue-selector *)) end diff --git a/spec/lib/quality/test_level_spec.rb b/spec/lib/quality/test_level_spec.rb index 34163c6cfbc..6042ab24787 100644 --- a/spec/lib/quality/test_level_spec.rb +++ b/spec/lib/quality/test_level_spec.rb @@ -28,7 +28,14 @@ RSpec.describe Quality::TestLevel do context 'when level is migration' do it 'returns a pattern' do expect(subject.pattern(:migration)) - .to eq("spec/{migrations,lib/gitlab/background_migration,lib/ee/gitlab/background_migration}{,/**/}*_spec.rb") + .to eq("spec/{migrations}{,/**/}*_spec.rb") + end + end + + context 'when level is background_migration' do + it 'returns a pattern' do + expect(subject.pattern(:background_migration)) + .to eq("spec/{lib/gitlab/background_migration,lib/ee/gitlab/background_migration}{,/**/}*_spec.rb") end end @@ -89,7 +96,14 @@ RSpec.describe Quality::TestLevel do context 'when level is migration' do it 'returns a regexp' do expect(subject.regexp(:migration)) - .to eq(%r{spec/(migrations|lib/gitlab/background_migration|lib/ee/gitlab/background_migration)}) + .to eq(%r{spec/(migrations)}) + end + end + + context 'when level is background_migration' do + it 'returns a regexp' do + expect(subject.regexp(:background_migration)) + .to eq(%r{spec/(lib/gitlab/background_migration|lib/ee/gitlab/background_migration)}) end end @@ -160,4 +174,26 @@ RSpec.describe Quality::TestLevel do %r{Test level for spec/unknown/foo_spec.rb couldn't be set. Please rename the file properly or change the test level detection regexes in .+/lib/quality/test_level.rb.}) end end + + describe '#background_migration?' do + it 'returns false for a unit test' do + expect(subject.background_migration?('spec/models/abuse_report_spec.rb')).to be(false) + end + + it 'returns true for a migration test' do + expect(subject.background_migration?('spec/migrations/add_default_and_free_plans_spec.rb')).to be(false) + end + + it 'returns true for a background migration test' do + expect(subject.background_migration?('spec/lib/gitlab/background_migration/archive_legacy_traces_spec.rb')).to be(true) + end + + it 'returns true for a geo migration test' do + expect(described_class.new('ee/').background_migration?('ee/spec/migrations/geo/migrate_ci_job_artifacts_to_separate_registry_spec.rb')).to be(false) + end + + it 'returns true for a EE-namespaced background migration test' do + expect(described_class.new('ee/').background_migration?('ee/spec/lib/ee/gitlab/background_migration/prune_orphaned_geo_events_spec.rb')).to be(true) + end + end end |