This repository has been archived by the owner on Sep 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
context_test.go
60 lines (51 loc) · 1.68 KB
/
context_test.go
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
package apigo
import (
"context"
"testing"
"github.com/aws/aws-lambda-go/events"
"github.com/stretchr/testify/assert"
)
func TestNewContext(t *testing.T) {
ev := events.APIGatewayProxyRequest{
RequestContext: events.APIGatewayProxyRequestContext{
AccountID: "000000000000",
ResourceID: "XXXXXX",
Stage: "testing",
RequestID: "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
Identity: events.APIGatewayRequestIdentity{
CognitoIdentityPoolID: "xxx",
AccountID: "xxx",
CognitoIdentityID: "xxx",
Caller: "xxx",
APIKey: "xxx",
SourceIP: "1.1.1.1",
CognitoAuthenticationType: "xxx",
CognitoAuthenticationProvider: "xxx",
UserArn: "xxx",
UserAgent: "xxx",
User: "xxx",
},
ResourcePath: "/{id}",
Authorizer: map[string]interface{}{
"cognitoUsername": "johndoe",
"principalId": "xxxx",
},
HTTPMethod: "GET",
APIID: "XXXXXXXXXX",
},
}
r, _ := new(DefaultProxy).Transform(context.TODO(), ev)
rc, _ := RequestContext(r.Context())
assert.Equal(t, "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX", rc.RequestID)
assert.Equal(t, "johndoe", rc.Authorizer["cognitoUsername"])
}
func TestNewRequest_context(t *testing.T) {
type testRequestContextKey struct{}
var testContextKey = &testRequestContextKey{}
ev := events.APIGatewayProxyRequest{}
ctx := context.WithValue(context.TODO(), testContextKey, "value")
r, err := new(DefaultProxy).Transform(ctx, ev)
assert.NoError(t, err)
v := r.Context().Value(testContextKey)
assert.Equal(t, "value", v)
}