Commit b3d68a1a authored by Nick Thomas's avatar Nick Thomas

Stop using Gitlab::Shell#create_repository in specs

This method is going away, and its use in specs hinders that effort.
In specs, it is used to set up scenarios where a repository conflicts
with an attempt to create one, so going through a ::Repository is
typically not an option. We can use `TestEnv#create_bare_repository`
instead, though.
parent b4e3a822
...@@ -54,16 +54,15 @@ describe ::Gitlab::BareRepositoryImport::Repository do ...@@ -54,16 +54,15 @@ describe ::Gitlab::BareRepositoryImport::Repository do
end end
context 'hashed storage' do context 'hashed storage' do
let(:gitlab_shell) { Gitlab::Shell.new }
let(:repository_storage) { 'default' }
let(:root_path) { Gitlab.config.repositories.storages[repository_storage].legacy_disk_path }
let(:hash) { '6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b' } let(:hash) { '6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b' }
let(:hashed_path) { "@hashed/6b/86/6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b" } let(:hashed_path) { "@hashed/6b/86/6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b" }
let(:root_path) { TestEnv.repos_path }
let(:repo_path) { File.join(root_path, "#{hashed_path}.git") } let(:repo_path) { File.join(root_path, "#{hashed_path}.git") }
let(:wiki_path) { File.join(root_path, "#{hashed_path}.wiki.git") } let(:wiki_path) { File.join(root_path, "#{hashed_path}.wiki.git") }
before do before do
gitlab_shell.create_repository(repository_storage, hashed_path, 'group/project') TestEnv.create_bare_repository(repo_path)
Gitlab::GitalyClient::StorageSettings.allow_disk_access do Gitlab::GitalyClient::StorageSettings.allow_disk_access do
repository = Rugged::Repository.new(repo_path) repository = Rugged::Repository.new(repo_path)
repository.config['gitlab.fullpath'] = 'to/repo' repository.config['gitlab.fullpath'] = 'to/repo'
...@@ -71,7 +70,7 @@ describe ::Gitlab::BareRepositoryImport::Repository do ...@@ -71,7 +70,7 @@ describe ::Gitlab::BareRepositoryImport::Repository do
end end
after do after do
gitlab_shell.remove_repository(repository_storage, hashed_path) FileUtils.rm_rf(repo_path)
end end
subject { described_class.new(root_path, repo_path) } subject { described_class.new(root_path, repo_path) }
......
...@@ -500,11 +500,11 @@ describe Gitlab::Git::Repository, :seed_helper do ...@@ -500,11 +500,11 @@ describe Gitlab::Git::Repository, :seed_helper do
subject { new_repository.fetch_repository_as_mirror(repository) } subject { new_repository.fetch_repository_as_mirror(repository) }
before do before do
Gitlab::Shell.new.create_repository('default', 'my_project', 'group/project') new_repository.create_repository
end end
after do after do
Gitlab::Shell.new.remove_repository('default', 'my_project') new_repository.remove
end end
it 'fetches a repository as a mirror remote' do it 'fetches a repository as a mirror remote' do
......
...@@ -6,7 +6,6 @@ describe Projects::CreateService, '#execute' do ...@@ -6,7 +6,6 @@ describe Projects::CreateService, '#execute' do
include ExternalAuthorizationServiceHelpers include ExternalAuthorizationServiceHelpers
include GitHelpers include GitHelpers
let(:gitlab_shell) { Gitlab::Shell.new }
let(:user) { create :user } let(:user) { create :user }
let(:opts) do let(:opts) do
{ {
...@@ -264,8 +263,6 @@ describe Projects::CreateService, '#execute' do ...@@ -264,8 +263,6 @@ describe Projects::CreateService, '#execute' do
end end
context 'when another repository already exists on disk' do context 'when another repository already exists on disk' do
let(:repository_storage) { 'default' }
let(:opts) do let(:opts) do
{ {
name: 'Existing', name: 'Existing',
...@@ -274,13 +271,15 @@ describe Projects::CreateService, '#execute' do ...@@ -274,13 +271,15 @@ describe Projects::CreateService, '#execute' do
end end
context 'with legacy storage' do context 'with legacy storage' do
let(:fake_repo_path) { File.join(TestEnv.repos_path, user.namespace.full_path, 'existing.git') }
before do before do
stub_application_setting(hashed_storage_enabled: false) stub_application_setting(hashed_storage_enabled: false)
gitlab_shell.create_repository(repository_storage, "#{user.namespace.full_path}/existing", 'group/project') TestEnv.create_bare_repository(fake_repo_path)
end end
after do after do
gitlab_shell.remove_repository(repository_storage, "#{user.namespace.full_path}/existing") FileUtils.rm_rf(fake_repo_path)
end end
it 'does not allow to create a project when path matches existing repository on disk' do it 'does not allow to create a project when path matches existing repository on disk' do
...@@ -305,17 +304,15 @@ describe Projects::CreateService, '#execute' do ...@@ -305,17 +304,15 @@ describe Projects::CreateService, '#execute' do
context 'with hashed storage' do context 'with hashed storage' do
let(:hash) { '6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b' } let(:hash) { '6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b' }
let(:hashed_path) { '@hashed/6b/86/6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b' } let(:hashed_path) { '@hashed/6b/86/6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b' }
let(:fake_repo_path) { File.join(TestEnv.repos_path, "#{hashed_path}.git") }
before do before do
allow(Digest::SHA2).to receive(:hexdigest) { hash } allow(Digest::SHA2).to receive(:hexdigest) { hash }
end TestEnv.create_bare_repository(fake_repo_path)
before do
gitlab_shell.create_repository(repository_storage, hashed_path, 'group/project')
end end
after do after do
gitlab_shell.remove_repository(repository_storage, hashed_path) FileUtils.rm_rf(fake_repo_path)
end end
it 'does not allow to create a project when path matches existing repository on disk' do it 'does not allow to create a project when path matches existing repository on disk' do
......
...@@ -4,7 +4,6 @@ require 'spec_helper' ...@@ -4,7 +4,6 @@ require 'spec_helper'
describe Projects::ForkService do describe Projects::ForkService do
include ProjectForksHelper include ProjectForksHelper
include Gitlab::ShellAdapter
shared_examples 'forks count cache refresh' do shared_examples 'forks count cache refresh' do
it 'flushes the forks count cache of the source project', :clean_gitlab_redis_cache do it 'flushes the forks count cache of the source project', :clean_gitlab_redis_cache do
...@@ -135,17 +134,16 @@ describe Projects::ForkService do ...@@ -135,17 +134,16 @@ describe Projects::ForkService do
end end
context 'repository in legacy storage already exists' do context 'repository in legacy storage already exists' do
let(:repository_storage) { 'default' } let(:fake_repo_path) { File.join(TestEnv.repos_path, @to_user.namespace.full_path, "#{@from_project.path}.git") }
let(:repository_storage_path) { Gitlab.config.repositories.storages[repository_storage].legacy_disk_path }
let(:params) { { namespace: @to_user.namespace } } let(:params) { { namespace: @to_user.namespace } }
before do before do
stub_application_setting(hashed_storage_enabled: false) stub_application_setting(hashed_storage_enabled: false)
gitlab_shell.create_repository(repository_storage, "#{@to_user.namespace.full_path}/#{@from_project.path}", "#{@to_user.namespace.full_path}/#{@from_project.path}") TestEnv.create_bare_repository(fake_repo_path)
end end
after do after do
gitlab_shell.remove_repository(repository_storage, "#{@to_user.namespace.full_path}/#{@from_project.path}") FileUtils.rm_rf(fake_repo_path)
end end
subject { fork_project(@from_project, @to_user, params) } subject { fork_project(@from_project, @to_user, params) }
......
...@@ -5,7 +5,6 @@ require 'spec_helper' ...@@ -5,7 +5,6 @@ require 'spec_helper'
describe Projects::TransferService do describe Projects::TransferService do
include GitHelpers include GitHelpers
let(:gitlab_shell) { Gitlab::Shell.new }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:group) { create(:group) } let(:group) { create(:group) }
let(:project) { create(:project, :repository, :legacy_storage, namespace: user.namespace) } let(:project) { create(:project, :repository, :legacy_storage, namespace: user.namespace) }
...@@ -104,7 +103,7 @@ describe Projects::TransferService do ...@@ -104,7 +103,7 @@ describe Projects::TransferService do
it 'rolls back repo location' do it 'rolls back repo location' do
attempt_project_transfer attempt_project_transfer
expect(gitlab_shell.repository_exists?(project.repository_storage, "#{project.disk_path}.git")).to be(true) expect(project.repository.raw.exists?).to be(true)
expect(original_path).to eq current_path expect(original_path).to eq current_path
end end
...@@ -172,21 +171,18 @@ describe Projects::TransferService do ...@@ -172,21 +171,18 @@ describe Projects::TransferService do
end end
context 'namespace which contains orphan repository with same projects path name' do context 'namespace which contains orphan repository with same projects path name' do
let(:repository_storage) { 'default' } let(:fake_repo_path) { File.join(TestEnv.repos_path, group.full_path, "#{project.path}.git") }
let(:repository_storage_path) { Gitlab.config.repositories.storages[repository_storage].legacy_disk_path }
before do before do
group.add_owner(user) group.add_owner(user)
unless gitlab_shell.create_repository(repository_storage, "#{group.full_path}/#{project.path}", project.full_path) TestEnv.create_bare_repository(fake_repo_path)
raise 'failed to add repository'
end
@result = transfer_project(project, user, group) @result = transfer_project(project, user, group)
end end
after do after do
gitlab_shell.remove_repository(repository_storage, "#{group.full_path}/#{project.path}") FileUtils.rm_rf(fake_repo_path)
end end
it { expect(@result).to eq false } it { expect(@result).to eq false }
......
...@@ -12,7 +12,6 @@ describe Projects::UpdateService do ...@@ -12,7 +12,6 @@ describe Projects::UpdateService do
end end
describe '#execute' do describe '#execute' do
let(:gitlab_shell) { Gitlab::Shell.new }
let(:admin) { create(:admin) } let(:admin) { create(:admin) }
context 'when changing visibility level' do context 'when changing visibility level' do
...@@ -303,18 +302,17 @@ describe Projects::UpdateService do ...@@ -303,18 +302,17 @@ describe Projects::UpdateService do
end end
context 'when renaming a project' do context 'when renaming a project' do
let(:repository_storage) { 'default' } let(:fake_repo_path) { File.join(TestEnv.repos_path, user.namespace.full_path, 'existing.git') }
let(:repository_storage_path) { Gitlab.config.repositories.storages[repository_storage].legacy_disk_path }
context 'with legacy storage' do context 'with legacy storage' do
let(:project) { create(:project, :legacy_storage, :repository, creator: user, namespace: user.namespace) } let(:project) { create(:project, :legacy_storage, :repository, creator: user, namespace: user.namespace) }
before do before do
gitlab_shell.create_repository(repository_storage, "#{user.namespace.full_path}/existing", user.namespace.full_path) TestEnv.create_bare_repository(fake_repo_path)
end end
after do after do
gitlab_shell.remove_repository(repository_storage, "#{user.namespace.full_path}/existing") FileUtils.rm_rf(fake_repo_path)
end end
it 'does not allow renaming when new path matches existing repository on disk' do it 'does not allow renaming when new path matches existing repository on disk' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment