-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmultipart_test.go
138 lines (120 loc) · 3.85 KB
/
multipart_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package test
import (
"bytes"
mclient "github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/encrypt"
"github.com/stretchr/testify/require"
"io"
"testing"
"time"
)
func TestApi_Object_Multipart(t *testing.T) {
t.Parallel()
bucket := "object-mp"
r := require.New(t)
err := proxyClient.MakeBucket(tstCtx, bucket, mclient.MakeBucketOptions{Region: "us-east"})
r.NoError(err)
t.Cleanup(func() {
cleanup(t, true, bucket)
})
ok, err := proxyClient.BucketExists(tstCtx, bucket)
r.NoError(err)
r.True(ok)
r.Eventually(func() bool {
ok, err = mainClient.BucketExists(tstCtx, bucket)
if err != nil || !ok {
return false
}
ok, err = f1Client.BucketExists(tstCtx, bucket)
if err != nil || !ok {
return false
}
ok, err = f2Client.BucketExists(tstCtx, bucket)
if err != nil || !ok {
return false
}
return true
}, time.Second*3, time.Millisecond*100)
objName := "obj-mp"
_, err = mainClient.StatObject(tstCtx, bucket, objName, mclient.StatObjectOptions{})
r.Error(err)
_, err = f1Client.StatObject(tstCtx, bucket, objName, mclient.StatObjectOptions{})
r.Error(err)
_, err = f2Client.StatObject(tstCtx, bucket, objName, mclient.StatObjectOptions{})
r.Error(err)
_, err = proxyClient.StatObject(tstCtx, bucket, objName, mclient.StatObjectOptions{})
r.Error(err)
uploadID, err := mpProxyClient.NewMultipartUpload(tstCtx, bucket, objName, mclient.PutObjectOptions{UserMetadata: map[string]string{"Content-Type": "binary/octet-stream"}, DisableContentSha256: true})
r.NoError(err)
buf := bytes.Repeat([]byte("a"), 32*1024*1024)
br := bytes.NewReader(buf)
partBuf := make([]byte, 100*1024*1024)
parts := make([]mclient.CompletePart, 0, 5)
partID := 0
for {
n, err := br.Read(partBuf)
if err != nil && err != io.EOF {
t.Fatal("Error:", err)
}
if err == io.EOF {
break
}
if n > 0 {
partID++
data := bytes.NewReader(partBuf[:n])
dataLen := int64(len(partBuf[:n]))
objectPart, err := mpProxyClient.PutObjectPart(tstCtx, bucket, objName, uploadID, partID,
data, dataLen,
mclient.PutObjectPartOptions{SSE: encrypt.NewSSE()},
)
r.NoError(err)
parts = append(parts, mclient.CompletePart{
PartNumber: partID,
ETag: objectPart.ETag,
})
}
}
objectParts, err := mpProxyClient.ListObjectParts(tstCtx, bucket, objName, uploadID, 0, 0)
r.NoError(err)
r.EqualValues(len(parts), len(objectParts.ObjectParts))
_, err = proxyClient.StatObject(tstCtx, bucket, objName, mclient.GetObjectOptions{})
r.Error(err)
_, err = mpProxyClient.CompleteMultipartUpload(tstCtx, bucket, objName, uploadID, parts, mclient.PutObjectOptions{})
r.NoError(err)
obj, err := proxyClient.GetObject(tstCtx, bucket, objName, mclient.GetObjectOptions{})
r.NoError(err)
proxyBytes, err := io.ReadAll(obj)
r.NoError(err)
_, err = proxyClient.StatObject(tstCtx, bucket, objName, mclient.StatObjectOptions{})
r.NoError(err)
r.Eventually(func() bool {
_, err = mainClient.StatObject(tstCtx, bucket, objName, mclient.StatObjectOptions{})
if err != nil {
return false
}
_, err = f1Client.StatObject(tstCtx, bucket, objName, mclient.StatObjectOptions{})
if err != nil {
return false
}
_, err = f2Client.StatObject(tstCtx, bucket, objName, mclient.StatObjectOptions{})
if err != nil {
return false
}
return true
}, time.Second*3, time.Millisecond*100)
obj, err = mainClient.GetObject(tstCtx, bucket, objName, mclient.GetObjectOptions{})
r.NoError(err)
objBytes, err := io.ReadAll(obj)
r.NoError(err)
r.EqualValues(proxyBytes, objBytes)
obj, err = f1Client.GetObject(tstCtx, bucket, objName, mclient.GetObjectOptions{})
r.NoError(err)
objBytes, err = io.ReadAll(obj)
r.NoError(err)
r.EqualValues(proxyBytes, objBytes)
obj, err = f2Client.GetObject(tstCtx, bucket, objName, mclient.GetObjectOptions{})
r.NoError(err)
objBytes, err = io.ReadAll(obj)
r.NoError(err)
r.EqualValues(proxyBytes, objBytes)
}