2019-07-31 22:56:46 +05:30
|
|
|
# frozen_string_literal: true
|
2018-11-08 19:23:39 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Projects::LfsPointers::LfsImportService do
|
2019-07-31 22:56:46 +05:30
|
|
|
let(:project) { create(:project) }
|
|
|
|
let(:user) { project.creator }
|
2018-11-08 19:23:39 +05:30
|
|
|
let(:import_url) { 'http://www.gitlab.com/demo/repo.git' }
|
|
|
|
let(:oid_download_links) { { 'oid1' => "#{import_url}/gitlab-lfs/objects/oid1", 'oid2' => "#{import_url}/gitlab-lfs/objects/oid2" } }
|
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
subject { described_class.new(project, user) }
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
context 'when lfs is enabled for the project' do
|
|
|
|
before do
|
|
|
|
allow(project).to receive(:lfs_enabled?).and_return(true)
|
2018-11-08 19:23:39 +05:30
|
|
|
end
|
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
it 'downloads lfs objects' do
|
|
|
|
service = double
|
|
|
|
expect_any_instance_of(Projects::LfsPointers::LfsObjectDownloadListService).to receive(:execute).and_return(oid_download_links)
|
|
|
|
expect(Projects::LfsPointers::LfsDownloadService).to receive(:new).and_return(service).twice
|
|
|
|
expect(service).to receive(:execute).twice
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
result = subject.execute
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
expect(result[:status]).to eq :success
|
2018-11-08 19:23:39 +05:30
|
|
|
end
|
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
context 'when no downloadable lfs object links' do
|
|
|
|
it 'does not call LfsDownloadService' do
|
|
|
|
expect_any_instance_of(Projects::LfsPointers::LfsObjectDownloadListService).to receive(:execute).and_return({})
|
|
|
|
expect(Projects::LfsPointers::LfsDownloadService).not_to receive(:new)
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
result = subject.execute
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
expect(result[:status]).to eq :success
|
2018-11-08 19:23:39 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
context 'when an exception is raised' do
|
|
|
|
it 'returns error' do
|
|
|
|
error_message = "error message"
|
|
|
|
expect_any_instance_of(Projects::LfsPointers::LfsObjectDownloadListService).to receive(:execute).and_raise(StandardError, error_message)
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
result = subject.execute
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
expect(result[:status]).to eq :error
|
|
|
|
expect(result[:message]).to eq error_message
|
2018-11-08 19:23:39 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
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
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
expect(result[:status]).to eq :success
|
2018-11-08 19:23:39 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|