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

object_pool_service_spec.rb « gitaly_client « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: baf7076c7185bd7d8ee5b0d9542c691c6bbc57b1 (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::GitalyClient::ObjectPoolService do
  let(:pool_repository) { create(:pool_repository) }
  let(:project) { pool_repository.source_project }
  let(:raw_repository) { project.repository.raw }
  let(:object_pool) { pool_repository.object_pool }

  subject { described_class.new(object_pool) }

  before do
    subject.create(raw_repository) # rubocop:disable Rails/SaveBang
  end

  describe '#create' do
    it 'exists on disk' do
      expect(object_pool.repository.exists?).to be(true)
    end

    context 'when the pool already exists' do
      it 'returns an error' do
        expect do
          subject.create(raw_repository) # rubocop:disable Rails/SaveBang
        end.to raise_error(GRPC::FailedPrecondition)
      end
    end
  end

  describe '#delete' do
    it 'removes the repository from disk' do
      subject.delete

      expect(object_pool.repository.exists?).to be(false)
    end

    context 'when called twice' do
      it "doesn't raise an error" do
        subject.delete

        expect { object_pool.delete }.not_to raise_error
      end
    end
  end

  describe '#fetch' do
    context 'without changes' do
      it 'fetches changes' do
        expect(subject.fetch(project.repository)).to eq(Gitaly::FetchIntoObjectPoolResponse.new)
      end
    end

    context 'with new reference in source repository' do
      let(:branch) { 'ref-to-be-fetched' }
      let(:source_ref) { "refs/heads/#{branch}" }
      let(:pool_ref) { "refs/remotes/origin/heads/#{branch}" }

      before do
        # Create a new reference in the source repository that we can fetch.
        project.repository.write_ref(source_ref, 'refs/heads/master')
      end

      it 'fetches changes' do
        # Sanity-check to verify that the reference only exists in the source repository now, but not in the
        # object pool.
        expect(project.repository.ref_exists?(source_ref)).to be(true)
        expect(object_pool.repository.ref_exists?(pool_ref)).to be(false)

        subject.fetch(project.repository)

        # The fetch should've created the reference in the object pool.
        expect(object_pool.repository.ref_exists?(pool_ref)).to be(true)
      end
    end
  end
end