BigW Consortium Gitlab

commit_service_spec.rb 4.46 KB
Newer Older
1 2
require 'spec_helper'

3
describe Gitlab::GitalyClient::CommitService do
4
  let(:project) { create(:project, :repository) }
5
  let(:storage_name) { project.repository_storage }
6
  let(:relative_path) { project.disk_path + '.git' }
7 8
  let(:repository) { project.repository }
  let(:repository_message) { repository.gitaly_repository }
9 10 11
  let(:revision) { '913c66a37b4a45b9769037c55c2d238bd0942d2e' }
  let(:commit) { project.commit(revision) }
  let(:client) { described_class.new(repository) }
12

13
  describe '#diff_from_parent' do
14 15 16 17 18
    context 'when a commit has a parent' do
      it 'sends an RPC request with the parent ID as left commit' do
        request = Gitaly::CommitDiffRequest.new(
          repository: repository_message,
          left_commit_id: 'cfe32cf61b73a0d5e9f13e774abde7ff789b1660',
19 20 21 22
          right_commit_id: commit.id,
          collapse_diffs: true,
          enforce_limits: true,
          **Gitlab::Git::DiffCollection.collection_limits.to_h
23 24
        )

25
        expect_any_instance_of(Gitaly::DiffService::Stub).to receive(:commit_diff).with(request, kind_of(Hash))
26

27
        client.diff_from_parent(commit)
28 29 30 31 32
      end
    end

    context 'when a commit does not have a parent' do
      it 'sends an RPC request with empty tree ref as left commit' do
33
        initial_commit = project.commit('1a0b36b3cdad1d2ee32457c102a8c0b7056fa863').raw
34 35 36
        request        = Gitaly::CommitDiffRequest.new(
          repository: repository_message,
          left_commit_id: '4b825dc642cb6eb9a060e54bf8d69288fbee4904',
37 38 39 40
          right_commit_id: initial_commit.id,
          collapse_diffs: true,
          enforce_limits: true,
          **Gitlab::Git::DiffCollection.collection_limits.to_h
41 42
        )

43
        expect_any_instance_of(Gitaly::DiffService::Stub).to receive(:commit_diff).with(request, kind_of(Hash))
44

45
        client.diff_from_parent(initial_commit)
46 47 48
      end
    end

49
    it 'returns a Gitlab::GitalyClient::DiffStitcher' do
50
      ret = client.diff_from_parent(commit)
51

52
      expect(ret).to be_kind_of(Gitlab::GitalyClient::DiffStitcher)
53 54 55 56 57 58 59 60 61 62 63 64
    end
  end

  describe '#commit_deltas' do
    context 'when a commit has a parent' do
      it 'sends an RPC request with the parent ID as left commit' do
        request = Gitaly::CommitDeltaRequest.new(
          repository: repository_message,
          left_commit_id: 'cfe32cf61b73a0d5e9f13e774abde7ff789b1660',
          right_commit_id: commit.id
        )

65
        expect_any_instance_of(Gitaly::DiffService::Stub).to receive(:commit_delta).with(request, kind_of(Hash)).and_return([])
66

67
        client.commit_deltas(commit)
68 69 70 71 72 73 74 75 76 77 78 79
      end
    end

    context 'when a commit does not have a parent' do
      it 'sends an RPC request with empty tree ref as left commit' do
        initial_commit = project.commit('1a0b36b3cdad1d2ee32457c102a8c0b7056fa863')
        request        = Gitaly::CommitDeltaRequest.new(
          repository: repository_message,
          left_commit_id: '4b825dc642cb6eb9a060e54bf8d69288fbee4904',
          right_commit_id: initial_commit.id
        )

80
        expect_any_instance_of(Gitaly::DiffService::Stub).to receive(:commit_delta).with(request, kind_of(Hash)).and_return([])
81

82
        client.commit_deltas(initial_commit)
83
      end
84 85
    end
  end
86 87 88 89

  describe '#between' do
    let(:from) { 'master' }
    let(:to) { '4b825dc642cb6eb9a060e54bf8d69288fbee4904' }
90

91 92 93 94 95 96 97 98 99 100 101
    it 'sends an RPC request' do
      request = Gitaly::CommitsBetweenRequest.new(
        repository: repository_message, from: from, to: to
      )

      expect_any_instance_of(Gitaly::CommitService::Stub).to receive(:commits_between)
        .with(request, kind_of(Hash)).and_return([])

      described_class.new(repository).between(from, to)
    end
  end
102 103 104 105 106 107 108 109 110 111 112 113 114

  describe '#tree_entries' do
    let(:path) { '/' }

    it 'sends a get_tree_entries message' do
      expect_any_instance_of(Gitaly::CommitService::Stub)
        .to receive(:get_tree_entries)
        .with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash))
        .and_return([])

      client.tree_entries(repository, revision, path)
    end
  end
115 116 117 118 119 120 121 122 123 124 125 126 127 128

  describe '#find_commit' do
    let(:revision) { '4b825dc642cb6eb9a060e54bf8d69288fbee4904' }
    it 'sends an RPC request' do
      request = Gitaly::FindCommitRequest.new(
        repository: repository_message, revision: revision
      )

      expect_any_instance_of(Gitaly::CommitService::Stub).to receive(:find_commit)
        .with(request, kind_of(Hash)).and_return(double(commit: nil))

      described_class.new(repository).find_commit(revision)
    end
  end
129
end