2019-11-13 03:06:31 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-12-20 20:17:28 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 18:09:03 +00:00
|
|
|
RSpec.describe Gitlab::GitalyClient::RemoteService do
|
2017-12-20 20:17:28 +00:00
|
|
|
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) }
|
|
|
|
|
2018-09-04 20:00:36 +00:00
|
|
|
describe '#find_remote_root_ref' do
|
2021-05-06 12:10:38 +00:00
|
|
|
let(:remote) { 'origin' }
|
|
|
|
let(:url) { 'http://git.example.com/my-repo.git' }
|
|
|
|
let(:auth) { 'Basic secret' }
|
2021-05-26 18:10:52 +00:00
|
|
|
let(:expected_params) { { remote_url: url, http_authorization_header: auth } }
|
2021-05-06 12:10:38 +00:00
|
|
|
|
2021-05-26 18:10:52 +00:00
|
|
|
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'))
|
2021-05-06 12:10:38 +00:00
|
|
|
|
2021-05-26 18:10:52 +00:00
|
|
|
expect(client.find_remote_root_ref(remote, url, auth)).to eq 'master'
|
2021-05-06 12:10:38 +00:00
|
|
|
end
|
|
|
|
|
2021-05-26 18:10:52 +00:00
|
|
|
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"))
|
2018-09-07 04:46:12 +00:00
|
|
|
|
2021-05-26 18:10:52 +00:00
|
|
|
expect(client.find_remote_root_ref(remote, url, auth)).to eq "an_invalid_ref_å"
|
2018-09-07 04:46:12 +00:00
|
|
|
end
|
2018-09-04 20:00:36 +00:00
|
|
|
end
|
|
|
|
|
2018-01-17 23:25:16 +00:00
|
|
|
describe '#update_remote_mirror' do
|
|
|
|
let(:ref_name) { 'remote_mirror_1' }
|
2019-12-20 09:24:38 +00:00
|
|
|
let(:only_branches_matching) { %w[my-branch master] }
|
2018-11-12 10:52:48 +00:00
|
|
|
let(:ssh_key) { 'KEY' }
|
|
|
|
let(:known_hosts) { 'KNOWN HOSTS' }
|
2018-01-17 23:25:16 +00:00
|
|
|
|
2021-06-16 15:10:08 +00:00
|
|
|
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) } }
|
2018-01-17 23:25:16 +00:00
|
|
|
|
2021-06-16 15:10:08 +00:00
|
|
|
it_behaves_like 'an update'
|
2018-01-17 23:25:16 +00:00
|
|
|
end
|
|
|
|
end
|
2018-03-27 09:48:11 +00:00
|
|
|
|
|
|
|
describe '.exists?' do
|
|
|
|
context "when the remote doesn't exist" do
|
|
|
|
let(:url) { 'https://gitlab.com/gitlab-org/ik-besta-niet-of-ik-word-geplaagd.git' }
|
2020-07-07 15:08:49 +00:00
|
|
|
let(:storage_name) { 'default' }
|
2018-03-27 09:48:11 +00:00
|
|
|
|
|
|
|
it 'returns false' do
|
2020-07-07 15:08:49 +00:00
|
|
|
expect(Gitaly::FindRemoteRepositoryRequest).to receive(:new).with(remote: url, storage_name: storage_name).and_call_original
|
|
|
|
|
2018-03-27 09:48:11 +00:00
|
|
|
expect(described_class.exists?(url)).to be(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-12-20 20:17:28 +00:00
|
|
|
end
|