1
- import { S3 } from "@aws-sdk/client-s3" ;
1
+ import { S3 , S3ClientConfig , waitUntilBucketExists , waitUntilBucketNotExists } from "@aws-sdk/client-s3" ;
2
2
import { GetCallerIdentityCommandOutput , STS } from "@aws-sdk/client-sts" ;
3
3
import { afterAll , beforeAll , describe , expect , test as it } from "vitest" ;
4
4
5
5
const testValue = "Hello S3 global client!" ;
6
6
7
7
describe ( "S3 Global Client Test" , ( ) => {
8
8
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
+ } ) ;
13
27
const s3Clients = regionConfigs . map ( ( config ) => new S3 ( config ) ) ;
14
28
const stsClient = new STS ( { } ) ;
15
29
@@ -24,8 +38,18 @@ describe("S3 Global Client Test", () => {
24
38
beforeAll ( async ( ) => {
25
39
callerID = await stsClient . getCallerIdentity ( { } ) ;
26
40
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
+ ) ;
29
53
await Promise . all ( bucketNames . map ( ( bucketName , index ) => s3Clients [ index ] . headBucket ( { Bucket : bucketName } ) ) ) ;
30
54
} ) ;
31
55
0 commit comments