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

describe Gitlab::GitalyClient::DiffStitcher, lib: true do
  describe 'enumeration' do
    it 'combines segregated diff messages together' do
      diff_1 = OpenStruct.new(
        to_path: ".gitmodules",
        from_path: ".gitmodules",
        old_mode: 0100644,
        new_mode: 0100644,
        from_id: '357406f3075a57708d0163752905cc1576fceacc',
        to_id: '8e5177d718c561d36efde08bad36b43687ee6bf0',
        patch: 'a' * 100
      )
      diff_2 = OpenStruct.new(
        to_path: ".gitignore",
        from_path: ".gitignore",
        old_mode: 0100644,
        new_mode: 0100644,
        from_id: '357406f3075a57708d0163752905cc1576fceacc',
        to_id: '8e5177d718c561d36efde08bad36b43687ee6bf0',
        patch: 'a' * 200
      )
      diff_3 = OpenStruct.new(
        to_path: "README",
        from_path: "README",
        old_mode: 0100644,
        new_mode: 0100644,
        from_id: '357406f3075a57708d0163752905cc1576fceacc',
        to_id: '8e5177d718c561d36efde08bad36b43687ee6bf0',
        patch: 'a' * 100
      )

      msg_1 = OpenStruct.new(diff_1.to_h.except(:patch))
      msg_1.raw_patch_data = diff_1.patch
      msg_1.end_of_patch = true

      msg_2 = OpenStruct.new(diff_2.to_h.except(:patch))
      msg_2.raw_patch_data = diff_2.patch[0..100]
      msg_2.end_of_patch = false

      msg_3 = OpenStruct.new(raw_patch_data: diff_2.patch[101..-1], end_of_patch: true)

      msg_4 = OpenStruct.new(diff_3.to_h.except(:patch))
      msg_4.raw_patch_data = diff_3.patch
      msg_4.end_of_patch = true

      diff_msgs = [msg_1, msg_2, msg_3, msg_4]

      expected_diffs = [
        Gitlab::GitalyClient::Diff.new(diff_1.to_h),
        Gitlab::GitalyClient::Diff.new(diff_2.to_h),
        Gitlab::GitalyClient::Diff.new(diff_3.to_h)
      ]

      expect(described_class.new(diff_msgs).to_a).to eq(expected_diffs)
    end
  end
end