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

analysis_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: c57d9b9592c818d9e6cb70949511a476acd356f5 (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::GitalyClient::AnalysisService, feature_category: :gitaly do
  let_it_be(:project) do
    create(:project, :repository)
  end

  let(:repository) { project.repository.raw }
  let(:base) { project.default_branch }
  let(:head) { branch }
  let(:branch) { 'test-check-blobs-generated' }

  let(:client) { described_class.new(repository) }

  describe '#check_blobs_generated' do
    subject(:check_blobs_generated) { client.check_blobs_generated(base, head, changed_paths) }

    before do
      project.repository.create_branch(branch, project.default_branch)

      project.repository.create_file(
        project.creator,
        'file1.txt',
        'new file content',
        message: 'Add new file',
        branch_name: branch)

      project.repository.create_file(
        project.creator,
        'package-lock.json',
        'new file content',
        message: 'Add new file',
        branch_name: branch)

      project.repository.delete_file(
        project.creator,
        'README',
        message: 'Delete README',
        branch_name: branch)
    end

    context 'when valid changed_paths are given' do
      let(:changed_paths) do
        [
          Gitlab::Git::ChangedPath.new(status: :DELETED, path: 'README', old_mode: '100644', new_mode: '0'),
          Gitlab::Git::ChangedPath.new(status: :ADDED, path: 'file1.txt', old_mode: '0', new_mode: '100644'),
          Gitlab::Git::ChangedPath.new(status: :ADDED, path: 'package-lock.json', old_mode: '0', new_mode: '100644')
        ]
      end

      it 'returns an expected array' do
        expect(check_blobs_generated).to contain_exactly(
          { generated: false, path: 'README' },
          { generated: false, path: 'file1.txt' },
          { generated: true, path: 'package-lock.json' }
        )
      end

      context 'when changed_paths includes a submodule' do
        let(:changed_paths) do
          [
            Gitlab::Git::ChangedPath.new(status: :ADDED, path: 'package-lock.json', old_mode: '0', new_mode: '100644'),
            Gitlab::Git::ChangedPath.new(status: :DELETED, path: 'gitlab-shell', old_mode: '160000', new_mode: '0')
          ]
        end

        it 'returns an array wihout the submodule change' do
          expect(check_blobs_generated).to contain_exactly(
            { generated: true, path: 'package-lock.json' }
          )
        end
      end

      context 'when changed_paths only has a submodule' do
        let(:changed_paths) do
          [
            Gitlab::Git::ChangedPath.new(status: :ADDED, path: 'gitlab-shell', old_mode: '0', new_mode: '160000')
          ]
        end

        it 'returns an empty array' do
          expect(check_blobs_generated).to eq([])
        end
      end
    end

    context 'when changed_paths includes a path with :' do
      before do
        project.repository.create_file(
          project.creator,
          'abc:def',
          'new file content',
          message: 'Add new file',
          branch_name: branch)
      end

      let(:changed_paths) do
        [
          Gitlab::Git::ChangedPath.new(status: :ADDED, path: 'abc:def', old_mode: '0', new_mode: '100644')
        ]
      end

      it 'returns an expected array' do
        expect(check_blobs_generated).to contain_exactly(
          { generated: false, path: 'abc:def' }
        )
      end
    end

    context 'when an unknown revision is given' do
      let(:head)  { 'unknownrevision' }
      let(:changed_paths) do
        [
          Gitlab::Git::ChangedPath.new(status: :ADDED, path: 'file1.txt', old_mode: '0', new_mode: '100644')
        ]
      end

      it 'raises an error' do
        expect { check_blobs_generated }.to raise_error(GRPC::Internal)
      end
    end

    context 'when an unknown path is given' do
      let(:changed_paths) do
        [
          Gitlab::Git::ChangedPath.new(status: :ADDED, path: 'unknownpath', old_mode: '0', new_mode: '100644')
        ]
      end

      it 'raises an error' do
        expect { check_blobs_generated }.to raise_error(GRPC::Internal)
      end
    end
  end
end