summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/gitaly_client/conflicts_service_spec.rb
blob: e4fe01a671f4dac035645633ecf45a0bb4fe8e36 (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
require 'spec_helper'

describe Gitlab::GitalyClient::ConflictsService do
  let(:project) { create(:project, :repository) }
  let(:target_project) { create(:project, :repository) }
  let(:source_repository) { project.repository.raw }
  let(:target_repository) { target_project.repository.raw }
  let(:target_gitaly_repository) { target_repository.gitaly_repository }
  let(:our_commit_oid) { 'f00' }
  let(:their_commit_oid) { 'f44' }
  let(:client) do
    described_class.new(target_repository, our_commit_oid, their_commit_oid)
  end

  describe '#list_conflict_files' do
    let(:request) do
      Gitaly::ListConflictFilesRequest.new(
        repository: target_gitaly_repository, our_commit_oid: our_commit_oid,
        their_commit_oid: their_commit_oid
      )
    end

    it 'sends an RPC request' do
      expect_any_instance_of(Gitaly::ConflictsService::Stub).to receive(:list_conflict_files)
        .with(request, kind_of(Hash)).and_return([].to_enum)

      client.list_conflict_files
    end
  end

  describe '#resolve_conflicts' do
    let(:user) { create(:user) }
    let(:files) do
      [{ old_path: 'some/path', new_path: 'some/path', content: '' }]
    end
    let(:source_branch) { 'master' }
    let(:target_branch) { 'feature' }
    let(:commit_message) { 'Solving conflicts' }
    let(:resolution) do
      Gitlab::Git::Conflict::Resolution.new(user, files, commit_message)
    end

    subject do
      client.resolve_conflicts(source_repository, resolution, source_branch, target_branch)
    end

    it 'sends an RPC request' do
      expect_any_instance_of(Gitaly::ConflictsService::Stub).to receive(:resolve_conflicts)
        .with(kind_of(Enumerator), kind_of(Hash)).and_return(double(resolution_error: ""))

      subject
    end

    it 'raises a relevant exception if resolution_error is present' do
      expect_any_instance_of(Gitaly::ConflictsService::Stub).to receive(:resolve_conflicts)
        .with(kind_of(Enumerator), kind_of(Hash)).and_return(double(resolution_error: "something happened"))

      expect { subject }.to raise_error(Gitlab::Git::Conflict::Resolver::ResolutionError)
    end
  end
end