MCPcopy
hub / github.com/minio/minio-go / Test200MultipartUploadWithError

Function Test200MultipartUploadWithError

200OKwithError_test.go:89–148  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

87}
88
89func Test200MultipartUploadWithError(t *testing.T) {
90 const maxRetries = 3
91 retries := maxRetries
92
93 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
94 retries--
95 w.Write([]byte(`<?xml version="1.0" encoding="UTF-8"?>`))
96 w.(http.Flusher).Flush()
97 for i := 0; i < 5; i++ {
98 time.Sleep(time.Second)
99 w.Write([]byte(" "))
100 w.(http.Flusher).Flush()
101 }
102
103 w.Write([]byte(`<Error><Code>SlowDownWrite</Code><Message>Resource requested is unwritable, please reduce your request rate</Message><Key>object</Key><BucketName>bucket</BucketName><Resource>/bucket/object</Resource><RequestId>18413E84F6C30613</RequestId><HostId>49371f38c0d7ec74eae2befc695360a3dfece04732914e58a4281759cd2eba4f</HostId></Error>`))
104 }))
105
106 srv, err := url.Parse(ts.URL)
107 if err != nil {
108 t.Fatal(err)
109 }
110
111 // Instantiate new minio client object.
112 core, err := NewCore(
113 srv.Host,
114 &Options{
115 Creds: credentials.NewStaticV4("foo", "foo12345", ""),
116 Secure: srv.Scheme == "https",
117 Region: "us-east-1",
118 MaxRetries: retries,
119 })
120 if err != nil {
121 t.Fatal("Error:", err)
122 }
123
124 parts := []CompletePart{
125 {PartNumber: 1, ETag: "b386a859d8a22ff986c0b1252be34658"},
126 {PartNumber: 2, ETag: "78c577a580bbbba92845789cda1fa932"},
127 }
128
129 _, err = core.CompleteMultipartUpload(context.Background(),
130 "bucket",
131 "object",
132 "jY1M2U5NWMtZGY2OC00ZjYyLTljZGYtYmZlOWEzODM3MDMwLjlmZWY5OGNlLWQ1Y2EtNDgwMC04N2Y4LWZkNTNkMDM4ZDdiMXgxNzQ4NjA0NzI0NzE4NjU3MTY3",
133 parts,
134 PutObjectOptions{},
135 )
136 if err == nil {
137 t.Fatal("CompleteMultipartUpload() returned <nil>, which is unexpected")
138 }
139
140 expectedErrorMsg := "Resource requested is unwritable, please reduce your request rate"
141 if err.Error() != expectedErrorMsg {
142 t.Fatalf("Unexpected returned error, expected: `%v`, found: `%v`", expectedErrorMsg, err.Error())
143 }
144
145 if retries != 0 {
146 t.Fatalf("CompleteMultipart request was not retried enough times, expected: %d, found: %d", maxRetries, retries)

Callers

nothing calls this directly

Calls 4

NewStaticV4Function · 0.92
NewCoreFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected