lfs_retriever_spec.rb 1.93 KB
Newer Older
1 2
# frozen_string_literal: true

3 4
require 'spec_helper'

5
RSpec.describe Gitlab::Geo::Replication::LfsRetriever, :geo do
Ryan Cobb's avatar
Ryan Cobb committed
6
  describe '#execute' do
7
    subject { retriever.execute }
8 9

    context 'when the LFS object exists' do
10
      let(:retriever) { described_class.new(lfs_object.id, extra_params) }
11 12 13 14 15 16 17

      before do
        expect(LfsObject).to receive(:find_by).with(id: lfs_object.id).and_return(lfs_object)
      end

      context 'when the LFS object has a file' do
        let(:lfs_object) { create(:lfs_object, :with_file) }
18
        let(:extra_params) { { checksum: lfs_object.oid } }
19

20
        context 'when the extra_params checksum matches the LFS object oid' do
21 22 23 24 25
          it 'returns the file in a success hash' do
            expect(subject).to eq(code: :ok, message: 'Success', file: lfs_object.file)
          end
        end

26 27
        context 'when the extra_params checksum does not match the LFS object oid' do
          let(:extra_params) { { checksum: 'foo' } }
28 29

          it 'returns an error hash' do
30
            expect(subject).to include(code: :not_found, message: 'LFS object not found')
31 32 33 34 35 36
          end
        end
      end

      context 'when the LFS object does not have a file' do
        let(:lfs_object) { create(:lfs_object) }
37
        let(:extra_params) { { checksum: lfs_object.oid } }
38 39 40 41 42 43

        it 'returns an error hash' do
          expect(subject).to include(code: :not_found, geo_code: 'FILE_NOT_FOUND', message: match(/LfsObject #\d+ file not found/))
        end

        it 'logs the missing file' do
44
          expect(retriever).to receive(:log_error).with('Could not upload LFS object because it does not have a file', id: lfs_object.id)
45 46 47 48 49 50 51

          subject
        end
      end
    end

    context 'when the LFS object does not exist' do
52
      let(:retriever) { described_class.new(10000, {}) }
53 54 55 56 57 58 59

      it 'returns an error hash' do
        expect(subject).to eq(code: :not_found, message: 'LFS object not found')
      end
    end
  end
end