@@ -375,13 +375,13 @@ func TestObjectService_Upload(t *testing.T) {
375375 }
376376 defer os .Remove (filePath )
377377 // 源文件内容
378- b := make ([]byte , 1024 * 1024 * 10 )
378+ b := make ([]byte , 1024 * 1024 * 33 )
379379 _ , err = rand .Read (b )
380380 newfile .Write (b )
381381 newfile .Close ()
382382
383383 // 已上传内容, 10个分块
384- rb := make ([][]byte , 10 )
384+ rb := make ([][]byte , 33 )
385385 uploadid := "test-cos-multiupload-uploadid"
386386 partmap := make (map [int64 ]int )
387387 mux .HandleFunc ("/test.go.upload" , func (w http.ResponseWriter , r * http.Request ) {
@@ -423,9 +423,7 @@ func TestObjectService_Upload(t *testing.T) {
423423 // 完成分块上传
424424 tb := crc64 .MakeTable (crc64 .ECMA )
425425 crc := uint64 (0 )
426- ccv := make ([]uint64 , 10 )
427- for i , v := range rb {
428- ccv [i ] = crc64 .Update (0 , crc64 .MakeTable (crc64 .ECMA ), v )
426+ for _ , v := range rb {
429427 crc = crc64 .Update (crc , tb , v )
430428 }
431429 w .Header ().Add ("x-cos-hash-crc64ecma" , strconv .FormatUint (crc , 10 ))
@@ -450,3 +448,69 @@ func TestObjectService_Upload(t *testing.T) {
450448 t .Fatalf ("Object.Upload returned error: %v" , err )
451449 }
452450}
451+
452+ func TestObjectService_Upload2 (t * testing.T ) {
453+ setup ()
454+ defer teardown ()
455+
456+ filePath := "tmpfile" + time .Now ().Format (time .RFC3339 )
457+ newfile , err := os .Create (filePath )
458+ if err != nil {
459+ t .Fatalf ("create tmp file failed" )
460+ }
461+ defer os .Remove (filePath )
462+ // 源文件内容
463+ b := make ([]byte , 1024 * 1024 * 3 )
464+ _ , err = rand .Read (b )
465+ newfile .Write (b )
466+ newfile .Close ()
467+
468+ tb := crc64 .MakeTable (crc64 .ECMA )
469+ realcrc := crc64 .Update (0 , tb , b )
470+ name := "test/hello.txt"
471+ retry := 0
472+ final := 4
473+ mux .HandleFunc ("/test/hello.txt" , func (w http.ResponseWriter , r * http.Request ) {
474+ testMethod (t , r , http .MethodPut )
475+ testHeader (t , r , "x-cos-acl" , "private" )
476+ testHeader (t , r , "Content-Type" , "text/html" )
477+
478+ if retry % 2 == 0 {
479+ bs , _ := ioutil .ReadAll (r .Body )
480+ crc := crc64 .Update (0 , tb , bs )
481+ if ! reflect .DeepEqual (bs , b ) {
482+ t .Errorf ("Object.Put request body Error" )
483+ }
484+ if ! reflect .DeepEqual (crc , realcrc ) {
485+ t .Errorf ("Object.Put crc: %v, want: %v" , crc , realcrc )
486+ }
487+ w .Header ().Add ("x-cos-hash-crc64ecma" , strconv .FormatUint (crc , 10 ))
488+ if retry != final {
489+ w .WriteHeader (http .StatusGatewayTimeout )
490+ }
491+ } else {
492+ w .Header ().Add ("x-cos-hash-crc64ecma" , "123456789" )
493+ }
494+ })
495+
496+ mopt := & MultiUploadOptions {
497+ OptIni : & InitiateMultipartUploadOptions {
498+ ObjectPutHeaderOptions : & ObjectPutHeaderOptions {
499+ ContentType : "text/html" ,
500+ },
501+ ACLHeaderOptions : & ACLHeaderOptions {
502+ XCosACL : "private" ,
503+ },
504+ },
505+ }
506+ for retry <= final {
507+ _ , _ , err := client .Object .Upload (context .Background (), name , filePath , mopt )
508+ if retry < final && err == nil {
509+ t .Fatalf ("Error must not nil when retry < final" )
510+ }
511+ if retry == final && err != nil {
512+ t .Fatalf ("Put Error: %v" , err )
513+ }
514+ retry ++
515+ }
516+ }
0 commit comments