1
1
import { HttpHandlerOptions , HeaderBag } from "@smithy/types" ;
2
2
import { HttpHandler , HttpRequest , HttpResponse } from "@smithy/protocol-http" ;
3
- import { Readable } from ' stream' ;
3
+ import { Readable } from " stream" ;
4
4
5
5
/**
6
6
* Throws an expected exception that contains the serialized request.
7
7
*/
8
8
class EXPECTED_REQUEST_SERIALIZATION_ERROR extends Error {
9
- constructor ( readonly request : HttpRequest ) {
10
- super ( ) ;
11
- }
9
+ constructor ( readonly request : HttpRequest ) {
10
+ super ( ) ;
11
+ }
12
12
}
13
13
14
14
/**
15
15
* Throws an EXPECTED_REQUEST_SERIALIZATION_ERROR error before sending a
16
16
* request. The thrown exception contains the serialized request.
17
17
*/
18
18
class RequestSerializationTestHandler implements HttpHandler {
19
- handle (
20
- request : HttpRequest ,
21
- options ?: HttpHandlerOptions
22
- ) : Promise < { response : HttpResponse } > {
23
- return Promise . reject ( new EXPECTED_REQUEST_SERIALIZATION_ERROR ( request ) ) ;
24
- }
25
- updateHttpClientConfig ( key : never , value : never ) : void { }
26
- httpHandlerConfigs ( ) { return { } ; }
19
+ handle ( request : HttpRequest , options ?: HttpHandlerOptions ) : Promise < { response : HttpResponse } > {
20
+ return Promise . reject ( new EXPECTED_REQUEST_SERIALIZATION_ERROR ( request ) ) ;
21
+ }
22
+ updateHttpClientConfig ( key : never , value : never ) : void { }
23
+ httpHandlerConfigs ( ) {
24
+ return { } ;
25
+ }
27
26
}
28
27
29
28
/**
30
29
* Returns a resolved Promise of the specified response contents.
31
30
*/
32
31
class ResponseDeserializationTestHandler implements HttpHandler {
33
- isSuccess : boolean ;
34
- code : number ;
35
- headers : HeaderBag ;
36
- body : String ;
37
-
38
- constructor (
39
- isSuccess : boolean ,
40
- code : number ,
41
- headers ?: HeaderBag ,
42
- body ?: String
43
- ) {
44
- this . isSuccess = isSuccess ;
45
- this . code = code ;
46
- if ( headers === undefined ) {
47
- this . headers = { } ;
48
- } else {
49
- this . headers = headers ;
50
- }
51
- if ( body === undefined ) {
52
- body = "" ;
53
- }
54
- this . body = body ;
32
+ isSuccess : boolean ;
33
+ code : number ;
34
+ headers : HeaderBag ;
35
+ body : String ;
36
+
37
+ constructor ( isSuccess : boolean , code : number , headers ?: HeaderBag , body ?: String ) {
38
+ this . isSuccess = isSuccess ;
39
+ this . code = code ;
40
+ if ( headers === undefined ) {
41
+ this . headers = { } ;
42
+ } else {
43
+ this . headers = headers ;
55
44
}
56
-
57
- handle (
58
- request : HttpRequest ,
59
- options ?: HttpHandlerOptions
60
- ) : Promise < { response : HttpResponse } > {
61
- return Promise . resolve ( {
62
- response : new HttpResponse ( {
63
- statusCode : this . code ,
64
- headers : this . headers ,
65
- body : Readable . from ( [ this . body ] )
66
- } )
67
- } ) ;
45
+ if ( body === undefined ) {
46
+ body = "" ;
68
47
}
69
- updateHttpClientConfig ( key : never , value : never ) : void { }
70
- httpHandlerConfigs ( ) { return { } ; }
48
+ this . body = body ;
49
+ }
50
+
51
+ handle ( request : HttpRequest , options ?: HttpHandlerOptions ) : Promise < { response : HttpResponse } > {
52
+ return Promise . resolve ( {
53
+ response : new HttpResponse ( {
54
+ statusCode : this . code ,
55
+ headers : this . headers ,
56
+ body : Readable . from ( [ this . body ] ) ,
57
+ } ) ,
58
+ } ) ;
59
+ }
60
+ updateHttpClientConfig ( key : never , value : never ) : void { }
61
+ httpHandlerConfigs ( ) {
62
+ return { } ;
63
+ }
71
64
}
72
65
73
66
interface comparableParts {
74
- [ key : string ] : string
67
+ [ key : string ] : string ;
75
68
}
76
69
77
70
/**
78
71
* Generates a standard map of un-equal values given input parts.
79
72
*/
80
73
const compareParts = ( expectedParts : comparableParts , generatedParts : comparableParts ) => {
81
74
const unequalParts : any = { } ;
82
- Object . keys ( expectedParts ) . forEach ( key => {
75
+ Object . keys ( expectedParts ) . forEach ( ( key ) => {
83
76
if ( generatedParts [ key ] === undefined ) {
84
77
unequalParts [ key ] = { exp : expectedParts [ key ] , gen : undefined } ;
85
78
} else if ( ! equivalentContents ( expectedParts [ key ] , generatedParts [ key ] ) ) {
86
79
unequalParts [ key ] = { exp : expectedParts [ key ] , gen : generatedParts [ key ] } ;
87
80
}
88
81
} ) ;
89
82
90
- Object . keys ( generatedParts ) . forEach ( key => {
83
+ Object . keys ( generatedParts ) . forEach ( ( key ) => {
91
84
if ( expectedParts [ key ] === undefined ) {
92
85
unequalParts [ key ] = { exp : undefined , gen : generatedParts [ key ] } ;
93
86
}
@@ -115,10 +108,10 @@ const equivalentContents = (expected: any, generated: any): boolean => {
115
108
// If a test fails with an issue in the below 6 lines, it's likely
116
109
// due to an issue in the nestedness or existence of the property
117
110
// being compared.
118
- delete localExpected [ ' $$metadata' ] ;
119
- delete generated [ ' $$metadata' ] ;
120
- Object . keys ( localExpected ) . forEach ( key => localExpected [ key ] === undefined && delete localExpected [ key ] )
121
- Object . keys ( generated ) . forEach ( key => generated [ key ] === undefined && delete generated [ key ] )
111
+ delete localExpected [ " $$metadata" ] ;
112
+ delete generated [ " $$metadata" ] ;
113
+ Object . keys ( localExpected ) . forEach ( ( key ) => localExpected [ key ] === undefined && delete localExpected [ key ] ) ;
114
+ Object . keys ( generated ) . forEach ( ( key ) => generated [ key ] === undefined && delete generated [ key ] ) ;
122
115
123
116
const expectedProperties = Object . getOwnPropertyNames ( localExpected ) ;
124
117
const generatedProperties = Object . getOwnPropertyNames ( generated ) ;
@@ -137,17 +130,18 @@ const equivalentContents = (expected: any, generated: any): boolean => {
137
130
}
138
131
139
132
return true ;
140
- }
133
+ } ;
141
134
142
135
const clientParams = {
143
136
region : "us-west-2" ,
144
- credentials : { accessKeyId : "key" , secretAccessKey : "secret" }
145
- }
137
+ endpoint : "https://localhost/" ,
138
+ credentials : { accessKeyId : "key" , secretAccessKey : "secret" } ,
139
+ } ;
146
140
147
141
/**
148
142
* A wrapper function that shadows `fail` from jest-jasmine2
149
143
* (jasmine2 was replaced with circus in > v27 as the default test runner)
150
144
*/
151
145
const fail = ( error ?: any ) : never => {
152
- throw new Error ( error ) ;
153
- }
146
+ throw new Error ( error ) ;
147
+ } ;
0 commit comments