2017-09-07 17:27:04 -04:00
|
|
|
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
|
|
|
|
)
|
2017-09-07 17:27:04 -04:00
|
|
|
allow(config).to receive(:enabled) { enabled }
|
2018-03-22 14:37:47 -04:00
|
|
|
allow(config).to receive(:proxy_download) { proxy_download }
|
2017-12-08 04:09:06 -05:00
|
|
|
allow(config).to receive(:background_upload) { background_upload }
|
2018-03-23 06:07:22 -04:00
|
|
|
allow(config).to receive(:direct_upload) { direct_upload }
|
2017-09-07 17:27:04 -04:00
|
|
|
|
|
|
|
return unless enabled
|
|
|
|
|
2018-03-23 06:07:22 -04:00
|
|
|
Fog.mock!
|
|
|
|
|
2017-09-07 17:27:04 -04: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 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
|