summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/gitaly_client
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/gitaly_client')
-rw-r--r--spec/lib/gitlab/gitaly_client/remote_service_spec.rb51
-rw-r--r--spec/lib/gitlab/gitaly_client/repository_service_spec.rb132
2 files changed, 92 insertions, 91 deletions
diff --git a/spec/lib/gitlab/gitaly_client/remote_service_spec.rb b/spec/lib/gitlab/gitaly_client/remote_service_spec.rb
index 70fc4fe4416..df9dde324a5 100644
--- a/spec/lib/gitlab/gitaly_client/remote_service_spec.rb
+++ b/spec/lib/gitlab/gitaly_client/remote_service_spec.rb
@@ -38,47 +38,26 @@ RSpec.describe Gitlab::GitalyClient::RemoteService 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 } }
- shared_examples 'a find_remote_root_ref call' do
- it 'sends an find_remote_root_ref message and returns the root ref' do
- expect_any_instance_of(Gitaly::RemoteService::Stub)
- .to receive(:find_remote_root_ref)
- .with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash))
- .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'
- end
-
- it 'ensure ref is a valid UTF-8 string' do
- expect_any_instance_of(Gitaly::RemoteService::Stub)
- .to receive(:find_remote_root_ref)
- .with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash))
- .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_å"
- end
- end
-
- context 'with inmemory feature enabled' do
- before do
- stub_feature_flags(find_remote_root_refs_inmemory: true)
- end
+ it 'sends an find_remote_root_ref message and returns the root ref' do
+ expect_any_instance_of(Gitaly::RemoteService::Stub)
+ .to receive(:find_remote_root_ref)
+ .with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash))
+ .with(gitaly_request_with_params(expected_params), kind_of(Hash))
+ .and_return(double(ref: 'master'))
- it_behaves_like 'a find_remote_root_ref call' do
- let(:expected_params) { { remote_url: url, http_authorization_header: auth } }
- end
+ expect(client.find_remote_root_ref(remote, url, auth)).to eq 'master'
end
- context 'with inmemory feature disabled' do
- before do
- stub_feature_flags(find_remote_root_refs_inmemory: false)
- end
+ it 'ensure ref is a valid UTF-8 string' do
+ expect_any_instance_of(Gitaly::RemoteService::Stub)
+ .to receive(:find_remote_root_ref)
+ .with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash))
+ .with(gitaly_request_with_params(expected_params), kind_of(Hash))
+ .and_return(double(ref: "an_invalid_ref_\xE5"))
- it_behaves_like 'a find_remote_root_ref call' do
- let(:expected_params) { { remote: remote } }
- end
+ expect(client.find_remote_root_ref(remote, url, auth)).to eq "an_invalid_ref_å"
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 26ec194a2e7..56c8fe20eca 100644
--- a/spec/lib/gitlab/gitaly_client/repository_service_spec.rb
+++ b/spec/lib/gitlab/gitaly_client/repository_service_spec.rb
@@ -122,67 +122,89 @@ RSpec.describe Gitlab::GitalyClient::RepositoryService do
end
describe '#fetch_remote' do
- let(:remote) { 'remote-name' }
-
- it 'sends a fetch_remote_request message' do
- expected_request = gitaly_request_with_params(
- remote: remote,
- ssh_key: '',
- known_hosts: '',
- force: false,
- no_tags: false,
- no_prune: false,
- check_tags_changed: false
- )
+ 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
- expect_any_instance_of(Gitaly::RepositoryService::Stub)
- .to receive(:fetch_remote)
- .with(expected_request, kind_of(Hash))
- .and_return(double(value: true))
+ 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
- client.fetch_remote(remote, ssh_auth: nil, forced: false, no_tags: false, timeout: 1, check_tags_changed: false)
+ 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
end
- 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 | '' | '' | {}
+ context 'with remote' do
+ it_behaves_like 'a fetch' do
+ let(:remote) { 'remote-name' }
+ let(:url) { nil }
end
+ end
- 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: remote,
- 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, ssh_auth: ssh_auth, forced: false, no_tags: false, timeout: 1)
- end
+ context 'with URL' do
+ it_behaves_like 'a fetch' do
+ let(:remote) { "" }
+ let(:url) { 'https://example.com/git/repo.git' }
end
end
end