2019-04-15 06:17:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-07-23 10:33:06 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
require Rails.root.join('config', 'object_store_settings.rb')
|
|
|
|
|
2020-06-03 23:08:05 -04:00
|
|
|
RSpec.describe ObjectStoreSettings do
|
2020-06-17 11:08:36 -04:00
|
|
|
describe '#parse!' do
|
|
|
|
let(:settings) { Settingslogic.new(config) }
|
|
|
|
|
|
|
|
subject { described_class.new(settings).parse! }
|
|
|
|
|
|
|
|
context 'with valid config' do
|
|
|
|
let(:connection) do
|
|
|
|
{
|
|
|
|
'provider' => 'AWS',
|
|
|
|
'aws_access_key_id' => 'AWS_ACCESS_KEY_ID',
|
|
|
|
'aws_secret_access_key' => 'AWS_SECRET_ACCESS_KEY',
|
|
|
|
'region' => 'us-east-1'
|
|
|
|
}
|
|
|
|
end
|
2020-08-10 23:11:00 -04:00
|
|
|
|
2020-06-17 11:08:36 -04:00
|
|
|
let(:config) do
|
|
|
|
{
|
|
|
|
'lfs' => { 'enabled' => true },
|
|
|
|
'artifacts' => { 'enabled' => true },
|
|
|
|
'external_diffs' => { 'enabled' => false },
|
|
|
|
'object_store' => {
|
|
|
|
'enabled' => true,
|
|
|
|
'connection' => connection,
|
|
|
|
'proxy_download' => true,
|
|
|
|
'objects' => {
|
|
|
|
'artifacts' => {
|
|
|
|
'bucket' => 'artifacts',
|
|
|
|
'proxy_download' => false
|
|
|
|
},
|
|
|
|
'lfs' => {
|
|
|
|
'bucket' => 'lfs-objects'
|
|
|
|
},
|
|
|
|
'external_diffs' => {
|
|
|
|
'bucket' => 'external_diffs',
|
|
|
|
'enabled' => false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sets correct default values' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(settings.artifacts['enabled']).to be true
|
|
|
|
expect(settings.artifacts['object_store']['enabled']).to be true
|
|
|
|
expect(settings.artifacts['object_store']['connection']).to eq(connection)
|
|
|
|
expect(settings.artifacts['object_store']['direct_upload']).to be true
|
|
|
|
expect(settings.artifacts['object_store']['background_upload']).to be false
|
|
|
|
expect(settings.artifacts['object_store']['proxy_download']).to be false
|
|
|
|
expect(settings.artifacts['object_store']['remote_directory']).to eq('artifacts')
|
|
|
|
|
|
|
|
expect(settings.lfs['enabled']).to be true
|
|
|
|
expect(settings.lfs['object_store']['enabled']).to be true
|
|
|
|
expect(settings.lfs['object_store']['connection']).to eq(connection)
|
|
|
|
expect(settings.lfs['object_store']['direct_upload']).to be true
|
|
|
|
expect(settings.lfs['object_store']['background_upload']).to be false
|
|
|
|
expect(settings.lfs['object_store']['proxy_download']).to be true
|
|
|
|
expect(settings.lfs['object_store']['remote_directory']).to eq('lfs-objects')
|
|
|
|
|
|
|
|
expect(settings.external_diffs['enabled']).to be false
|
|
|
|
expect(settings.external_diffs['object_store']['enabled']).to be false
|
|
|
|
expect(settings.external_diffs['object_store']['remote_directory']).to eq('external_diffs')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'raises an error when a bucket is missing' do
|
|
|
|
config['object_store']['objects']['lfs'].delete('bucket')
|
|
|
|
|
|
|
|
expect { subject }.to raise_error(/Object storage for lfs must have a bucket specified/)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with legacy config' do
|
|
|
|
let(:legacy_settings) do
|
|
|
|
{
|
|
|
|
'enabled' => true,
|
|
|
|
'remote_directory' => 'some-bucket',
|
|
|
|
'direct_upload' => true,
|
|
|
|
'background_upload' => false,
|
|
|
|
'proxy_download' => false
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
settings.lfs['object_store'] = described_class.legacy_parse(legacy_settings)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not alter config if legacy settings are specified' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(settings.artifacts['object_store']).to be_nil
|
|
|
|
expect(settings.lfs['object_store']['remote_directory']).to eq('some-bucket')
|
|
|
|
expect(settings.external_diffs['object_store']).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.legacy_parse' do
|
2019-04-05 04:43:27 -04:00
|
|
|
it 'sets correct default values' do
|
2020-06-17 11:08:36 -04:00
|
|
|
settings = described_class.legacy_parse(nil)
|
2018-07-23 10:33:06 -04:00
|
|
|
|
|
|
|
expect(settings['enabled']).to be false
|
|
|
|
expect(settings['direct_upload']).to be false
|
|
|
|
expect(settings['background_upload']).to be true
|
|
|
|
expect(settings['remote_directory']).to be nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'respects original values' do
|
|
|
|
original_settings = Settingslogic.new({
|
|
|
|
'enabled' => true,
|
|
|
|
'remote_directory' => 'artifacts'
|
|
|
|
})
|
|
|
|
|
2020-06-17 11:08:36 -04:00
|
|
|
settings = described_class.legacy_parse(original_settings)
|
2018-07-23 10:33:06 -04:00
|
|
|
|
|
|
|
expect(settings['enabled']).to be true
|
|
|
|
expect(settings['direct_upload']).to be false
|
|
|
|
expect(settings['background_upload']).to be true
|
|
|
|
expect(settings['remote_directory']).to eq 'artifacts'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|