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

remote_mirror_spec.rb « git « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0954879f6bdd12c7a7697b3ada2aaf6a7e69530c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Git::RemoteMirror do
  describe '#update' do
    let(:project) { create(:project, :repository) }
    let(:repository) { project.repository }
    let(:ref_name) { 'foo' }
    let(:url) { 'https://example.com' }
    let(:options) { { only_branches_matching: ['master'], ssh_key: 'KEY', known_hosts: 'KNOWN HOSTS', keep_divergent_refs: true } }

    subject(:remote_mirror) { described_class.new(repository, ref_name, url, **options) }

    shared_examples 'an update' do
      it 'delegates to the Gitaly client' do
        expect(repository.gitaly_remote_client)
          .to receive(:update_remote_mirror)
          .with(ref_name, url, ['master'], ssh_key: 'KEY', known_hosts: 'KNOWN HOSTS', keep_divergent_refs: true)

        remote_mirror.update # rubocop:disable Rails/SaveBang
      end
    end

    context 'with url' do
      it_behaves_like 'an update'
    end

    context 'without url' do
      let(:url) { nil }

      it_behaves_like 'an update'
    end

    it 'wraps gitaly errors' do
      expect(repository.gitaly_remote_client)
        .to receive(:update_remote_mirror)
        .and_raise(StandardError)

      expect { remote_mirror.update }.to raise_error(StandardError) # rubocop:disable Rails/SaveBang
    end
  end
end