@@ -392,6 +392,63 @@ fn insert_multipart_async() {
392
392
util:: cmp_strings ( & exp_body, & act_body) ;
393
393
}
394
394
395
+ #[ cfg( feature = "async-multipart" ) ]
396
+ #[ test]
397
+ fn insert_multipart_stream_bytes ( ) {
398
+ use bytes:: { BufMut , Bytes , BytesMut } ;
399
+
400
+ let metadata = Metadata {
401
+ name : Some ( "good_name" . to_owned ( ) ) ,
402
+ content_type : Some ( "text/plain" . to_owned ( ) ) ,
403
+ content_encoding : Some ( "gzip" . to_owned ( ) ) ,
404
+ content_disposition : Some ( "attachment; filename=\" good name.jpg\" " . to_owned ( ) ) ,
405
+ metadata : Some (
406
+ [ "akey" ]
407
+ . iter ( )
408
+ . map ( |k| ( String :: from ( * k) , format ! ( "{}value" , k) ) )
409
+ . collect ( ) ,
410
+ ) ,
411
+ ..Default :: default ( )
412
+ } ;
413
+
414
+ let insert_req = Object :: insert_multipart (
415
+ & BucketName :: non_validated ( "bucket" ) ,
416
+ Bytes :: from ( TEST_CONTENT ) ,
417
+ TEST_CONTENT . len ( ) as u64 ,
418
+ & metadata,
419
+ None ,
420
+ )
421
+ . unwrap ( ) ;
422
+
423
+ let exp_body = format ! (
424
+ "--{b}\n content-type: application/json; charset=utf-8\n \n {}\n --{b}\n content-type: text/plain\n \n {}\n --{b}--" ,
425
+ serde_json:: to_string( & metadata) . unwrap( ) ,
426
+ TEST_CONTENT ,
427
+ b = "tame_gcs"
428
+ ) ;
429
+
430
+ let expected = http:: Request :: builder ( )
431
+ . method ( http:: Method :: POST )
432
+ . uri ( "https://www.googleapis.com/upload/storage/v1/b/bucket/o?uploadType=multipart&prettyPrint=false" )
433
+ . header ( http:: header:: CONTENT_TYPE , "multipart/related; boundary=tame_gcs" )
434
+ . header ( http:: header:: CONTENT_LENGTH , 5758 )
435
+ . body ( exp_body)
436
+ . unwrap ( ) ;
437
+
438
+ let ( exp_parts, exp_body) = expected. into_parts ( ) ;
439
+ let ( act_parts, act_multipart) = insert_req. into_parts ( ) ;
440
+
441
+ util:: cmp_strings ( & format ! ( "{:#?}" , exp_parts) , & format ! ( "{:#?}" , act_parts) ) ;
442
+
443
+ let mut act_body = BytesMut :: with_capacity ( 2 * 1024 ) ;
444
+ for chunk in futures:: executor:: block_on_stream ( act_multipart) {
445
+ act_body. put ( chunk) ;
446
+ }
447
+ let act_body = String :: from_utf8_lossy ( & act_body) ;
448
+
449
+ util:: cmp_strings ( & exp_body, & act_body) ;
450
+ }
451
+
395
452
#[ test]
396
453
fn patches ( ) {
397
454
let mut md = std:: collections:: BTreeMap :: new ( ) ;
0 commit comments