gitlab-org--gitlab-foss/spec/support/stub_object_storage.rb

49 lines
1.6 KiB
Ruby
Raw Normal View History

module StubConfiguration
2018-03-22 16:13:06 -04:00
def stub_object_storage_uploader(
2018-03-23 06:07:22 -04:00
config:,
uploader:,
remote_directory:,
2018-03-22 16:13:06 -04:00
enabled: true,
proxy_download: false,
2018-03-23 06:07:22 -04:00
background_upload: false,
direct_upload: false
)
allow(config).to receive(:enabled) { enabled }
2018-03-22 14:37:47 -04:00
allow(config).to receive(:proxy_download) { proxy_download }
allow(config).to receive(:background_upload) { background_upload }
2018-03-23 06:07:22 -04:00
allow(config).to receive(:direct_upload) { direct_upload }
return unless enabled
2018-03-23 06:07:22 -04:00
Fog.mock!
::Fog::Storage.new(uploader.object_store_credentials).tap do |connection|
begin
connection.directories.create(key: remote_directory)
rescue Excon::Error::Conflict
end
end
end
def stub_artifacts_object_storage(**params)
stub_object_storage_uploader(config: Gitlab.config.artifacts.object_store,
uploader: JobArtifactUploader,
remote_directory: 'artifacts',
**params)
end
def stub_lfs_object_storage(**params)
stub_object_storage_uploader(config: Gitlab.config.lfs.object_store,
uploader: LfsObjectUploader,
remote_directory: 'lfs-objects',
**params)
end
def stub_uploads_object_storage(uploader = described_class, **params)
stub_object_storage_uploader(config: Gitlab.config.uploads.object_store,
uploader: uploader,
remote_directory: 'uploads',
**params)
end
end