diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-19 04:45:44 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-19 04:45:44 +0300 |
commit | 85dc423f7090da0a52c73eb66faf22ddb20efff9 (patch) | |
tree | 9160f299afd8c80c038f08e1545be119f5e3f1e1 /spec/uploaders/object_storage_spec.rb | |
parent | 15c2c8c66dbe422588e5411eee7e68f1fa440bb8 (diff) |
Add latest changes from gitlab-org/gitlab@13-4-stable-ee
Diffstat (limited to 'spec/uploaders/object_storage_spec.rb')
-rw-r--r-- | spec/uploaders/object_storage_spec.rb | 76 |
1 files changed, 61 insertions, 15 deletions
diff --git a/spec/uploaders/object_storage_spec.rb b/spec/uploaders/object_storage_spec.rb index 12c936e154b..c73a9a7aab1 100644 --- a/spec/uploaders/object_storage_spec.rb +++ b/spec/uploaders/object_storage_spec.rb @@ -210,6 +210,27 @@ RSpec.describe ObjectStorage do end end + describe '#use_open_file' do + context 'when file is stored locally' do + it "returns the file" do + expect { |b| uploader.use_open_file(&b) }.to yield_with_args(an_instance_of(ObjectStorage::Concern::OpenFile)) + end + end + + context 'when file is stored remotely' do + let(:store) { described_class::Store::REMOTE } + + before do + stub_artifacts_object_storage + stub_request(:get, %r{s3.amazonaws.com/#{uploader.path}}).to_return(status: 200, body: '') + end + + it "returns the file" do + expect { |b| uploader.use_open_file(&b) }.to yield_with_args(an_instance_of(ObjectStorage::Concern::OpenFile)) + end + end + end + describe '#migrate!' do subject { uploader.migrate!(new_store) } @@ -414,28 +435,38 @@ RSpec.describe ObjectStorage do subject { uploader_class.workhorse_authorize(has_length: has_length, maximum_size: maximum_size) } - shared_examples 'uses local storage' do + shared_examples 'returns the maximum size given' do it "returns temporary path" do - is_expected.to have_key(:TempPath) + expect(subject[:MaximumSize]).to eq(maximum_size) + end + end + + shared_examples 'uses local storage' do + it_behaves_like 'returns the maximum size given' do + it "returns temporary path" do + is_expected.to have_key(:TempPath) - expect(subject[:TempPath]).to start_with(uploader_class.root) - expect(subject[:TempPath]).to include(described_class::TMP_UPLOAD_PATH) + expect(subject[:TempPath]).to start_with(uploader_class.root) + expect(subject[:TempPath]).to include(described_class::TMP_UPLOAD_PATH) + end end end shared_examples 'uses remote storage' do - it "returns remote store" do - is_expected.to have_key(:RemoteObject) + it_behaves_like 'returns the maximum size given' do + it "returns remote store" do + is_expected.to have_key(:RemoteObject) - expect(subject[:RemoteObject]).to have_key(:ID) - expect(subject[:RemoteObject]).to include(Timeout: a_kind_of(Integer)) - expect(subject[:RemoteObject][:Timeout]).to be(ObjectStorage::DirectUpload::TIMEOUT) - expect(subject[:RemoteObject]).to have_key(:GetURL) - expect(subject[:RemoteObject]).to have_key(:DeleteURL) - expect(subject[:RemoteObject]).to have_key(:StoreURL) - expect(subject[:RemoteObject][:GetURL]).to include(described_class::TMP_UPLOAD_PATH) - expect(subject[:RemoteObject][:DeleteURL]).to include(described_class::TMP_UPLOAD_PATH) - expect(subject[:RemoteObject][:StoreURL]).to include(described_class::TMP_UPLOAD_PATH) + expect(subject[:RemoteObject]).to have_key(:ID) + expect(subject[:RemoteObject]).to include(Timeout: a_kind_of(Integer)) + expect(subject[:RemoteObject][:Timeout]).to be(ObjectStorage::DirectUpload::TIMEOUT) + expect(subject[:RemoteObject]).to have_key(:GetURL) + expect(subject[:RemoteObject]).to have_key(:DeleteURL) + expect(subject[:RemoteObject]).to have_key(:StoreURL) + expect(subject[:RemoteObject][:GetURL]).to include(described_class::TMP_UPLOAD_PATH) + expect(subject[:RemoteObject][:DeleteURL]).to include(described_class::TMP_UPLOAD_PATH) + expect(subject[:RemoteObject][:StoreURL]).to include(described_class::TMP_UPLOAD_PATH) + end end end @@ -834,4 +865,19 @@ RSpec.describe ObjectStorage do end end end + + describe 'OpenFile' do + subject { ObjectStorage::Concern::OpenFile.new(file) } + + let(:file) { double(read: true, size: true, path: true) } + + it 'delegates read and size methods' do + expect(subject.read).to eq(true) + expect(subject.size).to eq(true) + end + + it 'does not delegate path method' do + expect { subject.path }.to raise_error(NoMethodError) + end + end end |