houdini/spec/lib/chunked_uploader/s3_spec.rb
Bradley M. Kuhn 6772312ea7 Relicense all .rb files under new project license.
The primary license of the project is changing to:
  AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later

with some specific files to be licensed under the one of two licenses:
   CC0-1.0
   LGPL-3.0-or-later

This commit is one of the many steps to relicense the entire codebase.

Documentation granting permission for this relicensing (from all past
contributors who hold copyrights) is on file with Software Freedom
Conservancy, Inc.
2018-03-25 15:10:40 -04:00

83 lines
2.5 KiB
Ruby

# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later
require 'rspec'
require 'rails_helper'
describe ChunkedUploader::S3 do
context '.upload' do
skip 'Only run this if you are okay getting billed on s3' do
before(:each) do
WebMock.disable!
@s3 = AWS::S3.new
@bucket = @s3.buckets[ENV['S3_BUCKET_NAME']]
@path = 'tmp/export/1000000000.csv'
@object = @bucket.objects[@path]
end
after(:each) do
@object.delete
WebMock.enable!
end
it 'uploads empty properly' do
ChunkedUploader::S3.upload(@path, [], content_type: 'text/csv')
info = @object.read.to_s
expect(info).to eq('')
end
it 'uploads very small properly' do
input = 'row11,row12\nrow21,row22\n'
ChunkedUploader::S3.upload(@path, [input], content_type: 'text/csv')
info = @object.read.to_s
expect(info).to eq(input)
pending('NOTE: METADATA CHECKING ISNT WORKING SO WE SKIP IT FOR NOW')
metadata = @object.metadata
puts metadata
expect(metadata['Content-Type']).to eq('text/csv')
end
it 'uploads very large single properly' do
temp = StringIO.new
500_000.times { temp << 'row11,row12\n' }
ChunkedUploader::S3.upload(@path, [temp.string])
info = @object.read.to_s
expect(info).to eq(temp.string)
pending('NOTE: METADATA CHECKING ISNT WORKING SO WE SKIP IT FOR NOW')
metadata = @object.metadata
expect(metadata['Content-Type']).to eq('text/csv')
end
it 'uploads properly' do
input_item = StringIO.new
input = Enumerator.new do |y|
temp = StringIO.new
300_000.times { temp << 'row11,row12\n' }
input_item.write(temp.string)
y << temp.string
temp = StringIO.new
300_000.times { temp << 'row21,row22\n' }
input_item.write(temp.string)
y << temp.string
temp = StringIO.new
300_000.times { temp << 'row31,row32\n' }
input_item.write(temp.string)
y << temp.string
end.lazy
ChunkedUploader::S3.upload(@path, input, content_type: 'text/csv')
info = @object.read.to_s
expect(info).to eq(input_item.string)
pending('NOTE: METADATA CHECKING ISNT WORKING SO WE SKIP IT FOR NOW')
metadata = @object.metadata
expect(metadata['Content-Type']).to eq('text/csv')
end
end
end
end