diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 10:08:36 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 10:08:36 +0300 |
commit | 48aff82709769b098321c738f3444b9bdaa694c6 (patch) | |
tree | e00c7c43e2d9b603a5a6af576b1685e400410dee /spec/services/lfs | |
parent | 879f5329ee916a948223f8f43d77fba4da6cd028 (diff) |
Add latest changes from gitlab-org/gitlab@13-5-stable-eev13.5.0-rc42
Diffstat (limited to 'spec/services/lfs')
-rw-r--r-- | spec/services/lfs/push_service_spec.rb | 48 |
1 files changed, 36 insertions, 12 deletions
diff --git a/spec/services/lfs/push_service_spec.rb b/spec/services/lfs/push_service_spec.rb index 8e5b98fdc9c..f67284ff48d 100644 --- a/spec/services/lfs/push_service_spec.rb +++ b/spec/services/lfs/push_service_spec.rb @@ -19,7 +19,7 @@ RSpec.describe Lfs::PushService do stub_lfs_batch(lfs_object) expect(lfs_client) - .to receive(:upload) + .to receive(:upload!) .with(lfs_object, upload_action_spec(lfs_object), authenticated: true) expect(service.execute).to eq(status: :success) @@ -28,7 +28,7 @@ RSpec.describe Lfs::PushService do it 'does nothing if there are no LFS objects' do lfs_object.destroy! - expect(lfs_client).not_to receive(:upload) + expect(lfs_client).not_to receive(:upload!) expect(service.execute).to eq(status: :success) end @@ -36,20 +36,39 @@ RSpec.describe Lfs::PushService do it 'does not upload the object when upload is not requested' do stub_lfs_batch(lfs_object, upload: false) - expect(lfs_client).not_to receive(:upload) + expect(lfs_client).not_to receive(:upload!) expect(service.execute).to eq(status: :success) end + it 'verifies the upload if requested' do + stub_lfs_batch(lfs_object, verify: true) + + expect(lfs_client).to receive(:upload!) + expect(lfs_client) + .to receive(:verify!) + .with(lfs_object, verify_action_spec(lfs_object), authenticated: true) + + expect(service.execute).to eq(status: :success) + end + + it 'skips verification if requested but upload fails' do + stub_lfs_batch(lfs_object, verify: true) + + expect(lfs_client).to receive(:upload!) { raise 'failed' } + expect(lfs_client).not_to receive(:verify!) + expect(service.execute).to eq(status: :error, message: 'failed') + end + it 'returns a failure when submitting a batch fails' do - expect(lfs_client).to receive(:batch) { raise 'failed' } + expect(lfs_client).to receive(:batch!) { raise 'failed' } expect(service.execute).to eq(status: :error, message: 'failed') end it 'returns a failure when submitting an upload fails' do stub_lfs_batch(lfs_object) - expect(lfs_client).to receive(:upload) { raise 'failed' } + expect(lfs_client).to receive(:upload!) { raise 'failed' } expect(service.execute).to eq(status: :error, message: 'failed') end @@ -71,23 +90,28 @@ RSpec.describe Lfs::PushService do create(:lfs_objects_project, project: project, repository_type: type).lfs_object end - def stub_lfs_batch(*objects, upload: true) + def stub_lfs_batch(*objects, upload: true, verify: false) expect(lfs_client) - .to receive(:batch).with('upload', containing_exactly(*objects)) - .and_return('transfer' => 'basic', 'objects' => objects.map { |o| object_spec(o, upload: upload) }) + .to receive(:batch!).with('upload', containing_exactly(*objects)) + .and_return('transfer' => 'basic', 'objects' => objects.map { |o| object_spec(o, upload: upload, verify: verify) }) end - def batch_spec(*objects, upload: true) + def batch_spec(*objects, upload: true, verify: false) { 'transfer' => 'basic', 'objects' => objects.map {|o| object_spec(o, upload: upload) } } end - def object_spec(object, upload: true) - { 'oid' => object.oid, 'size' => object.size, 'authenticated' => true }.tap do |spec| - spec['actions'] = { 'upload' => upload_action_spec(object) } if upload + def object_spec(object, upload: true, verify: false) + { 'oid' => object.oid, 'size' => object.size, 'authenticated' => true, 'actions' => {} }.tap do |spec| + spec['actions']['upload'] = upload_action_spec(object) if upload + spec['actions']['verify'] = verify_action_spec(object) if verify end end def upload_action_spec(object) { 'href' => "https://example.com/#{object.oid}/#{object.size}", 'header' => { 'Key' => 'value' } } end + + def verify_action_spec(object) + { 'href' => "https://example.com/#{object.oid}/#{object.size}/verify", 'header' => { 'Key' => 'value' } } + end end |