debian-mirror-gitlab/spec/lib/gitlab/checks/lfs_integrity_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

101 lines
2.7 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Gitlab::Checks::LfsIntegrity do
2018-03-17 18:26:18 +05:30
include ProjectForksHelper
2018-03-27 19:54:05 +05:30
2018-12-13 13:39:08 +05:30
let!(:time_left) { 50 }
2018-03-17 18:26:18 +05:30
let(:project) { create(:project, :repository) }
2018-03-27 19:54:05 +05:30
let(:repository) { project.repository }
let(:newrev) do
2023-01-13 00:05:48 +05:30
newrev = repository.commit_files(
project.creator,
branch_name: 'lfs_integrity_spec',
message: 'New LFS objects',
actions: [{
action: :create,
file_path: 'files/lfs/some.iso',
content: <<~LFS
version https://git-lfs.github.com/spec/v1
oid sha256:91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897
size 1575078
LFS
}]
)
2018-03-27 19:54:05 +05:30
# Create a commit not pointed at by any ref to emulate being in the
# pre-receive hook so that `--not --all` returns some objects
2023-01-13 00:05:48 +05:30
repository.delete_branch('lfs_integrity_spec')
newrev
2018-03-27 19:54:05 +05:30
end
2018-03-17 18:26:18 +05:30
2021-09-04 01:27:46 +05:30
let(:newrevs) { [newrev] }
subject { described_class.new(project, newrevs, time_left) }
2018-03-17 18:26:18 +05:30
describe '#objects_missing?' do
2018-03-27 19:54:05 +05:30
let(:blob_object) { repository.blob_at_branch('lfs', 'files/lfs/lfs_object.iso') }
2018-03-17 18:26:18 +05:30
context 'with LFS not enabled' do
2021-09-04 01:27:46 +05:30
before do
allow(project).to receive(:lfs_enabled?).and_return(false)
end
2018-03-17 18:26:18 +05:30
it 'skips integrity check' do
2018-03-27 19:54:05 +05:30
expect_any_instance_of(Gitlab::Git::LfsChanges).not_to receive(:new_pointers)
2018-03-17 18:26:18 +05:30
subject.objects_missing?
end
end
context 'with LFS enabled' do
before do
allow(project).to receive(:lfs_enabled?).and_return(true)
end
2021-09-04 01:27:46 +05:30
context 'nil rev' do
let(:newrevs) { [nil] }
it 'skips integrity check' do
expect_any_instance_of(Gitlab::Git::LfsChanges).not_to receive(:new_pointers)
expect(subject.objects_missing?).to be_falsey
end
end
2018-03-17 18:26:18 +05:30
context 'deletion' do
2021-09-04 01:27:46 +05:30
let(:newrevs) { [Gitlab::Git::BLANK_SHA] }
it 'skips integrity check' do
expect_any_instance_of(Gitlab::Git::LfsChanges).not_to receive(:new_pointers)
expect(subject.objects_missing?).to be_falsey
end
end
context 'no changes' do
let(:newrevs) { [] }
2018-03-17 18:26:18 +05:30
it 'skips integrity check' do
2018-03-27 19:54:05 +05:30
expect_any_instance_of(Gitlab::Git::LfsChanges).not_to receive(:new_pointers)
2018-03-17 18:26:18 +05:30
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
end
end