2019-08-22 06:57:44 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-05 06:16:17 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe Gitlab::Verify::LfsObjects do
|
2018-03-05 06:16:17 -05:00
|
|
|
include GitlabVerifyHelpers
|
|
|
|
|
|
|
|
it_behaves_like 'Gitlab::Verify::BatchVerifier subclass' do
|
|
|
|
let!(:objects) { create_list(:lfs_object, 3, :with_file) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#run_batches' do
|
|
|
|
let(:failures) { collect_failures }
|
|
|
|
let(:failure) { failures[lfs_object] }
|
|
|
|
|
|
|
|
let!(:lfs_object) { create(:lfs_object, :with_file, :correct_oid) }
|
|
|
|
|
|
|
|
it 'passes LFS objects with the correct file' do
|
|
|
|
expect(failures).to eq({})
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'fails LFS objects with a missing file' do
|
|
|
|
FileUtils.rm_f(lfs_object.file.path)
|
|
|
|
|
|
|
|
expect(failures.keys).to contain_exactly(lfs_object)
|
2018-06-13 13:11:43 -04:00
|
|
|
expect(failure).to include('No such file or directory')
|
|
|
|
expect(failure).to include(lfs_object.file.path)
|
2018-03-05 06:16:17 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'fails LFS objects with a mismatched oid' do
|
|
|
|
File.truncate(lfs_object.file.path, 0)
|
|
|
|
|
|
|
|
expect(failures.keys).to contain_exactly(lfs_object)
|
2018-06-13 13:11:43 -04:00
|
|
|
expect(failure).to include('Checksum mismatch')
|
2018-03-05 06:16:17 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with remote files' do
|
2018-06-13 13:11:43 -04:00
|
|
|
let(:file) { double(:file) }
|
|
|
|
|
2018-03-05 06:16:17 -05:00
|
|
|
before do
|
|
|
|
stub_lfs_object_storage
|
2018-06-13 13:11:43 -04:00
|
|
|
lfs_object.update!(file_store: ObjectStorage::Store::REMOTE)
|
|
|
|
expect(CarrierWave::Storage::Fog::File).to receive(:new).and_return(file)
|
2018-03-05 06:16:17 -05:00
|
|
|
end
|
|
|
|
|
2018-06-13 13:11:43 -04:00
|
|
|
it 'passes LFS objects in object storage that exist' do
|
|
|
|
expect(file).to receive(:exists?).and_return(true)
|
|
|
|
|
|
|
|
expect(failures).to eq({})
|
|
|
|
end
|
2018-03-05 06:16:17 -05:00
|
|
|
|
2018-06-13 13:11:43 -04:00
|
|
|
it 'fails LFS objects in object storage that do not exist' do
|
|
|
|
expect(file).to receive(:exists?).and_return(false)
|
2018-03-05 06:16:17 -05:00
|
|
|
|
2018-06-13 13:11:43 -04:00
|
|
|
expect(failures.keys).to contain_exactly(lfs_object)
|
|
|
|
expect(failure).to include('Remote object does not exist')
|
2018-03-05 06:16:17 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|