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