Skip to content

Commit 430ee9e

Browse files
adding tests
1 parent 93b9520 commit 430ee9e

2 files changed

Lines changed: 54 additions & 0 deletions

File tree

google-apis-core/spec/google/apis/core/service_spec.rb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
require 'google/apis/options'
1717
require 'google/apis/core/base_service'
1818
require 'google/apis/core/json_representation'
19+
require 'pry'
1920

2021
RSpec.describe Google::Apis::Core::BaseService do
2122
include TestHelpers
@@ -287,6 +288,24 @@
287288
expect(a_request(:put, upload_url)).to have_been_made
288289
end
289290
end
291+
context 'Should return false if wrong upload id is provided' do
292+
let(:upload_id) { 'wrong_id' }
293+
let(:command) do
294+
service.send(
295+
:restart_resumable_upload,
296+
bucket_name, file, upload_id,
297+
options: { upload_chunk_size: 11}
298+
)
299+
end
300+
before(:example) do
301+
stub_request(:put, upload_url)
302+
.to_return(status: 404)
303+
end
304+
it 'should return false' do
305+
expect(command).to be_falsey
306+
end
307+
end
308+
290309
end
291310

292311
context 'delete resumable upload with upload_id' do
@@ -312,6 +331,24 @@
312331
expect(a_request(:delete, upload_url)).to have_been_made
313332
expect(command).to be_truthy
314333
end
334+
335+
context 'Should return false if wrong upload id is provided' do
336+
let(:upload_id) { 'wrong_id' }
337+
let(:command) do
338+
service.send(
339+
:delete_resumable_upload,
340+
bucket_name, upload_id,
341+
options: { upload_chunk_size: 11}
342+
)
343+
end
344+
before(:example) do
345+
stub_request(:delete, upload_url)
346+
.to_return(status: 404)
347+
end
348+
it 'should return false' do
349+
expect(command).to be_falsey
350+
end
351+
end
315352
end
316353

317354
context 'with batch' do

google-apis-core/spec/google/apis/core/storage_upload_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,14 @@
161161
expect(a_request(:put, upload_url)
162162
.with(body: 'Hello world')).to have_been_made
163163
end
164+
165+
it 'should return false if wrong upload id is provided' do
166+
stub_request(:put, upload_url)
167+
.to_return(status: 404)
168+
command.options.upload_chunk_size = 11
169+
command.upload_id = upload_id
170+
expect(command.execute(client)).to be_falsy
171+
end
164172
end
165173

166174
context('should not restart resumable upload if upload is completed') do
@@ -235,6 +243,15 @@
235243
expect(a_request(:put, upload_url)
236244
.with(body: 'Hello world')).to have_not_been_made
237245
end
246+
247+
it 'should return false if wrong upload id is provided' do
248+
stub_request(:delete, upload_url)
249+
.to_return(status: 404)
250+
command.options.upload_chunk_size = 11
251+
command.upload_id = upload_id
252+
command.delete_upload = true
253+
expect(command.execute(client)).to be_falsy
254+
end
238255
end
239256

240257
context('with chunking disabled') do

0 commit comments

Comments
 (0)