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
end
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(:hashed_path) { "@hashed/6b/86/6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b" }
let(:root_path) { TestEnv.repos_path }
let(:repo_path) { File.join(root_path, "#{hashed_path}.git") }
let(:wiki_path) { File.join(root_path, "#{hashed_path}.wiki.git") }
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
repository = Rugged::Repository.new(repo_path)
repository.config['gitlab.fullpath'] = 'to/repo'
......@@ -71,7 +70,7 @@ describe ::Gitlab::BareRepositoryImport::Repository do
end
after do
gitlab_shell.remove_repository(repository_storage, hashed_path)
FileUtils.rm_rf(repo_path)
end
subject { described_class.new(root_path, repo_path) }
......
......@@ -500,11 +500,11 @@ describe Gitlab::Git::Repository, :seed_helper do
subject { new_repository.fetch_repository_as_mirror(repository) }
before do
Gitlab::Shell.new.create_repository('default', 'my_project', 'group/project')
new_repository.create_repository
end
after do
Gitlab::Shell.new.remove_repository('default', 'my_project')
new_repository.remove
end
it 'fetches a repository as a mirror remote' do
......
......@@ -6,7 +6,6 @@ describe Projects::CreateService, '#execute' do
include ExternalAuthorizationServiceHelpers
include GitHelpers
let(:gitlab_shell) { Gitlab::Shell.new }
let(:user) { create :user }
let(:opts) do
{
......@@ -264,8 +263,6 @@ describe Projects::CreateService, '#execute' do
end
context 'when another repository already exists on disk' do
let(:repository_storage) { 'default' }
let(:opts) do
{
name: 'Existing',
......@@ -274,13 +271,15 @@ describe Projects::CreateService, '#execute' do
end
context 'with legacy storage' do
let(:fake_repo_path) { File.join(TestEnv.repos_path, user.namespace.full_path, 'existing.git') }
before do
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
after do
gitlab_shell.remove_repository(repository_storage, "#{user.namespace.full_path}/existing")
FileUtils.rm_rf(fake_repo_path)
end
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
context 'with hashed storage' do
let(:hash) { '6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b' }
let(:hashed_path) { '@hashed/6b/86/6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b' }
let(:fake_repo_path) { File.join(TestEnv.repos_path, "#{hashed_path}.git") }
before do
allow(Digest::SHA2).to receive(:hexdigest) { hash }
end
before do
gitlab_shell.create_repository(repository_storage, hashed_path, 'group/project')
TestEnv.create_bare_repository(fake_repo_path)
end
after do
gitlab_shell.remove_repository(repository_storage, hashed_path)
FileUtils.rm_rf(fake_repo_path)
end
it 'does not allow to create a project when path matches existing repository on disk' do
......
......@@ -4,7 +4,6 @@ require 'spec_helper'
describe Projects::ForkService do
include ProjectForksHelper
include Gitlab::ShellAdapter
shared_examples 'forks count cache refresh' do
it 'flushes the forks count cache of the source project', :clean_gitlab_redis_cache do
......@@ -135,17 +134,16 @@ describe Projects::ForkService do
end
context 'repository in legacy storage already exists' do
let(:repository_storage) { 'default' }
let(:repository_storage_path) { Gitlab.config.repositories.storages[repository_storage].legacy_disk_path }
let(:fake_repo_path) { File.join(TestEnv.repos_path, @to_user.namespace.full_path, "#{@from_project.path}.git") }
let(:params) { { namespace: @to_user.namespace } }
before do
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
after do
gitlab_shell.remove_repository(repository_storage, "#{@to_user.namespace.full_path}/#{@from_project.path}")
FileUtils.rm_rf(fake_repo_path)
end
subject { fork_project(@from_project, @to_user, params) }
......
......@@ -5,7 +5,6 @@ require 'spec_helper'
describe Projects::TransferService do
include GitHelpers
let(:gitlab_shell) { Gitlab::Shell.new }
let(:user) { create(:user) }
let(:group) { create(:group) }
let(:project) { create(:project, :repository, :legacy_storage, namespace: user.namespace) }
......@@ -104,7 +103,7 @@ describe Projects::TransferService do
it 'rolls back repo location' do
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
end
......@@ -172,21 +171,18 @@ describe Projects::TransferService do
end
context 'namespace which contains orphan repository with same projects path name' do
let(:repository_storage) { 'default' }
let(:repository_storage_path) { Gitlab.config.repositories.storages[repository_storage].legacy_disk_path }
let(:fake_repo_path) { File.join(TestEnv.repos_path, group.full_path, "#{project.path}.git") }
before do
group.add_owner(user)
unless gitlab_shell.create_repository(repository_storage, "#{group.full_path}/#{project.path}", project.full_path)
raise 'failed to add repository'
end
TestEnv.create_bare_repository(fake_repo_path)
@result = transfer_project(project, user, group)
end
after do
gitlab_shell.remove_repository(repository_storage, "#{group.full_path}/#{project.path}")
FileUtils.rm_rf(fake_repo_path)
end
it { expect(@result).to eq false }
......
......@@ -12,7 +12,6 @@ describe Projects::UpdateService do
end
describe '#execute' do
let(:gitlab_shell) { Gitlab::Shell.new }
let(:admin) { create(:admin) }
context 'when changing visibility level' do
......@@ -303,18 +302,17 @@ describe Projects::UpdateService do
end
context 'when renaming a project' do
let(:repository_storage) { 'default' }
let(:repository_storage_path) { Gitlab.config.repositories.storages[repository_storage].legacy_disk_path }
let(:fake_repo_path) { File.join(TestEnv.repos_path, user.namespace.full_path, 'existing.git') }
context 'with legacy storage' do
let(:project) { create(:project, :legacy_storage, :repository, creator: user, namespace: user.namespace) }
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
after do
gitlab_shell.remove_repository(repository_storage, "#{user.namespace.full_path}/existing")
FileUtils.rm_rf(fake_repo_path)
end
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