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

Function TestProcessBucketLocationResponse

bucket-cache_test.go:285–349  ·  view source on GitHub ↗

Tests the processing of GetPolicy response from server.

(t *testing.T)

Source from the content-addressed store, hash-verified

283
284// Tests the processing of GetPolicy response from server.
285func TestProcessBucketLocationResponse(t *testing.T) {
286 // LocationResponse - format for location response.
287 type LocationResponse struct {
288 XMLName xml.Name `xml:"http://s3.amazonaws.com/doc/2006-03-01/ LocationConstraint" json:"-"`
289 Location string `xml:",chardata"`
290 }
291
292 APIErrors := []APIError{
293 {
294 Code: AccessDenied,
295 Description: "Access Denied",
296 HTTPStatusCode: http.StatusUnauthorized,
297 },
298 }
299 testCases := []struct {
300 bucketName string
301 inputLocation string
302 isAPIError bool
303 apiErr APIError
304 // expected results.
305 expectedResult string
306 err error
307 // flag indicating whether tests should pass.
308 shouldPass bool
309 }{
310 {"my-bucket", "", true, APIErrors[0], "us-east-1", nil, true},
311 {"my-bucket", "", false, APIError{}, "us-east-1", nil, true},
312 {"my-bucket", "EU", false, APIError{}, "eu-west-1", nil, true},
313 {"my-bucket", "eu-central-1", false, APIError{}, "eu-central-1", nil, true},
314 {"my-bucket", "us-east-1", false, APIError{}, "us-east-1", nil, true},
315 }
316
317 for i, testCase := range testCases {
318 inputResponse := &http.Response{}
319 var err error
320 if testCase.isAPIError {
321 inputResponse = generateErrorResponse(inputResponse, testCase.apiErr, testCase.bucketName)
322 } else {
323 inputResponse, err = generateLocationResponse(inputResponse, encodeResponse(LocationResponse{
324 Location: testCase.inputLocation,
325 }))
326 if err != nil {
327 t.Fatalf("Test %d: Creation of valid response failed", i+1)
328 }
329 }
330 actualResult, err := processBucketLocationResponse(inputResponse, "my-bucket")
331 if err != nil && testCase.shouldPass {
332 t.Errorf("Test %d: Expected to pass, but failed with: <ERROR> %s", i+1, err.Error())
333 }
334 if err == nil && !testCase.shouldPass {
335 t.Errorf("Test %d: Expected to fail with <ERROR> \"%s\", but passed instead", i+1, testCase.err.Error())
336 }
337 // Failed as expected, but does it fail for the expected reason.
338 if err != nil && !testCase.shouldPass {
339 if err.Error() != testCase.err.Error() {
340 t.Errorf("Test %d: Expected to fail with error \"%s\", but instead failed with error \"%s\" instead", i+1, testCase.err.Error(), err.Error())
341 }
342 }

Callers

nothing calls this directly

Calls 5

generateErrorResponseFunction · 0.85
generateLocationResponseFunction · 0.85
encodeResponseFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected