MCPcopy Create free account
hub / github.com/awsdocs/aws-lambda-developer-guide / TestMain

Function TestMain

sample-apps/blank-go/function/main_test.go:15–38  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

13)
14
15func TestMain(t *testing.T) {
16 d := time.Now().Add(50 * time.Millisecond)
17 os.Setenv("AWS_LAMBDA_FUNCTION_NAME","blank-go")
18 ctx, _ := context.WithDeadline(context.Background(), d)
19 ctx = lambdacontext.NewContext(ctx, &lambdacontext.LambdaContext{
20 AwsRequestID: "495b12a8-xmpl-4eca-8168-160484189f99",
21 InvokedFunctionArn: "arn:aws:lambda:us-east-2:123456789012:function:blank-go",
22 })
23 inputJson := ReadJSONFromFile(t, "../event.json")
24 var event events.SQSEvent
25 err := json.Unmarshal(inputJson, &event)
26 if err != nil {
27 t.Errorf("could not unmarshal event. details: %v", err)
28 }
29 //var inputEvent SQSEvent
30 result, err := handleRequest(ctx, event)
31 if err != nil {
32 t.Log(err)
33 }
34 t.Log(result)
35 if !strings.Contains(result, "FunctionCount") {
36 t.Errorf("Output does not contain FunctionCount.")
37 }
38}
39func ReadJSONFromFile(t *testing.T, inputFile string) []byte {
40 inputJSON, err := ioutil.ReadFile(inputFile)
41 if err != nil {

Callers

nothing calls this directly

Calls 2

ReadJSONFromFileFunction · 0.85
handleRequestFunction · 0.70

Tested by

no test coverage detected