2019-12-26 22:10:19 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Gitlab::GitalyClient::RemoteService do
|
2018-03-17 18:26:18 +05:30
|
|
|
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
|
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
describe '#find_remote_root_ref' 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))
|
|
|
|
.and_return(double(ref: 'master'))
|
|
|
|
|
|
|
|
expect(client.find_remote_root_ref('origin')).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))
|
|
|
|
.and_return(double(ref: "an_invalid_ref_\xE5"))
|
|
|
|
|
|
|
|
expect(client.find_remote_root_ref('origin')).to eq "an_invalid_ref_å"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
describe '#update_remote_mirror' do
|
|
|
|
let(:ref_name) { 'remote_mirror_1' }
|
2020-03-13 15:44:24 +05:30
|
|
|
let(:only_branches_matching) { %w[my-branch master] }
|
2019-02-15 15:39:39 +05:30
|
|
|
let(:ssh_key) { 'KEY' }
|
|
|
|
let(:known_hosts) { 'KNOWN HOSTS' }
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
it 'sends an update_remote_mirror message' do
|
|
|
|
expect_any_instance_of(Gitaly::RemoteService::Stub)
|
|
|
|
.to receive(:update_remote_mirror)
|
|
|
|
.with(kind_of(Enumerator), kind_of(Hash))
|
|
|
|
.and_return(double(:update_remote_mirror_response))
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
client.update_remote_mirror(ref_name, only_branches_matching, ssh_key: ssh_key, known_hosts: known_hosts, keep_divergent_refs: true)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
2018-05-09 12:01:36 +05:30
|
|
|
|
|
|
|
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-28 23:09:34 +05:30
|
|
|
let(:storage_name) { 'default' }
|
2018-05-09 12:01:36 +05:30
|
|
|
|
|
|
|
it 'returns false' do
|
2020-07-28 23:09:34 +05:30
|
|
|
expect(Gitaly::FindRemoteRepositoryRequest).to receive(:new).with(remote: url, storage_name: storage_name).and_call_original
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
expect(described_class.exists?(url)).to be(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|