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

replicate_service_spec.rb « repositories « services « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b4fbc478d2f1efc9bac444db958851e1bc38f326 (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
44
45
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Repositories::ReplicateService, feature_category: :source_code_management do
  let(:new_checksum) { 'match' }
  let(:repository) { instance_double('Gitlab::Git::Repository', checksum: 'match') }
  let(:new_repository) { instance_double('Gitlab::Git::Repository', checksum: new_checksum) }

  subject { described_class.new(repository) }

  it 'replicates repository' do
    expect(new_repository).to receive(:replicate).with(repository)
    expect(new_repository).not_to receive(:remove)

    expect { subject.execute(new_repository, :project) }.not_to raise_error
  end

  context 'when checksum does not match' do
    let(:new_checksum) { 'does not match' }

    it 'raises an error and removes new repository' do
      expect(new_repository).to receive(:replicate).with(repository)
      expect(new_repository).to receive(:remove)

      expect do
        subject.execute(new_repository, :project)
      end.to raise_error(described_class::Error, /Failed to verify project repository/)
    end
  end

  context 'when an error is raised during checksum calculation' do
    it 'raises the error and removes new repository' do
      error = StandardError.new

      expect(new_repository).to receive(:replicate).with(repository)
      expect(new_repository).to receive(:checksum).and_raise(error)
      expect(new_repository).to receive(:remove)

      expect do
        subject.execute(new_repository, :project)
      end.to raise_error(error)
    end
  end
end