2019-11-13 03:06:31 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-11 19:45:54 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 18:09:03 +00:00
|
|
|
RSpec.describe Gitlab::GitalyClient::RepositoryService do
|
2018-10-26 22:30:24 +00:00
|
|
|
using RSpec::Parameterized::TableSyntax
|
|
|
|
|
2017-08-11 19:45:54 +00:00
|
|
|
let(:project) { create(:project) }
|
|
|
|
let(:storage_name) { project.repository_storage }
|
|
|
|
let(:relative_path) { project.disk_path + '.git' }
|
|
|
|
let(:client) { described_class.new(project.repository) }
|
|
|
|
|
|
|
|
describe '#exists?' do
|
|
|
|
it 'sends a repository_exists message' do
|
|
|
|
expect_any_instance_of(Gitaly::RepositoryService::Stub)
|
|
|
|
.to receive(:repository_exists)
|
|
|
|
.with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash))
|
|
|
|
.and_return(double(exists: true))
|
|
|
|
|
|
|
|
client.exists?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#garbage_collect' do
|
|
|
|
it 'sends a garbage_collect message' do
|
|
|
|
expect_any_instance_of(Gitaly::RepositoryService::Stub)
|
|
|
|
.to receive(:garbage_collect)
|
|
|
|
.with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash))
|
|
|
|
.and_return(double(:garbage_collect_response))
|
|
|
|
|
2020-11-09 03:09:03 +00:00
|
|
|
client.garbage_collect(true, prune: true)
|
2017-08-11 19:45:54 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#repack_full' do
|
|
|
|
it 'sends a repack_full message' do
|
|
|
|
expect_any_instance_of(Gitaly::RepositoryService::Stub)
|
|
|
|
.to receive(:repack_full)
|
|
|
|
.with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash))
|
|
|
|
.and_return(double(:repack_full_response))
|
|
|
|
|
|
|
|
client.repack_full(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#repack_incremental' do
|
|
|
|
it 'sends a repack_incremental message' do
|
|
|
|
expect_any_instance_of(Gitaly::RepositoryService::Stub)
|
|
|
|
.to receive(:repack_incremental)
|
|
|
|
.with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash))
|
|
|
|
.and_return(double(:repack_incremental_response))
|
|
|
|
|
|
|
|
client.repack_incremental
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-03-08 18:16:39 +00:00
|
|
|
describe '#optimize_repository' do
|
|
|
|
it 'sends a optimize_repository message' do
|
|
|
|
expect_any_instance_of(Gitaly::RepositoryService::Stub)
|
|
|
|
.to receive(:optimize_repository)
|
|
|
|
.with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash))
|
|
|
|
.and_return(double(:optimize_repository))
|
|
|
|
|
|
|
|
client.optimize_repository
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#prune_unreachable_objects' do
|
|
|
|
it 'sends a prune_unreachable_objects message' do
|
|
|
|
expect_any_instance_of(Gitaly::RepositoryService::Stub)
|
|
|
|
.to receive(:prune_unreachable_objects)
|
|
|
|
.with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash))
|
|
|
|
.and_return(double(:prune_unreachable_objects))
|
|
|
|
|
|
|
|
client.prune_unreachable_objects
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-11 19:45:54 +00:00
|
|
|
describe '#repository_size' do
|
|
|
|
it 'sends a repository_size message' do
|
|
|
|
expect_any_instance_of(Gitaly::RepositoryService::Stub)
|
|
|
|
.to receive(:repository_size)
|
|
|
|
.with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash))
|
|
|
|
.and_return(size: 0)
|
|
|
|
|
|
|
|
client.repository_size
|
|
|
|
end
|
|
|
|
end
|
2017-08-11 22:44:25 +00:00
|
|
|
|
2019-05-27 04:38:20 +00:00
|
|
|
describe '#get_object_directory_size' do
|
|
|
|
it 'sends a get_object_directory_size message' do
|
|
|
|
expect_any_instance_of(Gitaly::RepositoryService::Stub)
|
|
|
|
.to receive(:get_object_directory_size)
|
|
|
|
.with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash))
|
|
|
|
.and_return(size: 0)
|
|
|
|
|
|
|
|
client.get_object_directory_size
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-11 22:44:25 +00:00
|
|
|
describe '#apply_gitattributes' do
|
|
|
|
let(:revision) { 'master' }
|
|
|
|
|
|
|
|
it 'sends an apply_gitattributes message' do
|
|
|
|
expect_any_instance_of(Gitaly::RepositoryService::Stub)
|
|
|
|
.to receive(:apply_gitattributes)
|
|
|
|
.with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash))
|
|
|
|
.and_return(double(:apply_gitattributes_response))
|
|
|
|
|
|
|
|
client.apply_gitattributes(revision)
|
|
|
|
end
|
|
|
|
end
|
2017-10-08 23:44:18 +00:00
|
|
|
|
2018-03-27 12:31:15 +00:00
|
|
|
describe '#info_attributes' do
|
|
|
|
it 'reads the info attributes' do
|
|
|
|
expect_any_instance_of(Gitaly::RepositoryService::Stub)
|
|
|
|
.to receive(:get_info_attributes)
|
|
|
|
.with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash))
|
|
|
|
.and_return([])
|
|
|
|
|
|
|
|
client.info_attributes
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-10-08 23:44:18 +00:00
|
|
|
describe '#has_local_branches?' do
|
|
|
|
it 'sends a has_local_branches message' do
|
|
|
|
expect_any_instance_of(Gitaly::RepositoryService::Stub)
|
|
|
|
.to receive(:has_local_branches)
|
|
|
|
.with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash))
|
|
|
|
.and_return(double(value: true))
|
|
|
|
|
|
|
|
expect(client.has_local_branches?).to be(true)
|
|
|
|
end
|
|
|
|
end
|
2018-02-07 21:26:35 +00:00
|
|
|
|
2018-03-02 13:50:17 +00:00
|
|
|
describe '#fetch_remote' do
|
2021-07-29 12:08:55 +00:00
|
|
|
let(:url) { 'https://example.com/git/repo.git' }
|
|
|
|
|
|
|
|
it 'sends a fetch_remote_request message' do
|
|
|
|
expected_request = gitaly_request_with_params(
|
|
|
|
remote_params: Gitaly::Remote.new(
|
|
|
|
url: url,
|
|
|
|
http_authorization_header: "",
|
|
|
|
mirror_refmaps: []
|
|
|
|
),
|
|
|
|
ssh_key: '',
|
|
|
|
known_hosts: '',
|
|
|
|
force: false,
|
|
|
|
no_tags: false,
|
|
|
|
no_prune: false,
|
|
|
|
check_tags_changed: false
|
|
|
|
)
|
2018-10-26 22:30:24 +00:00
|
|
|
|
2021-07-29 12:08:55 +00:00
|
|
|
expect_any_instance_of(Gitaly::RepositoryService::Stub)
|
|
|
|
.to receive(:fetch_remote)
|
|
|
|
.with(expected_request, kind_of(Hash))
|
|
|
|
.and_return(double(value: true))
|
2018-03-02 13:50:17 +00:00
|
|
|
|
2021-07-29 12:08:55 +00:00
|
|
|
client.fetch_remote(url, refmap: nil, ssh_auth: nil, forced: false, no_tags: false, timeout: 1, check_tags_changed: false)
|
2018-10-26 22:30:24 +00:00
|
|
|
end
|
|
|
|
|
2021-07-29 12:08:55 +00:00
|
|
|
context 'SSH auth' do
|
|
|
|
where(:ssh_mirror_url, :ssh_key_auth, :ssh_private_key, :ssh_known_hosts, :expected_params) do
|
|
|
|
false | false | 'key' | 'known_hosts' | {}
|
|
|
|
false | true | 'key' | 'known_hosts' | {}
|
|
|
|
true | false | 'key' | 'known_hosts' | { known_hosts: 'known_hosts' }
|
|
|
|
true | true | 'key' | 'known_hosts' | { ssh_key: 'key', known_hosts: 'known_hosts' }
|
|
|
|
true | true | 'key' | nil | { ssh_key: 'key' }
|
|
|
|
true | true | nil | 'known_hosts' | { known_hosts: 'known_hosts' }
|
|
|
|
true | true | nil | nil | {}
|
|
|
|
true | true | '' | '' | {}
|
2018-10-26 22:30:24 +00:00
|
|
|
end
|
|
|
|
|
2021-07-29 12:08:55 +00:00
|
|
|
with_them do
|
|
|
|
let(:ssh_auth) do
|
|
|
|
double(
|
|
|
|
:ssh_auth,
|
|
|
|
ssh_mirror_url?: ssh_mirror_url,
|
|
|
|
ssh_key_auth?: ssh_key_auth,
|
|
|
|
ssh_private_key: ssh_private_key,
|
|
|
|
ssh_known_hosts: ssh_known_hosts
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it do
|
|
|
|
expected_request = gitaly_request_with_params({
|
|
|
|
remote_params: Gitaly::Remote.new(
|
|
|
|
url: url,
|
|
|
|
http_authorization_header: "",
|
|
|
|
mirror_refmaps: []
|
|
|
|
),
|
|
|
|
ssh_key: '',
|
|
|
|
known_hosts: '',
|
|
|
|
force: false,
|
|
|
|
no_tags: false,
|
|
|
|
no_prune: false
|
|
|
|
}.update(expected_params))
|
|
|
|
|
|
|
|
expect_any_instance_of(Gitaly::RepositoryService::Stub)
|
|
|
|
.to receive(:fetch_remote)
|
|
|
|
.with(expected_request, kind_of(Hash))
|
|
|
|
.and_return(double(value: true))
|
|
|
|
|
|
|
|
client.fetch_remote(url, refmap: nil, ssh_auth: ssh_auth, forced: false, no_tags: false, timeout: 1)
|
|
|
|
end
|
2018-10-26 22:30:24 +00:00
|
|
|
end
|
2018-03-02 13:50:17 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-04-05 18:27:09 +00:00
|
|
|
describe '#calculate_checksum' do
|
|
|
|
it 'sends a calculate_checksum message' do
|
|
|
|
expect_any_instance_of(Gitaly::RepositoryService::Stub)
|
|
|
|
.to receive(:calculate_checksum)
|
|
|
|
.with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash))
|
|
|
|
.and_return(double(checksum: 0))
|
|
|
|
|
|
|
|
client.calculate_checksum
|
|
|
|
end
|
|
|
|
end
|
2018-04-03 17:57:55 +00:00
|
|
|
|
2022-03-11 15:07:48 +00:00
|
|
|
describe '#create_repository' do
|
|
|
|
it 'sends a create_repository message without arguments' do
|
|
|
|
expect_any_instance_of(Gitaly::RepositoryService::Stub)
|
|
|
|
.to receive(:create_repository)
|
|
|
|
.with(gitaly_request_with_path(storage_name, relative_path).and(gitaly_request_with_params(default_branch: '')), kind_of(Hash))
|
|
|
|
.and_return(double)
|
|
|
|
|
|
|
|
client.create_repository
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sends a create_repository message with default branch' do
|
|
|
|
expect_any_instance_of(Gitaly::RepositoryService::Stub)
|
|
|
|
.to receive(:create_repository)
|
|
|
|
.with(gitaly_request_with_path(storage_name, relative_path).and(gitaly_request_with_params(default_branch: 'default-branch-name')), kind_of(Hash))
|
|
|
|
.and_return(double)
|
|
|
|
|
|
|
|
client.create_repository('default-branch-name')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-04-03 17:57:55 +00:00
|
|
|
describe '#create_from_snapshot' do
|
|
|
|
it 'sends a create_repository_from_snapshot message' do
|
|
|
|
expect_any_instance_of(Gitaly::RepositoryService::Stub)
|
|
|
|
.to receive(:create_repository_from_snapshot)
|
|
|
|
.with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash))
|
|
|
|
.and_return(double)
|
|
|
|
|
|
|
|
client.create_from_snapshot('http://example.com?wiki=1', 'Custom xyz')
|
|
|
|
end
|
|
|
|
end
|
2018-05-02 08:12:15 +00:00
|
|
|
|
|
|
|
describe '#raw_changes_between' do
|
|
|
|
it 'sends a create_repository_from_snapshot message' do
|
|
|
|
expect_any_instance_of(Gitaly::RepositoryService::Stub)
|
|
|
|
.to receive(:get_raw_changes)
|
|
|
|
.with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash))
|
|
|
|
.and_return(double)
|
|
|
|
|
|
|
|
client.raw_changes_between('deadbeef', 'deadpork')
|
|
|
|
end
|
|
|
|
end
|
2019-05-01 04:45:19 +00:00
|
|
|
|
2021-03-17 15:09:03 +00:00
|
|
|
describe '#search_files_by_regexp' do
|
|
|
|
subject(:result) { client.search_files_by_regexp('master', '.*') }
|
|
|
|
|
|
|
|
before do
|
|
|
|
expect_any_instance_of(Gitaly::RepositoryService::Stub)
|
|
|
|
.to receive(:search_files_by_name)
|
|
|
|
.with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash))
|
|
|
|
.and_return([double(files: ['file1.txt']), double(files: ['file2.txt'])])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sends a search_files_by_name message and returns a flatten array' do
|
|
|
|
expect(result).to contain_exactly('file1.txt', 'file2.txt')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-05-01 04:45:19 +00:00
|
|
|
describe '#disconnect_alternates' do
|
2022-08-04 00:08:55 +00:00
|
|
|
it 'sends a disconnect_git_alternates message' do
|
|
|
|
expect_any_instance_of(Gitaly::ObjectPoolService::Stub)
|
|
|
|
.to receive(:disconnect_git_alternates)
|
|
|
|
.with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash))
|
2019-05-01 04:45:19 +00:00
|
|
|
|
2022-08-04 00:08:55 +00:00
|
|
|
client.disconnect_alternates
|
2019-05-01 04:45:19 +00:00
|
|
|
end
|
|
|
|
end
|
2019-10-02 15:06:12 +00:00
|
|
|
|
2020-03-13 00:09:34 +00:00
|
|
|
describe '#rename' do
|
|
|
|
it 'sends a rename_repository message' do
|
|
|
|
expect_any_instance_of(Gitaly::RepositoryService::Stub)
|
|
|
|
.to receive(:rename_repository)
|
|
|
|
.with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash))
|
|
|
|
.and_return(double(value: true))
|
|
|
|
|
|
|
|
client.rename('some/new/path')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#remove' do
|
2019-10-02 15:06:12 +00:00
|
|
|
it 'sends a remove_repository message' do
|
|
|
|
expect_any_instance_of(Gitaly::RepositoryService::Stub)
|
|
|
|
.to receive(:remove_repository)
|
|
|
|
.with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash))
|
|
|
|
.and_return(double(value: true))
|
|
|
|
|
|
|
|
client.remove
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-13 00:09:34 +00:00
|
|
|
describe '#replicate' do
|
2022-10-03 21:09:57 +00:00
|
|
|
let(:source_repository) { Gitlab::Git::Repository.new('default', 'repo/path', '', 'group/project') }
|
2020-03-13 00:09:34 +00:00
|
|
|
|
|
|
|
it 'sends a replicate_repository message' do
|
2019-10-02 15:06:12 +00:00
|
|
|
expect_any_instance_of(Gitaly::RepositoryService::Stub)
|
2020-03-13 00:09:34 +00:00
|
|
|
.to receive(:replicate_repository)
|
2019-10-02 15:06:12 +00:00
|
|
|
.with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash))
|
|
|
|
|
2020-03-13 00:09:34 +00:00
|
|
|
client.replicate(source_repository)
|
2019-10-02 15:06:12 +00:00
|
|
|
end
|
|
|
|
end
|
2021-07-29 06:10:15 +00:00
|
|
|
|
|
|
|
describe '#set_full_path' do
|
|
|
|
let(:path) { 'repo/path' }
|
|
|
|
|
|
|
|
it 'sends a set_full_path message' do
|
|
|
|
expect_any_instance_of(Gitaly::RepositoryService::Stub)
|
|
|
|
.to receive(:set_full_path)
|
|
|
|
.with(gitaly_request_with_params(path: path), kind_of(Hash))
|
|
|
|
.and_return(double)
|
|
|
|
|
|
|
|
client.set_full_path(path)
|
|
|
|
end
|
|
|
|
end
|
2022-08-01 12:12:10 +00:00
|
|
|
|
|
|
|
describe '#full_path' do
|
|
|
|
let(:path) { 'repo/path' }
|
|
|
|
|
|
|
|
it 'sends a full_path message' do
|
|
|
|
expect_any_instance_of(Gitaly::RepositoryService::Stub)
|
|
|
|
.to receive(:full_path)
|
|
|
|
.and_return(double(path: path))
|
|
|
|
|
|
|
|
expect(client.full_path).to eq(path)
|
|
|
|
end
|
|
|
|
end
|
2022-10-06 15:09:39 +00:00
|
|
|
|
|
|
|
describe "#find_license" do
|
|
|
|
it 'sends a find_license request with medium timeout' do
|
|
|
|
expect_any_instance_of(Gitaly::RepositoryService::Stub)
|
|
|
|
.to receive(:find_license) do |_service, _request, headers|
|
|
|
|
expect(headers[:deadline]).to be_between(
|
|
|
|
Gitlab::GitalyClient.fast_timeout.seconds.from_now.to_f,
|
|
|
|
Gitlab::GitalyClient.medium_timeout.seconds.from_now.to_f
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
client.find_license
|
|
|
|
end
|
|
|
|
end
|
2017-08-11 19:45:54 +00:00
|
|
|
end
|