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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::Checks::ChangesAccess do
include_context 'changes access checks context'
subject { changes_access }
describe '#validate!' do
shared_examples '#validate!' do
before do
allow(project).to receive(:lfs_enabled?).and_return(true)
end
context 'without failed checks' do
it "doesn't raise an error" do
expect { subject.validate! }.not_to raise_error
end
it 'calls lfs checks' do
expect_next_instance_of(Gitlab::Checks::LfsCheck) do |instance|
expect(instance).to receive(:validate!)
end
subject.validate!
end
end
context 'when time limit was reached' do
it 'raises a TimeoutError' do
logger = Gitlab::Checks::TimedLogger.new(start_time: timeout.ago, timeout: timeout)
access = described_class.new(changes,
project: project,
user_access: user_access,
protocol: protocol,
logger: logger)
expect { access.validate! }.to raise_error(Gitlab::Checks::TimedLogger::TimeoutError)
end
end
end
context 'with batched commits enabled' do
before do
stub_feature_flags(changes_batch_commits: true)
end
it_behaves_like '#validate!'
end
context 'with batched commits disabled' do
before do
stub_feature_flags(changes_batch_commits: false)
end
it_behaves_like '#validate!'
end
end
describe '#commits' do
it 'calls #new_commits' do
expect(project.repository).to receive(:new_commits).and_return([])
expect(subject.commits).to eq([])
end
context 'when changes contain empty revisions' do
let(:changes) { [{ newrev: newrev }, { newrev: '' }, { newrev: Gitlab::Git::BLANK_SHA }] }
let(:expected_commit) { instance_double(Commit) }
it 'returns only commits with non empty revisions' do
expect(project.repository).to receive(:new_commits).with([newrev], { allow_quarantine: true }) { [expected_commit] }
expect(subject.commits).to eq([expected_commit])
end
end
end
describe '#commits_for' do
let(:new_commits) { [] }
let(:expected_commits) { [] }
shared_examples 'a listing of new commits' do
it 'returns expected commits' do
expect(subject).to receive(:commits).and_return(new_commits)
expect(subject.commits_for(newrev)).to eq(expected_commits)
end
end
context 'with no commits' do
it_behaves_like 'a listing of new commits'
end
context 'with unrelated commits' do
let(:new_commits) { [create_commit('1234', %w[1111 2222])] }
it_behaves_like 'a listing of new commits'
end
context 'with single related commit' do
let(:new_commits) { [create_commit(newrev, %w[1111 2222])] }
let(:expected_commits) { new_commits }
it_behaves_like 'a listing of new commits'
end
context 'with single related and unrelated commit' do
let(:new_commits) do
[
create_commit(newrev, %w[1111 2222]),
create_commit('abcd', %w[1111 2222])
]
end
let(:expected_commits) do
[create_commit(newrev, %w[1111 2222])]
end
it_behaves_like 'a listing of new commits'
end
context 'with multiple related commits' do
let(:new_commits) do
[
create_commit(newrev, %w[1111]),
create_commit('1111', %w[2222]),
create_commit('abcd', [])
]
end
let(:expected_commits) do
[
create_commit(newrev, %w[1111]),
create_commit('1111', %w[2222])
]
end
it_behaves_like 'a listing of new commits'
end
context 'with merge commits' do
let(:new_commits) do
[
create_commit(newrev, %w[1111 2222 3333]),
create_commit('1111', []),
create_commit('3333', %w[4444]),
create_commit('4444', [])
]
end
let(:expected_commits) do
[
create_commit(newrev, %w[1111 2222 3333]),
create_commit('1111', []),
create_commit('3333', %w[4444]),
create_commit('4444', [])
]
end
it_behaves_like 'a listing of new commits'
end
end
def create_commit(id, parent_ids)
Gitlab::Git::Commit.new(project.repository, {
id: id,
parent_ids: parent_ids
})
end
end
|