Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/gitaly_client')
-rw-r--r--spec/lib/gitlab/gitaly_client/commit_service_spec.rb113
-rw-r--r--spec/lib/gitlab/gitaly_client/conflict_files_stitcher_spec.rb25
-rw-r--r--spec/lib/gitlab/gitaly_client/conflicts_service_spec.rb25
-rw-r--r--spec/lib/gitlab/gitaly_client/ref_service_spec.rb11
-rw-r--r--spec/lib/gitlab/gitaly_client/remote_service_spec.rb62
-rw-r--r--spec/lib/gitlab/gitaly_client/repository_service_spec.rb153
6 files changed, 248 insertions, 141 deletions
diff --git a/spec/lib/gitlab/gitaly_client/commit_service_spec.rb b/spec/lib/gitlab/gitaly_client/commit_service_spec.rb
index 22c29403255..a0e2d43cf45 100644
--- a/spec/lib/gitlab/gitaly_client/commit_service_spec.rb
+++ b/spec/lib/gitlab/gitaly_client/commit_service_spec.rb
@@ -169,7 +169,11 @@ RSpec.describe Gitlab::GitalyClient::CommitService do
end
describe '#tree_entries' do
+ subject { client.tree_entries(repository, revision, path, recursive, pagination_params) }
+
let(:path) { '/' }
+ let(:recursive) { false }
+ let(:pagination_params) { nil }
it 'sends a get_tree_entries message' do
expect_any_instance_of(Gitaly::CommitService::Stub)
@@ -177,7 +181,7 @@ RSpec.describe Gitlab::GitalyClient::CommitService do
.with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash))
.and_return([])
- client.tree_entries(repository, revision, path, false)
+ is_expected.to eq([[], nil])
end
context 'with UTF-8 params strings' do
@@ -190,7 +194,26 @@ RSpec.describe Gitlab::GitalyClient::CommitService do
.with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash))
.and_return([])
- client.tree_entries(repository, revision, path, false)
+ is_expected.to eq([[], nil])
+ end
+ end
+
+ context 'with pagination parameters' do
+ let(:pagination_params) { { limit: 3, page_token: nil } }
+
+ it 'responds with a pagination cursor' do
+ pagination_cursor = Gitaly::PaginationCursor.new(next_cursor: 'aabbccdd')
+ response = Gitaly::GetTreeEntriesResponse.new(
+ entries: [],
+ pagination_cursor: pagination_cursor
+ )
+
+ expect_any_instance_of(Gitaly::CommitService::Stub)
+ .to receive(:get_tree_entries)
+ .with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash))
+ .and_return([response])
+
+ is_expected.to eq([[], pagination_cursor])
end
end
end
@@ -320,6 +343,92 @@ RSpec.describe Gitlab::GitalyClient::CommitService do
end
end
+ describe '#list_new_commits' do
+ let(:revisions) { [revision] }
+ let(:gitaly_commits) { create_list(:gitaly_commit, 3) }
+ let(:commits) { gitaly_commits.map { |c| Gitlab::Git::Commit.new(repository, c) }}
+
+ subject { client.list_new_commits(revisions, allow_quarantine: allow_quarantine) }
+
+ shared_examples 'a #list_all_commits message' do
+ it 'sends a list_all_commits message' do
+ expected_repository = repository.gitaly_repository.dup
+ expected_repository.git_alternate_object_directories = Google::Protobuf::RepeatedField.new(:string)
+
+ expect_next_instance_of(Gitaly::CommitService::Stub) do |service|
+ expect(service).to receive(:list_all_commits)
+ .with(gitaly_request_with_params(repository: expected_repository), kind_of(Hash))
+ .and_return([Gitaly::ListAllCommitsResponse.new(commits: gitaly_commits)])
+ end
+
+ expect(subject).to eq(commits)
+ end
+ end
+
+ shared_examples 'a #list_commits message' do
+ it 'sends a list_commits message' do
+ expect_next_instance_of(Gitaly::CommitService::Stub) do |service|
+ expect(service).to receive(:list_commits)
+ .with(gitaly_request_with_params(revisions: revisions + %w[--not --all]), kind_of(Hash))
+ .and_return([Gitaly::ListCommitsResponse.new(commits: gitaly_commits)])
+ end
+
+ expect(subject).to eq(commits)
+ end
+ end
+
+ before do
+ ::Gitlab::GitalyClient.clear_stubs!
+
+ allow(Gitlab::Git::HookEnv)
+ .to receive(:all)
+ .with(repository.gl_repository)
+ .and_return(git_env)
+ end
+
+ context 'with hook environment' do
+ let(:git_env) do
+ {
+ 'GIT_OBJECT_DIRECTORY_RELATIVE' => '.git/objects',
+ 'GIT_ALTERNATE_OBJECT_DIRECTORIES_RELATIVE' => ['/dir/one', '/dir/two']
+ }
+ end
+
+ context 'with allowed quarantine' do
+ let(:allow_quarantine) { true }
+
+ it_behaves_like 'a #list_all_commits message'
+ end
+
+ context 'with disallowed quarantine' do
+ let(:allow_quarantine) { false }
+
+ it_behaves_like 'a #list_commits message'
+ end
+ end
+
+ context 'without hook environment' do
+ let(:git_env) do
+ {
+ 'GIT_OBJECT_DIRECTORY_RELATIVE' => '',
+ 'GIT_ALTERNATE_OBJECT_DIRECTORIES_RELATIVE' => []
+ }
+ end
+
+ context 'with allowed quarantine' do
+ let(:allow_quarantine) { true }
+
+ it_behaves_like 'a #list_commits message'
+ end
+
+ context 'with disallowed quarantine' do
+ let(:allow_quarantine) { false }
+
+ it_behaves_like 'a #list_commits message'
+ end
+ end
+ end
+
describe '#commit_stats' do
let(:request) do
Gitaly::CommitStatsRequest.new(
diff --git a/spec/lib/gitlab/gitaly_client/conflict_files_stitcher_spec.rb b/spec/lib/gitlab/gitaly_client/conflict_files_stitcher_spec.rb
index 0bb8628af6c..0eecdfcb630 100644
--- a/spec/lib/gitlab/gitaly_client/conflict_files_stitcher_spec.rb
+++ b/spec/lib/gitlab/gitaly_client/conflict_files_stitcher_spec.rb
@@ -9,22 +9,37 @@ RSpec.describe Gitlab::GitalyClient::ConflictFilesStitcher do
target_repository = target_project.repository.raw
target_gitaly_repository = target_repository.gitaly_repository
+ ancestor_path_1 = 'ancestor/path/1'
our_path_1 = 'our/path/1'
their_path_1 = 'their/path/1'
our_mode_1 = 0744
commit_oid_1 = 'f00'
content_1 = 'content of the first file'
+ ancestor_path_2 = 'ancestor/path/2'
our_path_2 = 'our/path/2'
their_path_2 = 'their/path/2'
our_mode_2 = 0600
commit_oid_2 = 'ba7'
content_2 = 'content of the second file'
- header_1 = double(repository: target_gitaly_repository, commit_oid: commit_oid_1,
- our_path: our_path_1, their_path: their_path_1, our_mode: our_mode_1)
- header_2 = double(repository: target_gitaly_repository, commit_oid: commit_oid_2,
- our_path: our_path_2, their_path: their_path_2, our_mode: our_mode_2)
+ header_1 = double(
+ repository: target_gitaly_repository,
+ commit_oid: commit_oid_1,
+ ancestor_path: ancestor_path_1,
+ our_path: our_path_1,
+ their_path: their_path_1,
+ our_mode: our_mode_1
+ )
+
+ header_2 = double(
+ repository: target_gitaly_repository,
+ commit_oid: commit_oid_2,
+ ancestor_path: ancestor_path_2,
+ our_path: our_path_2,
+ their_path: their_path_2,
+ our_mode: our_mode_2
+ )
messages = [
double(files: [double(header: header_1), double(header: nil, content: content_1[0..5])]),
@@ -39,6 +54,7 @@ RSpec.describe Gitlab::GitalyClient::ConflictFilesStitcher do
expect(conflict_files.size).to be(2)
expect(conflict_files[0].content).to eq(content_1)
+ expect(conflict_files[0].ancestor_path).to eq(ancestor_path_1)
expect(conflict_files[0].their_path).to eq(their_path_1)
expect(conflict_files[0].our_path).to eq(our_path_1)
expect(conflict_files[0].our_mode).to be(our_mode_1)
@@ -46,6 +62,7 @@ RSpec.describe Gitlab::GitalyClient::ConflictFilesStitcher do
expect(conflict_files[0].commit_oid).to eq(commit_oid_1)
expect(conflict_files[1].content).to eq(content_2)
+ expect(conflict_files[1].ancestor_path).to eq(ancestor_path_2)
expect(conflict_files[1].their_path).to eq(their_path_2)
expect(conflict_files[1].our_path).to eq(our_path_2)
expect(conflict_files[1].our_mode).to be(our_mode_2)
diff --git a/spec/lib/gitlab/gitaly_client/conflicts_service_spec.rb b/spec/lib/gitlab/gitaly_client/conflicts_service_spec.rb
index e90cb966917..89a41ae71f3 100644
--- a/spec/lib/gitlab/gitaly_client/conflicts_service_spec.rb
+++ b/spec/lib/gitlab/gitaly_client/conflicts_service_spec.rb
@@ -15,18 +15,31 @@ RSpec.describe Gitlab::GitalyClient::ConflictsService do
end
describe '#list_conflict_files' do
+ let(:allow_tree_conflicts) { false }
let(:request) do
Gitaly::ListConflictFilesRequest.new(
- repository: target_gitaly_repository, our_commit_oid: our_commit_oid,
- their_commit_oid: their_commit_oid
+ repository: target_gitaly_repository,
+ our_commit_oid: our_commit_oid,
+ their_commit_oid: their_commit_oid,
+ allow_tree_conflicts: allow_tree_conflicts
)
end
- it 'sends an RPC request' do
- expect_any_instance_of(Gitaly::ConflictsService::Stub).to receive(:list_conflict_files)
- .with(request, kind_of(Hash)).and_return([].to_enum)
+ shared_examples_for 'listing conflicts' do
+ it 'sends an RPC request' do
+ expect_any_instance_of(Gitaly::ConflictsService::Stub).to receive(:list_conflict_files)
+ .with(request, kind_of(Hash)).and_return([].to_enum)
+
+ client.list_conflict_files(allow_tree_conflicts: allow_tree_conflicts)
+ end
+ end
+
+ it_behaves_like 'listing conflicts'
+
+ context 'when allow_tree_conflicts is set to true' do
+ let(:allow_tree_conflicts) { true }
- client.list_conflict_files
+ it_behaves_like 'listing conflicts'
end
end
diff --git a/spec/lib/gitlab/gitaly_client/ref_service_spec.rb b/spec/lib/gitlab/gitaly_client/ref_service_spec.rb
index a4c6e30bba8..e19be965e68 100644
--- a/spec/lib/gitlab/gitaly_client/ref_service_spec.rb
+++ b/spec/lib/gitlab/gitaly_client/ref_service_spec.rb
@@ -178,6 +178,17 @@ RSpec.describe Gitlab::GitalyClient::RefService do
end
end
+ describe '#get_tag_signatures' do
+ it 'sends a get_tag_signatures message' do
+ expect_any_instance_of(Gitaly::RefService::Stub)
+ .to receive(:get_tag_signatures)
+ .with(gitaly_request_with_params(tag_revisions: ['some_tag_id']), kind_of(Hash))
+ .and_return([])
+
+ client.get_tag_signatures(['some_tag_id'])
+ end
+ end
+
describe '#find_ref_name', :seed_helper do
subject { client.find_ref_name(SeedRepo::Commit::ID, 'refs/heads/master') }
diff --git a/spec/lib/gitlab/gitaly_client/remote_service_spec.rb b/spec/lib/gitlab/gitaly_client/remote_service_spec.rb
index 2ec5f70be76..3d0f8358406 100644
--- a/spec/lib/gitlab/gitaly_client/remote_service_spec.rb
+++ b/spec/lib/gitlab/gitaly_client/remote_service_spec.rb
@@ -6,36 +6,9 @@ RSpec.describe Gitlab::GitalyClient::RemoteService do
let(:project) { create(:project) }
let(:storage_name) { project.repository_storage }
let(:relative_path) { project.disk_path + '.git' }
- let(:remote_name) { 'my-remote' }
let(:client) { described_class.new(project.repository) }
- describe '#add_remote' do
- let(:url) { 'http://my-repo.git' }
- let(:mirror_refmap) { :all_refs }
-
- it 'sends an add_remote message' do
- expect_any_instance_of(Gitaly::RemoteService::Stub)
- .to receive(:add_remote)
- .with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash))
- .and_return(double(:add_remote_response))
-
- client.add_remote(remote_name, url, mirror_refmap)
- end
- end
-
- describe '#remove_remote' do
- it 'sends an remove_remote message and returns the result value' do
- expect_any_instance_of(Gitaly::RemoteService::Stub)
- .to receive(:remove_remote)
- .with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash))
- .and_return(double(result: true))
-
- expect(client.remove_remote(remote_name)).to be(true)
- end
- end
-
describe '#find_remote_root_ref' do
- let(:remote) { 'origin' }
let(:url) { 'http://git.example.com/my-repo.git' }
let(:auth) { 'Basic secret' }
let(:expected_params) { { remote_url: url, http_authorization_header: auth } }
@@ -47,7 +20,7 @@ RSpec.describe Gitlab::GitalyClient::RemoteService do
.with(gitaly_request_with_params(expected_params), kind_of(Hash))
.and_return(double(ref: 'master'))
- expect(client.find_remote_root_ref(remote, url, auth)).to eq 'master'
+ expect(client.find_remote_root_ref(url, auth)).to eq 'master'
end
it 'ensure ref is a valid UTF-8 string' do
@@ -57,39 +30,24 @@ RSpec.describe Gitlab::GitalyClient::RemoteService do
.with(gitaly_request_with_params(expected_params), kind_of(Hash))
.and_return(double(ref: "an_invalid_ref_\xE5"))
- expect(client.find_remote_root_ref(remote, url, auth)).to eq "an_invalid_ref_å"
+ expect(client.find_remote_root_ref(url, auth)).to eq "an_invalid_ref_å"
end
end
describe '#update_remote_mirror' do
- let(:ref_name) { 'remote_mirror_1' }
let(:only_branches_matching) { %w[my-branch master] }
let(:ssh_key) { 'KEY' }
let(:known_hosts) { 'KNOWN HOSTS' }
+ let(:url) { 'http:://git.example.com/my-repo.git' }
+ let(:expected_params) { { remote: Gitaly::UpdateRemoteMirrorRequest::Remote.new(url: url) } }
- shared_examples 'an update' do
- it 'sends an update_remote_mirror message' do
- expect_any_instance_of(Gitaly::RemoteService::Stub)
- .to receive(:update_remote_mirror)
- .with(array_including(gitaly_request_with_params(expected_params)), kind_of(Hash))
- .and_return(double(:update_remote_mirror_response))
-
- client.update_remote_mirror(ref_name, url, only_branches_matching, ssh_key: ssh_key, known_hosts: known_hosts, keep_divergent_refs: true)
- end
- end
-
- context 'with remote name' do
- let(:url) { nil }
- let(:expected_params) { { ref_name: ref_name } }
-
- it_behaves_like 'an update'
- end
-
- context 'with remote URL' do
- let(:url) { 'http:://git.example.com/my-repo.git' }
- let(:expected_params) { { remote: Gitaly::UpdateRemoteMirrorRequest::Remote.new(url: url) } }
+ it 'sends an update_remote_mirror message' do
+ expect_any_instance_of(Gitaly::RemoteService::Stub)
+ .to receive(:update_remote_mirror)
+ .with(array_including(gitaly_request_with_params(expected_params)), kind_of(Hash))
+ .and_return(double(:update_remote_mirror_response))
- it_behaves_like 'an update'
+ client.update_remote_mirror(url, only_branches_matching, ssh_key: ssh_key, known_hosts: known_hosts, keep_divergent_refs: true)
end
end
diff --git a/spec/lib/gitlab/gitaly_client/repository_service_spec.rb b/spec/lib/gitlab/gitaly_client/repository_service_spec.rb
index 53805d67f9f..4b037d3f836 100644
--- a/spec/lib/gitlab/gitaly_client/repository_service_spec.rb
+++ b/spec/lib/gitlab/gitaly_client/repository_service_spec.rb
@@ -122,89 +122,75 @@ RSpec.describe Gitlab::GitalyClient::RepositoryService do
end
describe '#fetch_remote' do
- shared_examples 'a fetch' do
- it 'sends a fetch_remote_request message' do
- expected_remote_params = Gitaly::Remote.new(
- url: url, http_authorization_header: "", mirror_refmaps: [])
-
- expected_request = gitaly_request_with_params(
- remote: remote,
- remote_params: url ? expected_remote_params : nil,
- ssh_key: '',
- known_hosts: '',
- force: false,
- no_tags: false,
- no_prune: false,
- check_tags_changed: false
- )
-
- 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(remote, url: url, refmap: nil, ssh_auth: nil, forced: false, no_tags: false, timeout: 1, check_tags_changed: false)
- end
+ 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
+ )
- 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 | '' | '' | {}
- end
+ expect_any_instance_of(Gitaly::RepositoryService::Stub)
+ .to receive(:fetch_remote)
+ .with(expected_request, kind_of(Hash))
+ .and_return(double(value: true))
- 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_remote_params = Gitaly::Remote.new(
- url: url, http_authorization_header: "", mirror_refmaps: [])
-
- expected_request = gitaly_request_with_params({
- remote: remote,
- remote_params: url ? expected_remote_params : nil,
- 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(remote, url: url, refmap: nil, ssh_auth: ssh_auth, forced: false, no_tags: false, timeout: 1)
- end
- end
- end
+ client.fetch_remote(url, refmap: nil, ssh_auth: nil, forced: false, no_tags: false, timeout: 1, check_tags_changed: false)
end
- context 'with remote' do
- it_behaves_like 'a fetch' do
- let(:remote) { 'remote-name' }
- let(:url) { nil }
+ 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 | '' | '' | {}
end
- end
- context 'with URL' do
- it_behaves_like 'a fetch' do
- let(:remote) { "" }
- let(:url) { 'https://example.com/git/repo.git' }
+ 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
end
end
end
@@ -333,4 +319,17 @@ RSpec.describe Gitlab::GitalyClient::RepositoryService do
client.replicate(source_repository)
end
end
+
+ 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
end