@@ -8,8 +8,22 @@ describe("useRegionalEndpointMiddleware", () => {
8
8
jest . clearAllMocks ( ) ;
9
9
} ) ;
10
10
11
+ it ( "should accept any endpoint if set by customer" , async ( ) => {
12
+ const config = { isCustomEndpoint : true , region : async ( ) => "foo-region" } ;
13
+ const handler = useRegionalEndpointMiddleware ( config ) ( mockNextHandler , { } as any ) ;
14
+ await handler ( {
15
+ input : { } ,
16
+ request : new HttpRequest ( {
17
+ hostname : "s3.us-east-1.amazonaws.com" ,
18
+ } ) ,
19
+ } ) ;
20
+ expect ( mockNextHandler . mock . calls . length ) . toBe ( 1 ) ;
21
+ expect ( mockNextHandler . mock . calls [ 0 ] [ 0 ] . request . hostname ) . toEqual ( "s3.us-east-1.amazonaws.com" ) ;
22
+ } ) ;
23
+
11
24
it ( "should modify the hostname if it's global endpoint" , async ( ) => {
12
- const handler = useRegionalEndpointMiddleware ( ) ( mockNextHandler , { } as any ) ;
25
+ const config = { isCustomEndpoint : false , region : async ( ) => "foo-region" } ;
26
+ const handler = useRegionalEndpointMiddleware ( config ) ( mockNextHandler , { } as any ) ;
13
27
await handler ( {
14
28
input : { } ,
15
29
request : new HttpRequest ( {
@@ -21,7 +35,8 @@ describe("useRegionalEndpointMiddleware", () => {
21
35
} ) ;
22
36
23
37
it ( "should not modify the hostname if it's regional endpoint" , async ( ) => {
24
- const handler = useRegionalEndpointMiddleware ( ) ( mockNextHandler , { } as any ) ;
38
+ const config = { isCustomEndpoint : false , region : async ( ) => "foo-region" } ;
39
+ const handler = useRegionalEndpointMiddleware ( config ) ( mockNextHandler , { } as any ) ;
25
40
await handler ( {
26
41
input : { } ,
27
42
request : new HttpRequest ( {
@@ -31,4 +46,17 @@ describe("useRegionalEndpointMiddleware", () => {
31
46
expect ( mockNextHandler . mock . calls . length ) . toBe ( 1 ) ;
32
47
expect ( mockNextHandler . mock . calls [ 0 ] [ 0 ] . request . hostname ) . toEqual ( "s3.us-west-2.amazonaws.com" ) ;
33
48
} ) ;
49
+
50
+ it ( "should use global endpoint if region is set to 'aws-global'" , async ( ) => {
51
+ const config = { isCustomEndpoint : false , region : async ( ) => "aws-global" } ;
52
+ const handler = useRegionalEndpointMiddleware ( config ) ( mockNextHandler , { } as any ) ;
53
+ await handler ( {
54
+ input : { } ,
55
+ request : new HttpRequest ( {
56
+ hostname : "s3.aws-global.amazonaws.com" ,
57
+ } ) ,
58
+ } ) ;
59
+ expect ( mockNextHandler . mock . calls . length ) . toBe ( 1 ) ;
60
+ expect ( mockNextHandler . mock . calls [ 0 ] [ 0 ] . request . hostname ) . toEqual ( "s3.amazonaws.com" ) ;
61
+ } ) ;
34
62
} ) ;
0 commit comments