diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-03-14 15:08:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-03-14 15:08:06 +0300 |
commit | 363a1ea13879c755f9cd8018763d3a7bdf4bf1c7 (patch) | |
tree | 9e96d749ebb984b6650e28e79bb4a87ccf77d998 /spec/uploaders | |
parent | 6f9218ac84f0de0ebfddf2d4fbd79db881b2d46a (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/uploaders')
-rw-r--r-- | spec/uploaders/gitlab_uploader_spec.rb | 17 | ||||
-rw-r--r-- | spec/uploaders/object_storage/cdn_spec.rb | 88 | ||||
-rw-r--r-- | spec/uploaders/object_storage_spec.rb | 2 |
3 files changed, 60 insertions, 47 deletions
diff --git a/spec/uploaders/gitlab_uploader_spec.rb b/spec/uploaders/gitlab_uploader_spec.rb index f62ab726631..bd86f1fe08a 100644 --- a/spec/uploaders/gitlab_uploader_spec.rb +++ b/spec/uploaders/gitlab_uploader_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require 'carrierwave/storage/fog' -RSpec.describe GitlabUploader do +RSpec.describe GitlabUploader, feature_category: :shared do let(:uploader_class) { Class.new(described_class) } subject(:uploader) { uploader_class.new(double) } @@ -179,4 +179,19 @@ RSpec.describe GitlabUploader do it { expect { subject }.to raise_error(RuntimeError, /not supported/) } end + + describe '.storage_location' do + it 'sets the identifier for the storage location options' do + uploader_class.storage_location(:artifacts) + + expect(uploader_class.options).to eq(Gitlab.config.artifacts) + end + + context 'when given identifier is not known' do + it 'raises an error' do + expect { uploader_class.storage_location(:foo) } + .to raise_error(KeyError) + end + end + end end diff --git a/spec/uploaders/object_storage/cdn_spec.rb b/spec/uploaders/object_storage/cdn_spec.rb index d6c638297fa..0c1966b4df2 100644 --- a/spec/uploaders/object_storage/cdn_spec.rb +++ b/spec/uploaders/object_storage/cdn_spec.rb @@ -3,19 +3,6 @@ require 'spec_helper' RSpec.describe ObjectStorage::CDN, feature_category: :build_artifacts do - let(:cdn_options) do - { - 'object_store' => { - 'cdn' => { - 'provider' => 'google', - 'url' => 'https://gitlab.example.com', - 'key_name' => 'test-key', - 'key' => Base64.urlsafe_encode64('12345') - } - } - }.freeze - end - let(:uploader_class) do Class.new(GitlabUploader) do include ObjectStorage::Concern @@ -39,44 +26,66 @@ RSpec.describe ObjectStorage::CDN, feature_category: :build_artifacts do subject { uploader_class.new(object, :file) } context 'with CDN config' do + let(:cdn_options) do + { + 'object_store' => { + 'cdn' => { + 'provider' => cdn_provider, + 'url' => 'https://gitlab.example.com', + 'key_name' => 'test-key', + 'key' => Base64.urlsafe_encode64('12345') + } + } + }.freeze + end + before do stub_artifacts_object_storage(enabled: true) - uploader_class.options = Settingslogic.new(Gitlab.config.uploads.deep_merge(cdn_options)) + options = Settingslogic.new(Gitlab.config.uploads.deep_merge(cdn_options)) + allow(uploader_class).to receive(:options).and_return(options) end - describe '#cdn_enabled_url' do - it 'calls #cdn_signed_url' do - expect(subject).not_to receive(:url) - expect(subject).to receive(:cdn_signed_url).with(query_params).and_call_original + context 'with a known CDN provider' do + let(:cdn_provider) { 'google' } - result = subject.cdn_enabled_url(public_ip, query_params) + describe '#cdn_enabled_url' do + it 'calls #cdn_signed_url' do + expect(subject).not_to receive(:url) + expect(subject).to receive(:cdn_signed_url).with(query_params).and_call_original + + result = subject.cdn_enabled_url(public_ip, query_params) - expect(result.used_cdn).to be true + expect(result.used_cdn).to be true + end end - end - describe '#use_cdn?' do - it 'returns true' do - expect(subject.use_cdn?(public_ip)).to be true + describe '#use_cdn?' do + it 'returns true' do + expect(subject.use_cdn?(public_ip)).to be true + end end - end - describe '#cdn_signed_url' do - it 'returns a URL' do - expect_next_instance_of(ObjectStorage::CDN::GoogleCDN) do |cdn| - expect(cdn).to receive(:signed_url).and_return("https://cdn.example.com/path") + describe '#cdn_signed_url' do + it 'returns a URL' do + expect_next_instance_of(ObjectStorage::CDN::GoogleCDN) do |cdn| + expect(cdn).to receive(:signed_url).and_return("https://cdn.example.com/path") + end + + expect(subject.cdn_signed_url).to eq("https://cdn.example.com/path") end + end + end + + context 'with an unknown CDN provider' do + let(:cdn_provider) { 'amazon' } - expect(subject.cdn_signed_url).to eq("https://cdn.example.com/path") + it 'raises an error' do + expect { subject.use_cdn?(public_ip) }.to raise_error("Unknown CDN provider: amazon") end end end context 'without CDN config' do - before do - uploader_class.options = Gitlab.config.uploads - end - describe '#cdn_enabled_url' do it 'calls #url' do expect(subject).not_to receive(:cdn_signed_url) @@ -94,15 +103,4 @@ RSpec.describe ObjectStorage::CDN, feature_category: :build_artifacts do end end end - - context 'with an unknown CDN provider' do - before do - cdn_options['object_store']['cdn']['provider'] = 'amazon' - uploader_class.options = Settingslogic.new(Gitlab.config.uploads.deep_merge(cdn_options)) - end - - it 'raises an error' do - expect { subject.use_cdn?(public_ip) }.to raise_error("Unknown CDN provider: amazon") - end - end end diff --git a/spec/uploaders/object_storage_spec.rb b/spec/uploaders/object_storage_spec.rb index 5344dbeb512..0e293ec973c 100644 --- a/spec/uploaders/object_storage_spec.rb +++ b/spec/uploaders/object_storage_spec.rb @@ -8,7 +8,7 @@ class Implementation < GitlabUploader include ::RecordsUploads::Concern prepend ::ObjectStorage::Extension::RecordsUploads - storage_options Gitlab.config.uploads + storage_location :uploads private |