lfs_integrity_spec.rb 2.4 KB
Newer Older
1 2 3
require 'spec_helper'

describe Gitlab::Checks::LfsIntegrity do
4
  include ProjectForksHelper
5

6
  let(:project) { create(:project, :repository) }
7 8
  let(:repository) { project.repository }
  let(:newrev) do
9 10 11
    operations = Gitlab::GitalyClient::StorageSettings.allow_disk_access do
      BareRepoOperations.new(repository.path)
    end
12 13 14 15 16

    # 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
17 18 19 20

  subject { described_class.new(project, newrev) }

  describe '#objects_missing?' do
21
    let(:blob_object) { repository.blob_at_branch('lfs', 'files/lfs/lfs_object.iso') }
22 23 24

    context 'with LFS not enabled' do
      it 'skips integrity check' do
25
        expect_any_instance_of(Gitlab::Git::LfsChanges).not_to receive(:new_pointers)
26 27 28 29 30 31 32 33 34 35 36 37 38 39

        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
40
          expect_any_instance_of(Gitlab::Git::LfsChanges).not_to receive(:new_pointers)
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56

          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
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76

    context 'for forked project' do
      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

      it 'is false parent project already conatins LFS objects for the fork' do
        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
77 78
  end
end