@@ -108,7 +108,7 @@ func Test_AWSLambdaMiddleware_InvokeBasic(t *testing.T) {
108
108
assert .Equal (t , "/test/example/path" , lReq .Path )
109
109
assert .Equal (t , map [string ]string {"a" : "1" , "b" : "2" }, lReq .QueryStringParameters )
110
110
assert .Equal (t , map [string ][]string {"c" : {"3" , "4" }, "d[]" : {"5" , "6" }}, lReq .MultiValueQueryStringParameters )
111
- assert .Equal (t , map [string ]string {"Content-Type" : "text/plain " }, lReq .Headers )
111
+ assert .Equal (t , map [string ]string {"Content-Type" : "application/json " }, lReq .Headers )
112
112
assert .Equal (t , map [string ][]string {"X-Test" : {"foo" , "foobar" }}, lReq .MultiValueHeaders )
113
113
assert .Equal (t , "This is the body" , lReq .Body )
114
114
@@ -144,7 +144,7 @@ func Test_AWSLambdaMiddleware_InvokeBasic(t *testing.T) {
144
144
if err != nil {
145
145
t .Fatal (err )
146
146
}
147
- req .Header .Set ("Content-Type" , "text/plain " )
147
+ req .Header .Set ("Content-Type" , "application/json " )
148
148
req .Header .Add ("X-Test" , "foo" )
149
149
req .Header .Add ("X-Test" , "foobar" )
150
150
@@ -178,10 +178,11 @@ func Test_AWSLambdaMiddleware_GetTracingInformation(t *testing.T) {
178
178
func Test_AWSLambdaMiddleware_bodyToBase64_empty (t * testing.T ) {
179
179
req , err := http .NewRequest (http .MethodGet , "/" , nil )
180
180
require .NoError (t , err )
181
- isEncoded , body , err := bodyToBase64 (req )
181
+ isEncoded , contentType , body , err := bodyToBase64 (req )
182
182
183
183
assert .False (t , isEncoded )
184
184
assert .Equal (t , "" , body )
185
+ assert .Equal (t , "" , contentType )
185
186
require .NoError (t , err )
186
187
}
187
188
@@ -191,10 +192,27 @@ func Test_AWSLambdaMiddleware_bodyToBase64_notEncodedJSON(t *testing.T) {
191
192
192
193
req , err := http .NewRequest (http .MethodPost , "/" , strings .NewReader (reqBody ))
193
194
require .NoError (t , err )
194
- isEncoded , body , err := bodyToBase64 (req )
195
+ isEncoded , contentType , body , err := bodyToBase64 (req )
195
196
196
197
assert .False (t , isEncoded )
197
198
assert .Equal (t , reqBody , body )
199
+ assert .Equal (t , "text/plain; charset=utf-8" , contentType )
200
+ require .NoError (t , err )
201
+ }
202
+
203
+ func Test_AWSLambdaMiddleware_bodyToBase64_EncodedJSON (t * testing.T ) {
204
+ bodyBytes , err := json .Marshal (`{"test": "encoded"}` )
205
+ if err != nil {
206
+ t .Fatal (err )
207
+ }
208
+
209
+ req , err := http .NewRequest (http .MethodPost , "/" , strings .NewReader (string (bodyBytes )))
210
+ require .NoError (t , err )
211
+ isEncoded , contentType , body , err := bodyToBase64 (req )
212
+
213
+ assert .False (t , isEncoded )
214
+ assert .Equal (t , string (bodyBytes ), body )
215
+ assert .Equal (t , "text/plain; charset=utf-8" , contentType )
198
216
require .NoError (t , err )
199
217
}
200
218
@@ -206,10 +224,11 @@ func Test_AWSLambdaMiddleware_bodyToBase64_withcontent(t *testing.T) {
206
224
207
225
req , err := http .NewRequest (http .MethodPost , "/" , strings .NewReader (reqBody ))
208
226
require .NoError (t , err )
209
- isEncoded , body , err := bodyToBase64 (req )
227
+ isEncoded , contentType , body , err := bodyToBase64 (req )
210
228
211
229
assert .True (t , isEncoded )
212
230
assert .Equal (t , expected , body )
231
+ assert .Equal (t , "application/zip" , contentType )
213
232
require .NoError (t , err )
214
233
215
234
// image/jpeg
@@ -218,9 +237,10 @@ func Test_AWSLambdaMiddleware_bodyToBase64_withcontent(t *testing.T) {
218
237
219
238
req2 , err2 := http .NewRequest (http .MethodPost , "/" , strings .NewReader (reqBody2 ))
220
239
require .NoError (t , err2 )
221
- isEncoded2 , body2 , err2 := bodyToBase64 (req2 )
240
+ isEncoded2 , contentType2 , body2 , err2 := bodyToBase64 (req2 )
222
241
223
242
assert .True (t , isEncoded2 )
224
243
assert .Equal (t , expected2 , body2 )
244
+ assert .Equal (t , "image/jpeg" , contentType2 )
225
245
require .NoError (t , err2 )
226
246
}
0 commit comments