add headers + length test for upload io

This commit is contained in:
Ruslan Korolev 2015-08-17 16:51:01 +03:00
parent 0cc3a1f814
commit cb4c7cfb8c
1 changed files with 17 additions and 0 deletions

View File

@ -47,6 +47,12 @@ RSpec.describe Google::Apis::Core::UploadIO do
io = Google::Apis::Core::UploadIO.from_file(file, content_type: 'application/json') io = Google::Apis::Core::UploadIO.from_file(file, content_type: 'application/json')
expect(io.content_type).to eql('application/json') expect(io.content_type).to eql('application/json')
end end
it 'should setup length of the stream' do
upload_io = Google::Apis::Core::UploadIO.from_file(file)
expect(upload_io.length).to eq File.size(file)
end
end end
end end
@ -64,6 +70,11 @@ RSpec.describe Google::Apis::Core::UploadIO do
upload_io = Google::Apis::Core::UploadIO.from_io(io, content_type: 'application/x-gzip') upload_io = Google::Apis::Core::UploadIO.from_io(io, content_type: 'application/x-gzip')
expect(upload_io.content_type).to eq('application/x-gzip') expect(upload_io.content_type).to eq('application/x-gzip')
end end
it 'should setup length of the stream' do
upload_io = Google::Apis::Core::UploadIO.from_io(io)
expect(upload_io.length).to eq 'Hello google'.length
end
end end
end end
@ -96,6 +107,12 @@ RSpec.describe Google::Apis::Core::RawUploadCommand do
expect(a_request(:post, 'https://www.googleapis.com/zoo/animals') expect(a_request(:post, 'https://www.googleapis.com/zoo/animals')
.with { |req| req.headers['X-Goog-Upload-Protocol'] == 'raw' }).to have_been_made .with { |req| req.headers['X-Goog-Upload-Protocol'] == 'raw' }).to have_been_made
end end
it 'should send content-type header' do
command.execute(client)
expect(a_request(:post, 'https://www.googleapis.com/zoo/animals')
.with { |req| req.headers['X-Goog-Upload-Header-Content-Type'] == 'text/plain' }).to have_been_made
end
end end
context('with StringIO input') do context('with StringIO input') do