Test get object with FGetObject with custom context
()
| 13590 | |
| 13591 | // Test get object with FGetObject with custom context |
| 13592 | func testFGetObjectContextV2() { |
| 13593 | // initialize logging params |
| 13594 | startTime := time.Now() |
| 13595 | testName := getFuncName() |
| 13596 | function := "FGetObject(ctx, bucketName, objectName,fileName)" |
| 13597 | args := map[string]interface{}{ |
| 13598 | "ctx": "", |
| 13599 | "bucketName": "", |
| 13600 | "objectName": "", |
| 13601 | "fileName": "", |
| 13602 | } |
| 13603 | |
| 13604 | c, err := NewClient(ClientConfig{CredsV2: true}) |
| 13605 | if err != nil { |
| 13606 | logError(testName, function, args, startTime, "", "MinIO v2 client object creation failed", err) |
| 13607 | return |
| 13608 | } |
| 13609 | |
| 13610 | // Generate a new random bucket name. |
| 13611 | bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test-") |
| 13612 | args["bucketName"] = bucketName |
| 13613 | |
| 13614 | // Make a new bucket. |
| 13615 | err = c.MakeBucket(context.Background(), bucketName, minio.MakeBucketOptions{Region: "us-east-1"}) |
| 13616 | if err != nil { |
| 13617 | logError(testName, function, args, startTime, "", "MakeBucket call failed", err) |
| 13618 | return |
| 13619 | } |
| 13620 | |
| 13621 | defer cleanupBucket(bucketName, c) |
| 13622 | |
| 13623 | bufSize := dataFileMap["datatfile-1-MB"] |
| 13624 | reader := getDataReader("datafile-1-MB") |
| 13625 | defer reader.Close() |
| 13626 | // Save the data |
| 13627 | objectName := randString(60, rand.NewSource(time.Now().UnixNano()), "") |
| 13628 | args["objectName"] = objectName |
| 13629 | |
| 13630 | _, err = c.PutObject(context.Background(), bucketName, objectName, reader, int64(bufSize), minio.PutObjectOptions{ContentType: "binary/octet-stream"}) |
| 13631 | if err != nil { |
| 13632 | logError(testName, function, args, startTime, "", "PutObject call failed", err) |
| 13633 | return |
| 13634 | } |
| 13635 | |
| 13636 | ctx, cancel := context.WithTimeout(context.Background(), 1*time.Nanosecond) |
| 13637 | args["ctx"] = ctx |
| 13638 | defer cancel() |
| 13639 | |
| 13640 | fileName := "tempfile-context" |
| 13641 | args["fileName"] = fileName |
| 13642 | |
| 13643 | // Read the data back |
| 13644 | err = c.FGetObject(ctx, bucketName, objectName, fileName+"-f", minio.GetObjectOptions{}) |
| 13645 | if err == nil { |
| 13646 | logError(testName, function, args, startTime, "", "FGetObject should fail on short timeout", err) |
| 13647 | return |
| 13648 | } |
| 13649 | ctx, cancel = context.WithTimeout(context.Background(), 1*time.Hour) |
no test coverage detected