MCPcopy Index your code
hub / github.com/aws/aws-lambda-go / TestInvokeWithContext

Function TestInvokeWithContext

lambda/rpc_function_test.go:66–89  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

64}
65
66func TestInvokeWithContext(t *testing.T) {
67 key := struct{}{}
68 srv := NewFunction(&handlerOptions{
69 handlerFunc: func(ctx context.Context, _ []byte) (io.Reader, error) {
70 assert.Equal(t, "dummy", ctx.Value(key))
71 if deadline, ok := ctx.Deadline(); ok {
72 return strings.NewReader(strconv.FormatInt(deadline.UnixNano(), 10)), nil
73 }
74 return nil, errors.New("!?!?!?!?!")
75 },
76 baseContext: context.WithValue(context.Background(), key, "dummy"),
77 })
78 deadline := time.Now()
79 var response messages.InvokeResponse
80 err := srv.Invoke(&messages.InvokeRequest{
81 Deadline: messages.InvokeRequest_Timestamp{
82 Seconds: deadline.Unix(),
83 Nanos: int64(deadline.Nanosecond()),
84 }}, &response)
85 assert.NoError(t, err)
86 var responseValue int64
87 assert.NoError(t, json.Unmarshal(response.Payload, &responseValue))
88 assert.Equal(t, deadline.UnixNano(), responseValue)
89}
90
91type CustomError struct{}
92

Callers

nothing calls this directly

Calls 4

InvokeMethod · 0.95
NewFunctionFunction · 0.85
DeadlineMethod · 0.80
ValueMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…