MCPcopy Create free account
hub / github.com/aws/aws-lambda-go / TestContextDeserializationErrors

Function TestContextDeserializationErrors

lambda/invoke_loop_test.go:355–390  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

353}
354
355func TestContextDeserializationErrors(t *testing.T) {
356 badClientContext := defaultInvokeMetadata()
357 badClientContext.clientContext = `{ not json }`
358
359 badCognito := defaultInvokeMetadata()
360 badCognito.cognito = `{ not json }`
361
362 badDeadline := defaultInvokeMetadata()
363 badDeadline.deadline = `yolo`
364
365 badMetadata := []eventMetadata{badClientContext, badCognito, badDeadline}
366
367 ts, record := runtimeAPIServer(`{}`, len(badMetadata), badMetadata...)
368 defer ts.Close()
369 handler := NewHandler(func(ctx context.Context) (*lambdacontext.LambdaContext, error) {
370 lc, _ := lambdacontext.FromContext(ctx)
371 return lc, nil
372 })
373 endpoint := strings.Split(ts.URL, "://")[1]
374 _ = startRuntimeAPILoop(endpoint, handler)
375
376 assert.JSONEq(t, `{
377 "errorMessage":"failed to unmarshal client context json: invalid character 'n' looking for beginning of object key string",
378 "errorType":"errorString"
379 }`, string(record.responses[0]))
380
381 assert.JSONEq(t, `{
382 "errorMessage":"failed to unmarshal cognito identity json: invalid character 'n' looking for beginning of object key string",
383 "errorType":"errorString"
384 }`, string(record.responses[1]))
385
386 assert.JSONEq(t, `{
387 "errorMessage":"failed to parse deadline: strconv.ParseInt: parsing \"yolo\": invalid syntax",
388 "errorType":"errorString"
389 }`, string(record.responses[2]))
390}
391
392func TestClientContextWithNestedCustomValues(t *testing.T) {
393 metadata := defaultInvokeMetadata()

Callers

nothing calls this directly

Calls 6

FromContextFunction · 0.92
defaultInvokeMetadataFunction · 0.85
runtimeAPIServerFunction · 0.85
NewHandlerFunction · 0.85
startRuntimeAPILoopFunction · 0.70
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…