diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/lib/gitlab/checks/lfs_integrity_spec.rb | 17 | ||||
-rw-r--r-- | spec/lib/gitlab/git/blob_spec.rb | 61 |
2 files changed, 66 insertions, 12 deletions
diff --git a/spec/lib/gitlab/checks/lfs_integrity_spec.rb b/spec/lib/gitlab/checks/lfs_integrity_spec.rb index ec22e3a198e..9b6524b518c 100644 --- a/spec/lib/gitlab/checks/lfs_integrity_spec.rb +++ b/spec/lib/gitlab/checks/lfs_integrity_spec.rb @@ -5,24 +5,17 @@ describe Gitlab::Checks::LfsIntegrity do let(:project) { create(:project, :repository) } let(:repository) { project.repository } - let(:newrev) do - operations = Gitlab::GitalyClient::StorageSettings.allow_disk_access do - BareRepoOperations.new(repository.path) - end - - # 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 + let(:oldrev) { Gitlab::Git::EMPTY_TREE_ID } + let(:newrev) { TestEnv::BRANCH_SHA['lfs'] } - subject { described_class.new(project, newrev) } + subject { described_class.new(project, oldrev, newrev) } describe '#objects_missing?' do let(:blob_object) { repository.blob_at_branch('lfs', 'files/lfs/lfs_object.iso') } context 'with LFS not enabled' do it 'skips integrity check' do - expect_any_instance_of(Gitlab::Git::LfsChanges).not_to receive(:new_pointers) + expect(Gitlab::Git::Blob).not_to receive(:lfs_pointers_between) subject.objects_missing? end @@ -37,7 +30,7 @@ describe Gitlab::Checks::LfsIntegrity do let(:newrev) { nil } it 'skips integrity check' do - expect_any_instance_of(Gitlab::Git::LfsChanges).not_to receive(:new_pointers) + expect(Gitlab::Git::Blob).not_to receive(:lfs_pointers_between) expect(subject.objects_missing?).to be_falsey end diff --git a/spec/lib/gitlab/git/blob_spec.rb b/spec/lib/gitlab/git/blob_spec.rb index 94eaf86ef80..796dabf7d0e 100644 --- a/spec/lib/gitlab/git/blob_spec.rb +++ b/spec/lib/gitlab/git/blob_spec.rb @@ -277,6 +277,67 @@ describe Gitlab::Git::Blob, seed_helper: true do end end + describe '.lfs_pointers_between' do + let(:repository) { create(:project, :repository).repository } + let(:old_rev) { Gitlab::Git::EMPTY_TREE_ID } + let(:lfs_rev) { TestEnv::BRANCH_SHA['lfs'] } + let(:non_lfs_rev) { TestEnv::BRANCH_SHA['feature'] } + + context 'with LFS objects' do + it 'returns a list of Gitlab::Git::Blob' do + blobs = described_class.lfs_pointers_between(repository, old_rev, lfs_rev) + + expect(blobs.count).to eq(1) + expect(blobs).to all( be_a(Gitlab::Git::Blob) ) + expect(blobs).to be_an(Array) + end + + context 'when changes consist of a single LFS pointer' do + let(:parent_commit) { '5f923865dde3436854e9ceb9cdb7815618d4e849' } + let(:commit_with_lfs_pointer) { '048721d90c449b244b7b4c53a9186b04330174ec' } + + it 'returns the single LFS pointer found' do + blobs = described_class.lfs_pointers_between(repository, parent_commit, commit_with_lfs_pointer) + + expect(blobs.count).to eq(1) + expect(blobs).to all( be_a(Gitlab::Git::Blob) ) + end + end + end + + context 'without LFS objects' do + it 'returns an empty Array' do + blobs = described_class.lfs_pointers_between(repository, old_rev, non_lfs_rev) + + expect(blobs).to eq([]) + end + end + end + + describe '.lfs_pointers_from_tree' do + let(:repository) { create(:project, :repository).repository } + let(:tree_with_lfs_objects) { repository.tree('lfs', 'files/lfs') } + let(:tree_without_lfs_objects) { repository.tree('feature', '/') } + + context 'with a tree with LFS objects' do + it 'returns a list of Gitlab::Git::Blob' do + blobs = described_class.lfs_pointers_from_tree(repository, tree_with_lfs_objects) + + expect(blobs.count).to eq(1) + expect(blobs).to all( be_a(Gitlab::Git::Blob) ) + expect(blobs).to be_an(Array) + end + end + + context 'with a tree without LFS objects' do + it 'returns an empty Array' do + blobs = described_class.lfs_pointers_from_tree(repository, tree_without_lfs_objects) + + expect(blobs).to eq([]) + end + end + end + describe '.batch_lfs_pointers' do let(:tree_object) { repository.rugged.rev_parse('master^{tree}') } |