diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-20 15:11:03 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-20 15:11:03 +0300 |
commit | 027f19b39c73b3b98e7cf305fead871626e8b717 (patch) | |
tree | d97ff241c76a5655f8f58444ccf76695b1b89bcf /spec/uploaders | |
parent | a7b422860c90eecd1b98845d234a8347686fbdcf (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/uploaders')
-rw-r--r-- | spec/uploaders/job_artifact_uploader_spec.rb | 8 | ||||
-rw-r--r-- | spec/uploaders/object_storage/cdn_spec.rb | 44 |
2 files changed, 44 insertions, 8 deletions
diff --git a/spec/uploaders/job_artifact_uploader_spec.rb b/spec/uploaders/job_artifact_uploader_spec.rb index 9ccf216d1fc..a7fd040837f 100644 --- a/spec/uploaders/job_artifact_uploader_spec.rb +++ b/spec/uploaders/job_artifact_uploader_spec.rb @@ -23,6 +23,14 @@ RSpec.describe JobArtifactUploader do it_behaves_like "builds correct paths", store_dir: %r[\h{2}/\h{2}/\h{64}/\d{4}_\d{1,2}_\d{1,2}/\d+/\d+\z] + + describe '#cdn_enabled_url' do + it 'returns URL and false' do + result = uploader.cdn_enabled_url(nil, '127.0.0.1') + + expect(result.used_cdn).to be false + end + end end context 'file is stored in valid local_path' do diff --git a/spec/uploaders/object_storage/cdn_spec.rb b/spec/uploaders/object_storage/cdn_spec.rb index 246cb1bf349..f99450b274f 100644 --- a/spec/uploaders/object_storage/cdn_spec.rb +++ b/spec/uploaders/object_storage/cdn_spec.rb @@ -10,7 +10,7 @@ RSpec.describe ObjectStorage::CDN do 'provider' => 'google', 'url' => 'https://gitlab.example.com', 'key_name' => 'test-key', - 'key' => '12345' + 'key' => Base64.urlsafe_encode64('12345') } } }.freeze @@ -31,21 +31,49 @@ RSpec.describe ObjectStorage::CDN do end let(:object) { build_stubbed(:user) } + let(:public_ip) { '18.245.0.1' } + + let_it_be(:project) { build(:project) } subject { uploader_class.new(object, :file) } context 'with CDN config' do before do + stub_artifacts_object_storage(enabled: true) uploader_class.options = Settingslogic.new(Gitlab.config.uploads.deep_merge(cdn_options)) end - describe '#use_cdn?' do - it 'returns true' do - expect_next_instance_of(ObjectStorage::CDN::GoogleCDN) do |cdn| - expect(cdn).to receive(:use_cdn?).and_return(true) + describe '#cdn_enabled_url' do + context 'with ci_job_artifacts_cdn feature flag disabled' do + before do + stub_feature_flags(ci_job_artifacts_cdn: false) end - expect(subject.use_cdn?('18.245.0.1')).to be true + it 'calls #url' do + expect(subject).to receive(:url).and_call_original + expect(subject).not_to receive(:cdn_signed_url) + + result = subject.cdn_enabled_url(project, public_ip) + + expect(result.used_cdn).to be false + end + end + + context 'with ci_job_artifacts_cdn feature flag enabled' do + it 'calls #cdn_signed_url' do + expect(subject).not_to receive(:url) + expect(subject).to receive(:cdn_signed_url).and_call_original + + result = subject.cdn_enabled_url(project, public_ip) + + 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 end end @@ -67,7 +95,7 @@ RSpec.describe ObjectStorage::CDN do describe '#use_cdn?' do it 'returns false' do - expect(subject.use_cdn?('18.245.0.1')).to be false + expect(subject.use_cdn?(public_ip)).to be false end end end @@ -79,7 +107,7 @@ RSpec.describe ObjectStorage::CDN do end it 'raises an error' do - expect { subject.use_cdn?('18.245.0.1') }.to raise_error("Unknown CDN provider: amazon") + expect { subject.use_cdn?(public_ip) }.to raise_error("Unknown CDN provider: amazon") end end end |