forked from aws/aws-lambda-runtime-interface-emulator
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathrestorenext_test.go
More file actions
87 lines (70 loc) · 2.96 KB
/
restorenext_test.go
File metadata and controls
87 lines (70 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package handler
import (
"context"
"net/http"
"net/http/httptest"
"strconv"
"strings"
"testing"
"github.com/stretchr/testify/assert"
"go.amzn.com/lambda/appctx"
"go.amzn.com/lambda/interop"
"go.amzn.com/lambda/telemetry"
"go.amzn.com/lambda/testdata"
)
func TestRenderRestoreNext(t *testing.T) {
flowTest := testdata.NewFlowTest()
flowTest.ConfigureForInit()
handler := NewRestoreNextHandler(flowTest.RegistrationService, flowTest.RenderingService)
responseRecorder := httptest.NewRecorder()
appCtx := flowTest.AppCtx
flowTest.ConfigureForRestore()
request := appctx.RequestWithAppCtx(httptest.NewRequest("", "/", nil), appCtx)
handler.ServeHTTP(responseRecorder, request)
assert.Equal(t, http.StatusOK, responseRecorder.Code)
}
func TestBrokenRenderer(t *testing.T) {
flowTest := testdata.NewFlowTest()
flowTest.ConfigureForInit()
handler := NewRestoreNextHandler(flowTest.RegistrationService, flowTest.RenderingService)
responseRecorder := httptest.NewRecorder()
appCtx := flowTest.AppCtx
flowTest.ConfigureForRestore()
flowTest.RenderingService.SetRenderer(&mockBrokenRenderer{})
request := appctx.RequestWithAppCtx(httptest.NewRequest("", "/", nil), appCtx)
handler.ServeHTTP(responseRecorder, request)
assert.Equal(t, http.StatusInternalServerError, responseRecorder.Code)
assert.JSONEq(t, `{"errorMessage":"Internal Server Error","errorType":"InternalServerError"}`, responseRecorder.Body.String())
}
func TestRenderRestoreAfterInvoke(t *testing.T) {
flowTest := testdata.NewFlowTest()
flowTest.ConfigureForInit()
handler := NewInvocationNextHandler(flowTest.RegistrationService, flowTest.RenderingService)
responseRecorder := httptest.NewRecorder()
appCtx := flowTest.AppCtx
deadlineNs := 12345
invokePayload := "Payload"
invoke := &interop.Invoke{
TraceID: "Root=RootID;Parent=LambdaFrontend;Sampled=1",
ID: "ID",
InvokedFunctionArn: "InvokedFunctionArn",
CognitoIdentityID: "CognitoIdentityId1",
CognitoIdentityPoolID: "CognitoIdentityPoolId1",
ClientContext: "ClientContext",
DeadlineNs: strconv.Itoa(deadlineNs),
ContentType: "image/png",
Payload: strings.NewReader(invokePayload),
}
ctx := telemetry.NewTraceContext(context.Background(), "RootID", "InvocationSubegmentID")
flowTest.ConfigureForInvoke(ctx, invoke)
request := appctx.RequestWithAppCtx(httptest.NewRequest("", "/", nil), appCtx)
handler.ServeHTTP(responseRecorder, request)
assert.Equal(t, http.StatusOK, responseRecorder.Code)
restoreHandler := NewRestoreNextHandler(flowTest.RegistrationService, flowTest.RenderingService)
restoreRequest := appctx.RequestWithAppCtx(httptest.NewRequest("", "/", nil), appCtx)
responseRecorder = httptest.NewRecorder()
restoreHandler.ServeHTTP(responseRecorder, restoreRequest)
assert.Equal(t, http.StatusForbidden, responseRecorder.Code)
}