2019-07-25 05:21:37 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-11-08 12:27:01 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Gitlab::Checks::LfsIntegrity do
|
2017-11-08 12:59:48 +00:00
|
|
|
include ProjectForksHelper
|
2018-02-06 22:49:33 +00:00
|
|
|
|
2018-10-22 14:49:20 +00:00
|
|
|
let!(:time_left) { 50 }
|
2017-11-08 12:27:01 +00:00
|
|
|
let(:project) { create(:project, :repository) }
|
2018-02-06 22:49:33 +00:00
|
|
|
let(:repository) { project.repository }
|
|
|
|
let(:newrev) do
|
2018-06-01 11:56:29 +00:00
|
|
|
operations = Gitlab::GitalyClient::StorageSettings.allow_disk_access do
|
|
|
|
BareRepoOperations.new(repository.path)
|
|
|
|
end
|
2018-02-06 22:49:33 +00:00
|
|
|
|
|
|
|
# Create a commit not pointed at by any ref to emulate being in the
|
|
|
|
# pre-receive hook so that `--not --all` returns some objects
|
|
|
|
operations.commit_tree('8856a329dd38ca86dfb9ce5aa58a16d88cc119bd', "New LFS objects")
|
|
|
|
end
|
2017-11-08 12:27:01 +00:00
|
|
|
|
2018-10-22 14:49:20 +00:00
|
|
|
subject { described_class.new(project, newrev, time_left) }
|
2017-11-08 12:27:01 +00:00
|
|
|
|
|
|
|
describe '#objects_missing?' do
|
2018-02-06 22:49:33 +00:00
|
|
|
let(:blob_object) { repository.blob_at_branch('lfs', 'files/lfs/lfs_object.iso') }
|
2017-11-08 12:27:01 +00:00
|
|
|
|
|
|
|
context 'with LFS not enabled' do
|
|
|
|
it 'skips integrity check' do
|
2018-02-06 22:49:33 +00:00
|
|
|
expect_any_instance_of(Gitlab::Git::LfsChanges).not_to receive(:new_pointers)
|
2017-11-08 12:27:01 +00:00
|
|
|
|
|
|
|
subject.objects_missing?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with LFS enabled' do
|
|
|
|
before do
|
|
|
|
allow(project).to receive(:lfs_enabled?).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'deletion' do
|
|
|
|
let(:newrev) { nil }
|
|
|
|
|
|
|
|
it 'skips integrity check' do
|
2018-02-06 22:49:33 +00:00
|
|
|
expect_any_instance_of(Gitlab::Git::LfsChanges).not_to receive(:new_pointers)
|
2017-11-08 12:27:01 +00:00
|
|
|
|
|
|
|
expect(subject.objects_missing?).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is true if any LFS blobs are missing' do
|
|
|
|
expect(subject.objects_missing?).to be_truthy
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is false if LFS objects have already been uploaded' do
|
|
|
|
lfs_object = create(:lfs_object, oid: blob_object.lfs_oid)
|
|
|
|
create(:lfs_objects_project, project: project, lfs_object: lfs_object)
|
|
|
|
|
|
|
|
expect(subject.objects_missing?).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
2017-11-08 12:59:48 +00:00
|
|
|
|
2019-10-23 09:06:03 +00:00
|
|
|
context 'for forked project', :sidekiq_might_not_need_inline do
|
2017-11-08 12:59:48 +00:00
|
|
|
let(:parent_project) { create(:project, :repository) }
|
|
|
|
let(:project) { fork_project(parent_project, nil, repository: true) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(project).to receive(:lfs_enabled?).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is true parent project is missing LFS objects' do
|
|
|
|
expect(subject.objects_missing?).to be_truthy
|
|
|
|
end
|
|
|
|
|
2018-10-30 10:53:01 +00:00
|
|
|
it 'is false parent project already contains LFS objects for the fork' do
|
2017-11-08 12:59:48 +00:00
|
|
|
lfs_object = create(:lfs_object, oid: blob_object.lfs_oid)
|
|
|
|
create(:lfs_objects_project, project: parent_project, lfs_object: lfs_object)
|
|
|
|
|
|
|
|
expect(subject.objects_missing?).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
2017-11-08 12:27:01 +00:00
|
|
|
end
|
|
|
|
end
|