2019-11-12 22:06:31 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-02-15 21:08:30 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe Gitlab::GitalyClient::RefService do
|
2017-08-14 07:12:32 -04:00
|
|
|
let(:project) { create(:project, :repository) }
|
2017-06-12 17:37:43 -04:00
|
|
|
let(:storage_name) { project.repository_storage }
|
2017-07-21 00:13:26 -04:00
|
|
|
let(:relative_path) { project.disk_path + '.git' }
|
2017-08-14 07:12:32 -04:00
|
|
|
let(:repository) { project.repository }
|
|
|
|
let(:client) { described_class.new(repository) }
|
2017-02-15 21:08:30 -05:00
|
|
|
|
2017-07-22 18:13:47 -04:00
|
|
|
describe '#branches' do
|
|
|
|
it 'sends a find_all_branches message' do
|
|
|
|
expect_any_instance_of(Gitaly::RefService::Stub)
|
|
|
|
.to receive(:find_all_branches)
|
|
|
|
.with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash))
|
|
|
|
.and_return([])
|
|
|
|
|
|
|
|
client.branches
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-07-17 22:08:23 -04:00
|
|
|
describe '#remote_branches' do
|
|
|
|
let(:remote_name) { 'my_remote' }
|
2019-12-12 07:07:33 -05:00
|
|
|
|
2018-07-17 22:08:23 -04:00
|
|
|
subject { client.remote_branches(remote_name) }
|
|
|
|
|
|
|
|
it 'sends a find_all_remote_branches message' do
|
|
|
|
expect_any_instance_of(Gitaly::RefService::Stub)
|
|
|
|
.to receive(:find_all_remote_branches)
|
|
|
|
.with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash))
|
|
|
|
.and_return([])
|
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
2020-06-22 11:09:27 -04:00
|
|
|
it 'concatenates and returns the response branches as Gitlab::Git::Branch objects' do
|
2018-07-17 22:08:23 -04:00
|
|
|
target_commits = create_list(:gitaly_commit, 4)
|
|
|
|
response_branches = target_commits.each_with_index.map do |gitaly_commit, i|
|
|
|
|
Gitaly::Branch.new(name: "#{remote_name}/#{i}", target_commit: gitaly_commit)
|
|
|
|
end
|
|
|
|
response = [
|
|
|
|
Gitaly::FindAllRemoteBranchesResponse.new(branches: response_branches[0, 2]),
|
|
|
|
Gitaly::FindAllRemoteBranchesResponse.new(branches: response_branches[2, 2])
|
|
|
|
]
|
|
|
|
|
|
|
|
expect_any_instance_of(Gitaly::RefService::Stub)
|
|
|
|
.to receive(:find_all_remote_branches).and_return(response)
|
|
|
|
|
|
|
|
expect(subject.length).to be(response_branches.length)
|
|
|
|
|
|
|
|
response_branches.each_with_index do |gitaly_branch, i|
|
|
|
|
branch = subject[i]
|
|
|
|
commit = Gitlab::Git::Commit.new(repository, gitaly_branch.target_commit)
|
|
|
|
|
|
|
|
expect(branch.name).to eq(i.to_s) # It removes the `remote/` prefix
|
|
|
|
expect(branch.dereferenced_target).to eq(commit)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-06-22 11:09:27 -04:00
|
|
|
describe '#merged_branches' do
|
|
|
|
it 'sends a find_all_branches message' do
|
|
|
|
expect_any_instance_of(Gitaly::RefService::Stub)
|
|
|
|
.to receive(:find_all_branches)
|
|
|
|
.with(gitaly_request_with_params(merged_only: true, merged_branches: ['test']), kind_of(Hash))
|
|
|
|
.and_return([])
|
|
|
|
|
|
|
|
client.merged_branches(%w(test))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-02-15 21:08:30 -05:00
|
|
|
describe '#branch_names' do
|
|
|
|
it 'sends a find_all_branch_names message' do
|
2017-07-18 03:59:36 -04:00
|
|
|
expect_any_instance_of(Gitaly::RefService::Stub)
|
2017-06-21 09:48:12 -04:00
|
|
|
.to receive(:find_all_branch_names)
|
|
|
|
.with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash))
|
|
|
|
.and_return([])
|
2017-02-15 21:08:30 -05:00
|
|
|
|
|
|
|
client.branch_names
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#tag_names' do
|
|
|
|
it 'sends a find_all_tag_names message' do
|
2017-07-18 03:59:36 -04:00
|
|
|
expect_any_instance_of(Gitaly::RefService::Stub)
|
2017-06-21 09:48:12 -04:00
|
|
|
.to receive(:find_all_tag_names)
|
|
|
|
.with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash))
|
|
|
|
.and_return([])
|
2017-02-15 21:08:30 -05:00
|
|
|
|
|
|
|
client.tag_names
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#default_branch_name' do
|
|
|
|
it 'sends a find_default_branch_name message' do
|
2017-07-18 03:59:36 -04:00
|
|
|
expect_any_instance_of(Gitaly::RefService::Stub)
|
2017-06-21 09:48:12 -04:00
|
|
|
.to receive(:find_default_branch_name)
|
|
|
|
.with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash))
|
|
|
|
.and_return(double(name: 'foo'))
|
2017-02-15 21:08:30 -05:00
|
|
|
|
|
|
|
client.default_branch_name
|
|
|
|
end
|
|
|
|
end
|
2017-03-17 15:36:46 -04:00
|
|
|
|
2019-03-26 12:17:57 -04:00
|
|
|
describe '#list_new_blobs' do
|
|
|
|
it 'raises DeadlineExceeded when timeout is too small' do
|
|
|
|
newrev = '54fcc214b94e78d7a41a9a8fe6d87a5e59500e51'
|
|
|
|
|
|
|
|
expect do
|
|
|
|
client.list_new_blobs(newrev, dynamic_timeout: 0.001)
|
|
|
|
end.to raise_error(GRPC::DeadlineExceeded)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-17 15:36:46 -04:00
|
|
|
describe '#local_branches' do
|
|
|
|
it 'sends a find_local_branches message' do
|
2017-07-18 03:59:36 -04:00
|
|
|
expect_any_instance_of(Gitaly::RefService::Stub)
|
2017-06-21 09:48:12 -04:00
|
|
|
.to receive(:find_local_branches)
|
|
|
|
.with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash))
|
|
|
|
.and_return([])
|
2017-03-17 15:36:46 -04:00
|
|
|
|
|
|
|
client.local_branches
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'parses and sends the sort parameter' do
|
2017-07-18 03:59:36 -04:00
|
|
|
expect_any_instance_of(Gitaly::RefService::Stub)
|
2017-06-21 09:48:12 -04:00
|
|
|
.to receive(:find_local_branches)
|
|
|
|
.with(gitaly_request_with_params(sort_by: :UPDATED_DESC), kind_of(Hash))
|
|
|
|
.and_return([])
|
2017-03-17 15:36:46 -04:00
|
|
|
|
|
|
|
client.local_branches(sort_by: 'updated_desc')
|
|
|
|
end
|
|
|
|
|
2017-06-28 15:38:00 -04:00
|
|
|
it 'translates known mismatches on sort param values' do
|
2017-07-18 03:59:36 -04:00
|
|
|
expect_any_instance_of(Gitaly::RefService::Stub)
|
2017-06-28 15:38:00 -04:00
|
|
|
.to receive(:find_local_branches)
|
|
|
|
.with(gitaly_request_with_params(sort_by: :NAME), kind_of(Hash))
|
|
|
|
.and_return([])
|
|
|
|
|
|
|
|
client.local_branches(sort_by: 'name_asc')
|
|
|
|
end
|
|
|
|
|
2017-03-17 15:36:46 -04:00
|
|
|
it 'raises an argument error if an invalid sort_by parameter is passed' do
|
|
|
|
expect { client.local_branches(sort_by: 'invalid_sort') }.to raise_error(ArgumentError)
|
|
|
|
end
|
|
|
|
end
|
2017-06-29 08:11:42 -04:00
|
|
|
|
2020-06-22 11:09:27 -04:00
|
|
|
describe '#tags' do
|
|
|
|
it 'sends a find_all_tags message' do
|
|
|
|
expect_any_instance_of(Gitaly::RefService::Stub)
|
|
|
|
.to receive(:find_all_tags)
|
|
|
|
.and_return([])
|
|
|
|
|
|
|
|
client.tags
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#branch_names_contains_sha' do
|
|
|
|
it 'sends a list_branch_names_containing_commit message' do
|
|
|
|
expect_any_instance_of(Gitaly::RefService::Stub)
|
|
|
|
.to receive(:list_branch_names_containing_commit)
|
|
|
|
.with(gitaly_request_with_params(commit_id: '123', limit: 0), kind_of(Hash))
|
|
|
|
.and_return([])
|
|
|
|
|
|
|
|
client.branch_names_contains_sha('123')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#get_tag_messages' do
|
|
|
|
it 'sends a get_tag_messages message' do
|
|
|
|
expect_any_instance_of(Gitaly::RefService::Stub)
|
|
|
|
.to receive(:get_tag_messages)
|
|
|
|
.with(gitaly_request_with_params(tag_ids: ['some_tag_id']), kind_of(Hash))
|
|
|
|
.and_return([])
|
|
|
|
|
|
|
|
client.get_tag_messages(['some_tag_id'])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-10-03 04:35:01 -04:00
|
|
|
describe '#find_ref_name', :seed_helper do
|
2017-06-29 08:11:42 -04:00
|
|
|
subject { client.find_ref_name(SeedRepo::Commit::ID, 'refs/heads/master') }
|
|
|
|
|
2017-07-05 16:12:10 -04:00
|
|
|
it { is_expected.to be_utf8 }
|
|
|
|
it { is_expected.to eq('refs/heads/master') }
|
2017-06-29 08:11:42 -04:00
|
|
|
end
|
2017-08-14 07:12:32 -04:00
|
|
|
|
2017-10-03 04:35:01 -04:00
|
|
|
describe '#ref_exists?', :seed_helper do
|
2017-08-14 07:12:32 -04:00
|
|
|
it 'finds the master branch ref' do
|
|
|
|
expect(client.ref_exists?('refs/heads/master')).to eq(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false for an illegal tag name ref' do
|
|
|
|
expect(client.ref_exists?('refs/tags/.this-tag-name-is-illegal')).to eq(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'raises an argument error if the ref name parameter does not start with refs/' do
|
|
|
|
expect { client.ref_exists?('reXXXXX') }.to raise_error(ArgumentError)
|
|
|
|
end
|
|
|
|
end
|
2017-11-17 11:54:48 -05:00
|
|
|
|
|
|
|
describe '#delete_refs' do
|
|
|
|
let(:prefixes) { %w(refs/heads refs/keep-around) }
|
|
|
|
|
|
|
|
it 'sends a delete_refs message' do
|
|
|
|
expect_any_instance_of(Gitaly::RefService::Stub)
|
|
|
|
.to receive(:delete_refs)
|
|
|
|
.with(gitaly_request_with_params(except_with_prefix: prefixes), kind_of(Hash))
|
2018-01-25 14:59:33 -05:00
|
|
|
.and_return(double('delete_refs_response', git_error: ""))
|
2017-11-17 11:54:48 -05:00
|
|
|
|
|
|
|
client.delete_refs(except_with_prefixes: prefixes)
|
|
|
|
end
|
|
|
|
end
|
2019-05-02 17:41:05 -04:00
|
|
|
|
|
|
|
describe '#pack_refs' do
|
|
|
|
it 'sends a pack_refs message' do
|
|
|
|
expect_any_instance_of(Gitaly::RefService::Stub)
|
|
|
|
.to receive(:pack_refs)
|
|
|
|
.with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash))
|
|
|
|
.and_return(double(:pack_refs_response))
|
|
|
|
|
|
|
|
client.pack_refs
|
|
|
|
end
|
|
|
|
end
|
2017-02-15 21:08:30 -05:00
|
|
|
end
|