diff options
Diffstat (limited to 'spec/lib/gitlab/cleanup')
-rw-r--r-- | spec/lib/gitlab/cleanup/orphan_lfs_file_references_spec.rb | 53 |
1 files changed, 49 insertions, 4 deletions
diff --git a/spec/lib/gitlab/cleanup/orphan_lfs_file_references_spec.rb b/spec/lib/gitlab/cleanup/orphan_lfs_file_references_spec.rb index 47b2cf5dc4a..efdfc0a980b 100644 --- a/spec/lib/gitlab/cleanup/orphan_lfs_file_references_spec.rb +++ b/spec/lib/gitlab/cleanup/orphan_lfs_file_references_spec.rb @@ -3,12 +3,16 @@ require 'spec_helper' RSpec.describe Gitlab::Cleanup::OrphanLfsFileReferences do + include ProjectForksHelper + let(:null_logger) { Logger.new('/dev/null') } let(:project) { create(:project, :repository, lfs_enabled: true) } let(:lfs_object) { create(:lfs_object) } let!(:invalid_reference) { create(:lfs_objects_project, project: project, lfs_object: lfs_object) } + subject(:service) { described_class.new(project, logger: null_logger, dry_run: dry_run) } + before do allow(null_logger).to receive(:info) @@ -21,25 +25,66 @@ RSpec.describe Gitlab::Cleanup::OrphanLfsFileReferences do end context 'dry run' do + let(:dry_run) { true } + it 'prints messages and does not delete references' do expect(null_logger).to receive(:info).with("[DRY RUN] Looking for orphan LFS files for project #{project.name_with_namespace}") expect(null_logger).to receive(:info).with("[DRY RUN] Found invalid references: 1") - expect { described_class.new(project, logger: null_logger).run! } - .not_to change { project.lfs_objects.count } + expect { service.run! }.not_to change { project.lfs_objects.count } end end context 'regular run' do + let(:dry_run) { false } + it 'prints messages and deletes invalid reference' do expect(null_logger).to receive(:info).with("Looking for orphan LFS files for project #{project.name_with_namespace}") expect(null_logger).to receive(:info).with("Removed invalid references: 1") expect(ProjectCacheWorker).to receive(:perform_async).with(project.id, [], [:lfs_objects_size]) - expect { described_class.new(project, logger: null_logger, dry_run: false).run! } - .to change { project.lfs_objects.count }.from(2).to(1) + expect { service.run! }.to change { project.lfs_objects.count }.from(2).to(1) expect(LfsObjectsProject.exists?(invalid_reference.id)).to be_falsey end + + context 'LFS object is in design repository' do + before do + expect(project.design_repository).to receive(:exists?).and_return(true) + + stub_lfs_pointers(project.design_repository, lfs_object.oid) + end + + it 'is not removed' do + expect { service.run! }.not_to change { project.lfs_objects.count } + end + end + + context 'LFS object is in wiki repository' do + before do + expect(project.wiki.repository).to receive(:exists?).and_return(true) + + stub_lfs_pointers(project.wiki.repository, lfs_object.oid) + end + + it 'is not removed' do + expect { service.run! }.not_to change { project.lfs_objects.count } + end + end + end + + context 'LFS for project snippets' do + let(:snippet) { create(:project_snippet) } + + it 'is disabled' do + # Support project snippets here before enabling LFS for them + expect(snippet.repository.lfs_enabled?).to be_falsy + end + end + + def stub_lfs_pointers(repo, *oids) + expect(repo.gitaly_blob_client) + .to receive(:get_all_lfs_pointers) + .and_return(oids.map { |oid| OpenStruct.new(lfs_oid: oid) }) end end |