1- import { S3 } from "@aws-sdk/client-s3" ;
1+ import { S3 , S3ClientConfig , waitUntilBucketExists , waitUntilBucketNotExists } from "@aws-sdk/client-s3" ;
22import { GetCallerIdentityCommandOutput , STS } from "@aws-sdk/client-sts" ;
33import { afterAll , beforeAll , describe , expect , test as it } from "vitest" ;
44
55const testValue = "Hello S3 global client!" ;
66
77describe ( "S3 Global Client Test" , ( ) => {
88 const regionConfigs = [
9- { region : "us-east-1" , followRegionRedirects : true } ,
10- { region : "eu-west-1" , followRegionRedirects : true } ,
11- { region : "us-west-2" , followRegionRedirects : true } ,
12- ] ;
9+ { region : "us-east-1" , followRegionRedirects : true } as S3ClientConfig ,
10+ { region : "eu-west-1" , followRegionRedirects : true } as S3ClientConfig ,
11+ { region : "us-west-2" , followRegionRedirects : true } as S3ClientConfig ,
12+ ] . map ( ( config ) => {
13+ config . logger = {
14+ ...console ,
15+ error ( log : any ) {
16+ if ( "clientName" in log ) {
17+ return ;
18+ }
19+ console . error ( log ) ;
20+ } ,
21+ trace ( ) { } ,
22+ debug ( ) { } ,
23+ info ( ) { } ,
24+ } ;
25+ return config ;
26+ } ) ;
1327 const s3Clients = regionConfigs . map ( ( config ) => new S3 ( config ) ) ;
1428 const stsClient = new STS ( { } ) ;
1529
@@ -24,8 +38,18 @@ describe("S3 Global Client Test", () => {
2438 beforeAll ( async ( ) => {
2539 callerID = await stsClient . getCallerIdentity ( { } ) ;
2640 bucketNames = regionConfigs . map ( ( config ) => `${ callerID . Account } -${ randId } -redirect-${ config . region } ` ) ;
27- await Promise . all ( bucketNames . map ( ( bucketName , index ) => deleteBucket ( s3Clients [ index ] , bucketName ) ) ) ;
28- await Promise . all ( bucketNames . map ( ( bucketName , index ) => s3Clients [ index ] . createBucket ( { Bucket : bucketName } ) ) ) ;
41+ await Promise . all (
42+ bucketNames . map ( async ( bucketName , index ) => {
43+ await deleteBucket ( s3Clients [ index ] , bucketName ) ;
44+ return waitUntilBucketNotExists ( { client : s3Clients [ index ] , maxWaitTime : 60 } , { Bucket : bucketName } ) ;
45+ } )
46+ ) ;
47+ await Promise . all (
48+ bucketNames . map ( async ( bucketName , index ) => {
49+ await s3Clients [ index ] . createBucket ( { Bucket : bucketName } ) ;
50+ return waitUntilBucketExists ( { client : s3Clients [ index ] , maxWaitTime : 60 } , { Bucket : bucketName } ) ;
51+ } )
52+ ) ;
2953 await Promise . all ( bucketNames . map ( ( bucketName , index ) => s3Clients [ index ] . headBucket ( { Bucket : bucketName } ) ) ) ;
3054 } ) ;
3155
0 commit comments