2017-09-07 21:27:04 +00:00
|
|
|
module StubConfiguration
|
2018-03-22 20:13:06 +00:00
|
|
|
def stub_object_storage_uploader(
|
2018-03-23 10:07:22 +00:00
|
|
|
config:,
|
|
|
|
uploader:,
|
|
|
|
remote_directory:,
|
2018-03-22 20:13:06 +00:00
|
|
|
enabled: true,
|
|
|
|
proxy_download: false,
|
2018-03-23 10:07:22 +00:00
|
|
|
background_upload: false,
|
|
|
|
direct_upload: false
|
|
|
|
)
|
2017-09-07 21:27:04 +00:00
|
|
|
allow(config).to receive(:enabled) { enabled }
|
2018-03-22 18:37:47 +00:00
|
|
|
allow(config).to receive(:proxy_download) { proxy_download }
|
2017-12-08 09:09:06 +00:00
|
|
|
allow(config).to receive(:background_upload) { background_upload }
|
2018-03-23 10:07:22 +00:00
|
|
|
allow(config).to receive(:direct_upload) { direct_upload }
|
2017-09-07 21:27:04 +00:00
|
|
|
|
|
|
|
return unless enabled
|
|
|
|
|
2018-03-23 10:07:22 +00:00
|
|
|
Fog.mock!
|
|
|
|
|
2017-09-07 21:27:04 +00:00
|
|
|
::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,
|
2017-12-05 14:31:33 +00:00
|
|
|
uploader: JobArtifactUploader,
|
2017-09-07 21:27:04 +00:00
|
|
|
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
|
2018-02-02 13:59:43 +00:00
|
|
|
|
|
|
|
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
|
2017-09-07 21:27:04 +00:00
|
|
|
end
|