|
|
@ -375,13 +375,13 @@ func TestObjectService_Upload(t *testing.T) { |
|
|
|
} |
|
|
|
defer os.Remove(filePath) |
|
|
|
// 源文件内容
|
|
|
|
b := make([]byte, 1024*1024*10) |
|
|
|
b := make([]byte, 1024*1024*33) |
|
|
|
_, err = rand.Read(b) |
|
|
|
newfile.Write(b) |
|
|
|
newfile.Close() |
|
|
|
|
|
|
|
// 已上传内容, 10个分块
|
|
|
|
rb := make([][]byte, 10) |
|
|
|
rb := make([][]byte, 33) |
|
|
|
uploadid := "test-cos-multiupload-uploadid" |
|
|
|
partmap := make(map[int64]int) |
|
|
|
mux.HandleFunc("/test.go.upload", func(w http.ResponseWriter, r *http.Request) { |
|
|
@ -423,9 +423,7 @@ func TestObjectService_Upload(t *testing.T) { |
|
|
|
// 完成分块上传
|
|
|
|
tb := crc64.MakeTable(crc64.ECMA) |
|
|
|
crc := uint64(0) |
|
|
|
ccv := make([]uint64, 10) |
|
|
|
for i, v := range rb { |
|
|
|
ccv[i] = crc64.Update(0, crc64.MakeTable(crc64.ECMA), v) |
|
|
|
for _, v := range rb { |
|
|
|
crc = crc64.Update(crc, tb, v) |
|
|
|
} |
|
|
|
w.Header().Add("x-cos-hash-crc64ecma", strconv.FormatUint(crc, 10)) |
|
|
@ -450,3 +448,69 @@ func TestObjectService_Upload(t *testing.T) { |
|
|
|
t.Fatalf("Object.Upload returned error: %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func TestObjectService_Upload2(t *testing.T) { |
|
|
|
setup() |
|
|
|
defer teardown() |
|
|
|
|
|
|
|
filePath := "tmpfile" + time.Now().Format(time.RFC3339) |
|
|
|
newfile, err := os.Create(filePath) |
|
|
|
if err != nil { |
|
|
|
t.Fatalf("create tmp file failed") |
|
|
|
} |
|
|
|
defer os.Remove(filePath) |
|
|
|
// 源文件内容
|
|
|
|
b := make([]byte, 1024*1024*3) |
|
|
|
_, err = rand.Read(b) |
|
|
|
newfile.Write(b) |
|
|
|
newfile.Close() |
|
|
|
|
|
|
|
tb := crc64.MakeTable(crc64.ECMA) |
|
|
|
realcrc := crc64.Update(0, tb, b) |
|
|
|
name := "test/hello.txt" |
|
|
|
retry := 0 |
|
|
|
final := 4 |
|
|
|
mux.HandleFunc("/test/hello.txt", func(w http.ResponseWriter, r *http.Request) { |
|
|
|
testMethod(t, r, http.MethodPut) |
|
|
|
testHeader(t, r, "x-cos-acl", "private") |
|
|
|
testHeader(t, r, "Content-Type", "text/html") |
|
|
|
|
|
|
|
if retry%2 == 0 { |
|
|
|
bs, _ := ioutil.ReadAll(r.Body) |
|
|
|
crc := crc64.Update(0, tb, bs) |
|
|
|
if !reflect.DeepEqual(bs, b) { |
|
|
|
t.Errorf("Object.Put request body Error") |
|
|
|
} |
|
|
|
if !reflect.DeepEqual(crc, realcrc) { |
|
|
|
t.Errorf("Object.Put crc: %v, want: %v", crc, realcrc) |
|
|
|
} |
|
|
|
w.Header().Add("x-cos-hash-crc64ecma", strconv.FormatUint(crc, 10)) |
|
|
|
if retry != final { |
|
|
|
w.WriteHeader(http.StatusGatewayTimeout) |
|
|
|
} |
|
|
|
} else { |
|
|
|
w.Header().Add("x-cos-hash-crc64ecma", "123456789") |
|
|
|
} |
|
|
|
}) |
|
|
|
|
|
|
|
mopt := &MultiUploadOptions{ |
|
|
|
OptIni: &InitiateMultipartUploadOptions{ |
|
|
|
ObjectPutHeaderOptions: &ObjectPutHeaderOptions{ |
|
|
|
ContentType: "text/html", |
|
|
|
}, |
|
|
|
ACLHeaderOptions: &ACLHeaderOptions{ |
|
|
|
XCosACL: "private", |
|
|
|
}, |
|
|
|
}, |
|
|
|
} |
|
|
|
for retry <= final { |
|
|
|
_, _, err := client.Object.Upload(context.Background(), name, filePath, mopt) |
|
|
|
if retry < final && err == nil { |
|
|
|
t.Fatalf("Error must not nil when retry < final") |
|
|
|
} |
|
|
|
if retry == final && err != nil { |
|
|
|
t.Fatalf("Put Error: %v", err) |
|
|
|
} |
|
|
|
retry++ |
|
|
|
} |
|
|
|
} |