Commit 5c68f074 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Add specs for package_file_uploader

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent f621783f
...@@ -61,6 +61,10 @@ FactoryBot.define do ...@@ -61,6 +61,10 @@ FactoryBot.define do
file_sha1 'f572d396fae9206628714fb2ce00f72e94f2258f' file_sha1 'f572d396fae9206628714fb2ce00f72e94f2258f'
file_type 'tgz' file_type 'tgz'
end end
trait :object_storage do
file_store { Packages::PackageFileUploader::Store::REMOTE }
end
end end
factory :maven_metadatum, class: Packages::MavenMetadatum do factory :maven_metadatum, class: Packages::MavenMetadatum do
......
...@@ -34,11 +34,4 @@ describe 'gitlab:packages namespace rake task' do ...@@ -34,11 +34,4 @@ describe 'gitlab:packages namespace rake task' do
end end
end end
end end
def stub_packages_object_storage(**params)
stub_object_storage_uploader(config: Gitlab.config.packages.object_store,
uploader: ::Packages::PackageFileUploader,
remote_directory: 'packages',
**params)
end
end end
require 'spec_helper'
describe Packages::PackageFileUploader do
let(:package_file) { create(:package_file, :xml) }
let(:uploader) { described_class.new(package_file, :file) }
let(:path) { Gitlab.config.packages.storage_path }
subject { uploader }
it_behaves_like "builds correct paths",
store_dir: %r[\h{2}/\h{2}],
cache_dir: %r[/packages/tmp/cache],
work_dir: %r[/packages/tmp/work]
context 'object store is remote' do
before do
stub_packages_object_storage
end
include_context 'with storage', described_class::Store::REMOTE
it_behaves_like "builds correct paths",
store_dir: %r[\h{2}/\h{2}]
end
describe 'remote file' do
let(:package_file) { create(:package_file, :object_storage, :xml) }
context 'with object storage enabled' do
before do
stub_packages_object_storage
end
it 'can store file remotely' do
allow(ObjectStorage::BackgroundMoveWorker).to receive(:perform_async)
package_file
expect(package_file.file_store).to eq(described_class::Store::REMOTE)
expect(package_file.file.path).not_to be_blank
end
end
end
end
...@@ -72,4 +72,11 @@ module StubObjectStorage ...@@ -72,4 +72,11 @@ module StubObjectStorage
stub_object_storage(connection_params: Pseudonymizer::Uploader.object_store_credentials, stub_object_storage(connection_params: Pseudonymizer::Uploader.object_store_credentials,
remote_directory: Pseudonymizer::Uploader.remote_directory) remote_directory: Pseudonymizer::Uploader.remote_directory)
end end
def stub_packages_object_storage(**params)
stub_object_storage_uploader(config: Gitlab.config.packages.object_store,
uploader: ::Packages::PackageFileUploader,
remote_directory: 'packages',
**params)
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment