1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Projects::LfsPointers::LfsImportService, feature_category: :source_code_management do
let(:project) { create(:project) }
let(:user) { project.creator }
let(:import_url) { 'http://www.gitlab.com/demo/repo.git' }
let(:oid_download_links) do
[
{ 'oid1' => "#{import_url}/gitlab-lfs/objects/oid1" },
{ 'oid2' => "#{import_url}/gitlab-lfs/objects/oid2" }
]
end
subject { described_class.new(project, user) }
context 'when lfs is enabled for the project' do
before do
allow(project).to receive(:lfs_enabled?).and_return(true)
end
it 'downloads lfs objects' do
service = double
expect_next_instance_of(Projects::LfsPointers::LfsObjectDownloadListService) do |instance|
expect(instance).to receive(:each_list_item)
.and_yield(oid_download_links[0]).and_yield(oid_download_links[1])
end
expect(Projects::LfsPointers::LfsDownloadService).to receive(:new).and_return(service).twice
expect(service).to receive(:execute).twice
result = subject.execute
expect(result[:status]).to eq :success
end
context 'when no downloadable lfs object links' do
it 'does not call LfsDownloadService' do
expect_next_instance_of(Projects::LfsPointers::LfsObjectDownloadListService) do |instance|
expect(instance).to receive(:each_list_item)
end
expect(Projects::LfsPointers::LfsDownloadService).not_to receive(:new)
result = subject.execute
expect(result[:status]).to eq :success
end
end
context 'when an exception is raised' do
it 'returns error' do
error_message = "error message"
expect_next_instance_of(Projects::LfsPointers::LfsObjectDownloadListService) do |instance|
expect(instance).to receive(:each_list_item).and_raise(StandardError, error_message)
end
result = subject.execute
expect(result[:status]).to eq :error
expect(result[:message]).to eq error_message
end
end
context 'when an GRPC::Core::CallError exception raised' do
it 'returns error' do
error_message = "error message"
expect_next_instance_of(Projects::LfsPointers::LfsObjectDownloadListService) do |instance|
expect(instance).to receive(:each_list_item).and_raise(GRPC::Core::CallError, error_message)
end
result = subject.execute
expect(result[:status]).to eq :error
expect(result[:message]).to eq error_message
end
end
end
context 'when lfs is not enabled for the project' do
it 'does not download lfs objects' do
allow(project).to receive(:lfs_enabled?).and_return(false)
expect(Projects::LfsPointers::LfsObjectDownloadListService).not_to receive(:new)
expect(Projects::LfsPointers::LfsDownloadService).not_to receive(:new)
result = subject.execute
expect(result[:status]).to eq :success
end
end
end
|