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

Function Test200DeleteObjectsWithError

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

Source from the content-addressed store, hash-verified

148}
149
150func Test200DeleteObjectsWithError(t *testing.T) {
151 const maxRetries = 3
152 retries := maxRetries
153
154 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
155 retries--
156 w.Write([]byte(`<?xml version="1.0" encoding="UTF-8"?>`))
157 w.(http.Flusher).Flush()
158 for i := 0; i < 5; i++ {
159 time.Sleep(time.Second)
160 w.Write([]byte(" "))
161 w.(http.Flusher).Flush()
162 }
163
164 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>`))
165 }))
166
167 srv, err := url.Parse(ts.URL)
168 if err != nil {
169 t.Fatal(err)
170 }
171
172 // Instantiate new minio client object.
173 core, err := NewCore(
174 srv.Host,
175 &Options{
176 Creds: credentials.NewStaticV4("foo", "foo12345", ""),
177 Secure: srv.Scheme == "https",
178 Region: "us-east-1",
179 MaxRetries: retries,
180 })
181 if err != nil {
182 t.Fatal("Error:", err)
183 }
184
185 // core.TraceOn(os.Stderr)
186
187 objs := make(chan ObjectInfo, 1000)
188 for i := range 1000 {
189 objs <- ObjectInfo{Key: fmt.Sprintf("obj-%d", i)}
190 }
191 close(objs)
192
193 delErrCh := core.RemoveObjects(context.Background(), "bucket", objs, RemoveObjectsOptions{})
194 delErr := <-delErrCh
195 err = delErr.Err
196 if err == nil {
197 t.Fatal("RemoveObjects() returned <nil>, which is unexpected")
198 }
199
200 expectedErrorMsg := "Resource requested is unwritable, please reduce your request rate"
201 if err.Error() != expectedErrorMsg {
202 t.Fatalf("Unexpected returned error, expected: `%v`, found: `%v`", expectedErrorMsg, err.Error())
203 }
204
205 if retries != 0 {
206 t.Fatalf("RemoveObjects() request was not retried enough times, expected: %d, found: %d", maxRetries, retries)
207 }

Callers

nothing calls this directly

Calls 4

NewStaticV4Function · 0.92
NewCoreFunction · 0.85
RemoveObjectsMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected