Test get object with FGetObject with custom context
()
| 13486 | |
| 13487 | // Test get object with FGetObject with custom context |
| 13488 | func testFGetObjectContextV2() { |
| 13489 | // initialize logging params |
| 13490 | startTime := time.Now() |
| 13491 | testName := getFuncName() |
| 13492 | function := "FGetObject(ctx, bucketName, objectName,fileName)" |
| 13493 | args := map[string]interface{}{ |
| 13494 | "ctx": "", |
| 13495 | "bucketName": "", |
| 13496 | "objectName": "", |
| 13497 | "fileName": "", |
| 13498 | } |
| 13499 | |
| 13500 | c, err := NewClient(ClientConfig{CredsV2: true}) |
| 13501 | if err != nil { |
| 13502 | logError(testName, function, args, startTime, "", "MinIO v2 client object creation failed", err) |
| 13503 | return |
| 13504 | } |
| 13505 | |
| 13506 | // Generate a new random bucket name. |
| 13507 | bucketName := randString(60, rand.NewSource(time.Now().UnixNano()), "minio-go-test-") |
| 13508 | args["bucketName"] = bucketName |
| 13509 | |
| 13510 | // Make a new bucket. |
| 13511 | err = c.MakeBucket(context.Background(), bucketName, minio.MakeBucketOptions{Region: "us-east-1"}) |
| 13512 | if err != nil { |
| 13513 | logError(testName, function, args, startTime, "", "MakeBucket call failed", err) |
| 13514 | return |
| 13515 | } |
| 13516 | |
| 13517 | defer cleanupBucket(bucketName, c) |
| 13518 | |
| 13519 | bufSize := dataFileMap["datatfile-1-MB"] |
| 13520 | reader := getDataReader("datafile-1-MB") |
| 13521 | defer reader.Close() |
| 13522 | // Save the data |
| 13523 | objectName := randString(60, rand.NewSource(time.Now().UnixNano()), "") |
| 13524 | args["objectName"] = objectName |
| 13525 | |
| 13526 | _, err = c.PutObject(context.Background(), bucketName, objectName, reader, int64(bufSize), minio.PutObjectOptions{ContentType: "binary/octet-stream"}) |
| 13527 | if err != nil { |
| 13528 | logError(testName, function, args, startTime, "", "PutObject call failed", err) |
| 13529 | return |
| 13530 | } |
| 13531 | |
| 13532 | ctx, cancel := context.WithTimeout(context.Background(), 1*time.Nanosecond) |
| 13533 | args["ctx"] = ctx |
| 13534 | defer cancel() |
| 13535 | |
| 13536 | fileName := "tempfile-context" |
| 13537 | args["fileName"] = fileName |
| 13538 | |
| 13539 | // Read the data back |
| 13540 | err = c.FGetObject(ctx, bucketName, objectName, fileName+"-f", minio.GetObjectOptions{}) |
| 13541 | if err == nil { |
| 13542 | logError(testName, function, args, startTime, "", "FGetObject should fail on short timeout", err) |
| 13543 | return |
| 13544 | } |
| 13545 | ctx, cancel = context.WithTimeout(context.Background(), 1*time.Hour) |
no test coverage detected