blob: 1a4e5c626a45fb5000faed1d81697e4b5afe7bb8 (
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
|
require 'spec_helper'
describe Gitlab::Verify::Uploads do
include GitlabVerifyHelpers
it_behaves_like 'Gitlab::Verify::BatchVerifier subclass' do
let(:projects) { create_list(:project, 3, :with_avatar) }
let!(:objects) { projects.flat_map(&:uploads) }
end
describe '#run_batches' do
let(:project) { create(:project, :with_avatar) }
let(:failures) { collect_failures }
let(:failure) { failures[upload] }
let!(:upload) { project.uploads.first }
it 'passes uploads with the correct file' do
expect(failures).to eq({})
end
it 'fails uploads with a missing file' do
FileUtils.rm_f(upload.absolute_path)
expect(failures.keys).to contain_exactly(upload)
expect(failure).to be_a(Errno::ENOENT)
expect(failure.to_s).to include(upload.absolute_path)
end
it 'fails uploads with a mismatched checksum' do
upload.update!(checksum: 'something incorrect')
expect(failures.keys).to contain_exactly(upload)
expect(failure.to_s).to include('Checksum mismatch')
end
it 'fails uploads with a missing precalculated checksum' do
upload.update!(checksum: '')
expect(failures.keys).to contain_exactly(upload)
expect(failure.to_s).to include('Checksum missing')
end
context 'with remote files' do
before do
stub_uploads_object_storage(AvatarUploader)
upload.update!(store: ObjectStorage::Store::REMOTE)
end
it 'passes uploads in object storage that exist' do
expect_any_instance_of(AvatarUploader).to receive(:exists?).and_return(true)
expect(failures).to eq({})
end
it 'fails uploads in object storage that do not exist' do
expect_any_instance_of(AvatarUploader).to receive(:exists?).and_return(false)
expect(failures.keys).to contain_exactly(upload)
expect(failure.to_s).to include('Remote object does not exist')
end
end
end
end
|