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

Function TestRuntimeAPIContextPlumbing

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

Source from the content-addressed store, hash-verified

196}
197
198func TestRuntimeAPIContextPlumbing(t *testing.T) {
199 handler := NewHandler(func(ctx context.Context) (interface{}, error) {
200 lc, _ := lambdacontext.FromContext(ctx)
201 deadline, _ := ctx.Deadline()
202 return struct {
203 Context *lambdacontext.LambdaContext
204 TraceID string
205 EnvTraceID string
206 Deadline int64
207 }{
208 Context: lc,
209 TraceID: ctx.Value("x-amzn-trace-id").(string),
210 EnvTraceID: os.Getenv("_X_AMZN_TRACE_ID"),
211 Deadline: deadline.UnixNano() / nsPerMS,
212 }, nil
213 })
214
215 metadata2 := defaultInvokeMetadata()
216 metadata2.tenantID = "some-tenant-id"
217 ts, record := runtimeAPIServer(``, 2, defaultInvokeMetadata(), metadata2)
218 defer ts.Close()
219
220 endpoint := strings.Split(ts.URL, "://")[1]
221 expectedError := fmt.Sprintf("failed to GET http://%s/2018-06-01/runtime/invocation/next: got unexpected status code: 410", endpoint)
222 assert.EqualError(t, startRuntimeAPILoop(endpoint, handler), expectedError)
223
224 expected1 := `
225 {
226 "Context": {
227 "AwsRequestID": "dummyid",
228 "InvokedFunctionArn": "dummyarn",
229 "Identity": {
230 "CognitoIdentityID": "dummyident",
231 "CognitoIdentityPoolID": "dummypool"
232 },
233 "ClientContext": {
234 "Client": {
235 "installation_id": "dummyinstallid",
236 "app_title": "dummytitle",
237 "app_version_code": "dummycode",
238 "app_package_name": "dummyname"
239 },
240 "env": null,
241 "custom": null
242 }
243 },
244 "TraceID": "its-xray-time",
245 "EnvTraceID": "its-xray-time",
246 "Deadline": 22
247 }
248 `
249 expected2 := `
250 {
251 "Context": {
252 "AwsRequestID": "dummyid",
253 "InvokedFunctionArn": "dummyarn",
254 "TenantID": "some-tenant-id",
255 "Identity": {

Callers

nothing calls this directly

Calls 8

FromContextFunction · 0.92
NewHandlerFunction · 0.85
defaultInvokeMetadataFunction · 0.85
runtimeAPIServerFunction · 0.85
DeadlineMethod · 0.80
startRuntimeAPILoopFunction · 0.70
ValueMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…