@@ -177,6 +177,67 @@ func TestApiGatewayCustomAuthorizerResponseMarshaling(t *testing.T) {
177
177
assert .JSONEq (t , string (inputJSON ), string (outputJSON ))
178
178
}
179
179
180
+ func TestAPIGatewayV2CustomAuthorizerSimpleResponseMarshalling (t * testing.T ) {
181
+ var tests = []struct {
182
+ desc string
183
+ in APIGatewayV2CustomAuthorizerSimpleResponse
184
+ out string
185
+ }{
186
+ {
187
+ "defaults" ,
188
+ APIGatewayV2CustomAuthorizerSimpleResponse {},
189
+ `{"isAuthorized":false}` ,
190
+ },
191
+ {
192
+ "without context" ,
193
+ APIGatewayV2CustomAuthorizerSimpleResponse {IsAuthorized : true },
194
+ `{"isAuthorized":true}` ,
195
+ },
196
+ {
197
+ "context is nil" ,
198
+ APIGatewayV2CustomAuthorizerSimpleResponse {Context : nil },
199
+ `{"isAuthorized":false}` ,
200
+ },
201
+ {
202
+ "context is empty" ,
203
+ APIGatewayV2CustomAuthorizerSimpleResponse {Context : map [string ]interface {}{}},
204
+ `{"isAuthorized":false}` ,
205
+ },
206
+ {
207
+ "context with basic types" ,
208
+ APIGatewayV2CustomAuthorizerSimpleResponse {Context : map [string ]interface {}{"string" : "value" , "bool" : true , "number" : 1234 }},
209
+ `{"isAuthorized":false,"context":{"string":"value","bool":true,"number":1234}}` ,
210
+ },
211
+ {
212
+ "context with array" ,
213
+ APIGatewayV2CustomAuthorizerSimpleResponse {Context : map [string ]interface {}{"array" : []string {"value1" , "value2" }}},
214
+ `{"isAuthorized":false,"context":{"array":["value1","value2"]}}` ,
215
+ },
216
+ {
217
+ "context with map" ,
218
+ APIGatewayV2CustomAuthorizerSimpleResponse {Context : map [string ]interface {}{"map" : map [string ]string {"key" : "value" }}},
219
+ `{"isAuthorized":false,"context":{"map":{"key":"value"}}}` ,
220
+ },
221
+ {
222
+ "context with nil value" ,
223
+ APIGatewayV2CustomAuthorizerSimpleResponse {Context : map [string ]interface {}{"nil" : nil }},
224
+ `{"isAuthorized":false,"context":{"nil":null}}` ,
225
+ },
226
+ }
227
+
228
+ for _ , tt := range tests {
229
+ tt := tt
230
+ t .Run (tt .desc , func (t * testing.T ) {
231
+ outputJSON , err := json .Marshal (tt .in )
232
+ if err != nil {
233
+ t .Errorf ("could not marshal event. details: %v" , err )
234
+ }
235
+
236
+ assert .JSONEq (t , tt .out , string (outputJSON ))
237
+ })
238
+ }
239
+ }
240
+
180
241
func TestApiGatewayCustomAuthorizerResponseMalformedJson (t * testing.T ) {
181
242
test .TestMalformedJson (t , APIGatewayCustomAuthorizerResponse {})
182
243
}
0 commit comments