diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2018-11-28 13:14:04 +0100 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2018-11-28 13:14:04 +0100 |
commit | 0b8a2779e788bd05180176a11ac585fd7999b76b (patch) | |
tree | 9426c5fe4eb41513af5066889891c10187da6f9b /spec/migrations | |
parent | 4c7665f2f930bba855646143684070544044de10 (diff) | |
parent | 0f800a5c0532508c84cee24bf44a4b9ce68168a2 (diff) | |
download | gitlab-ce-0b8a2779e788bd05180176a11ac585fd7999b76b.tar.gz |
Merge branch 'master' into fix/gb/encrypt-runners-tokens
* master: (243 commits)
Conflicts:
db/schema.rb
lib/gitlab/import_export/import_export.yml
Diffstat (limited to 'spec/migrations')
-rw-r--r-- | spec/migrations/backfill_store_project_full_path_in_repo_spec.rb | 98 | ||||
-rw-r--r-- | spec/migrations/migrate_issues_to_ghost_user_spec.rb | 12 |
2 files changed, 104 insertions, 6 deletions
diff --git a/spec/migrations/backfill_store_project_full_path_in_repo_spec.rb b/spec/migrations/backfill_store_project_full_path_in_repo_spec.rb new file mode 100644 index 00000000000..34f4a36d63d --- /dev/null +++ b/spec/migrations/backfill_store_project_full_path_in_repo_spec.rb @@ -0,0 +1,98 @@ +# frozen_string_literal: true + +require 'spec_helper' + +require Rails.root.join('db', 'post_migrate', '20181010133639_backfill_store_project_full_path_in_repo.rb') + +describe BackfillStoreProjectFullPathInRepo, :migration do + let(:namespaces) { table(:namespaces) } + let(:projects) { table(:projects) } + let(:group) { namespaces.create!(name: 'foo', path: 'foo') } + let(:subgroup) { namespaces.create!(name: 'bar', path: 'bar', parent_id: group.id) } + + subject(:migration) { described_class.new } + + around do |example| + Sidekiq::Testing.inline! do + example.run + end + end + + describe '#up' do + shared_examples_for 'writes the full path to git config' do + it 'writes the git config' do + expect_next_instance_of(Gitlab::GitalyClient::RepositoryService) do |repository_service| + allow(repository_service).to receive(:cleanup) + expect(repository_service).to receive(:set_config).with('gitlab.fullpath' => expected_path) + end + + migration.up + end + + it 'retries in case of failure' do + repository_service = spy(:repository_service) + + allow(Gitlab::GitalyClient::RepositoryService).to receive(:new).and_return(repository_service) + + allow(repository_service).to receive(:set_config).and_raise(GRPC::BadStatus, 'Retry me') + expect(repository_service).to receive(:set_config).exactly(3).times + + migration.up + end + + it 'cleans up repository before writing the config' do + expect_next_instance_of(Gitlab::GitalyClient::RepositoryService) do |repository_service| + expect(repository_service).to receive(:cleanup).ordered + expect(repository_service).to receive(:set_config).ordered + end + + migration.up + end + + context 'legacy storage' do + it 'finds the repository at the correct location' do + Project.find(project.id).create_repository + + expect { migration.up }.not_to raise_error + end + end + + context 'hashed storage' do + it 'finds the repository at the correct location' do + project.update_attribute(:storage_version, 1) + + Project.find(project.id).create_repository + + expect { migration.up }.not_to raise_error + end + end + end + + context 'project in group' do + let!(:project) { projects.create!(namespace_id: group.id, name: 'baz', path: 'baz') } + let(:expected_path) { 'foo/baz' } + + it_behaves_like 'writes the full path to git config' + end + + context 'project in subgroup' do + let!(:project) { projects.create!(namespace_id: subgroup.id, name: 'baz', path: 'baz') } + let(:expected_path) { 'foo/bar/baz' } + + it_behaves_like 'writes the full path to git config' + end + end + + describe '#down' do + context 'project in group' do + let!(:project) { projects.create!(namespace_id: group.id, name: 'baz', path: 'baz') } + + it 'deletes the gitlab full config value' do + expect_any_instance_of(Gitlab::GitalyClient::RepositoryService) + .to receive(:delete_config).with(['gitlab.fullpath']) + + migration.down + end + end + end +end diff --git a/spec/migrations/migrate_issues_to_ghost_user_spec.rb b/spec/migrations/migrate_issues_to_ghost_user_spec.rb index 9220b49a736..0016f058a17 100644 --- a/spec/migrations/migrate_issues_to_ghost_user_spec.rb +++ b/spec/migrations/migrate_issues_to_ghost_user_spec.rb @@ -18,33 +18,33 @@ describe MigrateIssuesToGhostUser, :migration do let!(:ghost) { users.create(ghost: true, email: 'ghost@example.com') } it 'does not create a new user' do - expect { schema_migrate_up! }.not_to change { User.count } + expect { migrate! }.not_to change { User.count } end it 'migrates issues where author = nil to the ghost user' do - schema_migrate_up! + migrate! expect(issues.first.reload.author_id).to eq(ghost.id) end it 'does not change issues authored by an existing user' do - expect { schema_migrate_up! }.not_to change { issues.second.reload.author_id} + expect { migrate! }.not_to change { issues.second.reload.author_id} end end context 'when ghost user does not exist' do it 'creates a new user' do - expect { schema_migrate_up! }.to change { User.count }.by(1) + expect { migrate! }.to change { User.count }.by(1) end it 'migrates issues where author = nil to the ghost user' do - schema_migrate_up! + migrate! expect(issues.first.reload.author_id).to eq(User.ghost.id) end it 'does not change issues authored by an existing user' do - expect { schema_migrate_up! }.not_to change { issues.second.reload.author_id} + expect { migrate! }.not_to change { issues.second.reload.author_id} end end end |