Skip to content

Commit d91ce84

Browse files
Merge branch 'master' of github.com:patelpratik4job/aws-lambda-go
2 parents e81668d + 36329db commit d91ce84

File tree

5 files changed

+81
-15
lines changed

5 files changed

+81
-15
lines changed

.github/workflows/tests.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ jobs:
2929
run: go test -race -coverprofile=coverage.txt -covermode=atomic ./...
3030

3131
- name: Upload coverage to Codecov
32-
uses: codecov/codecov-action@v1
33-
if: matrix.go == '1.16'
32+
uses: codecov/codecov-action@v2
3433
with:
3534
file: ./coverage.txt
35+
env_vars: GO
36+
env:
37+
GO: ${{ matrix.go }}

events/apigw.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,12 @@ type APIGatewayCustomAuthorizerResponse struct {
285285
UsageIdentifierKey string `json:"usageIdentifierKey,omitempty"`
286286
}
287287

288+
// APIGatewayV2CustomAuthorizerSimpleResponse represents the simple format of an API Gateway V2 authorization response.
289+
type APIGatewayV2CustomAuthorizerSimpleResponse struct {
290+
IsAuthorized bool `json:"isAuthorized"`
291+
Context map[string]interface{} `json:"context,omitempty"`
292+
}
293+
288294
// APIGatewayCustomAuthorizerPolicy represents an IAM policy
289295
type APIGatewayCustomAuthorizerPolicy struct {
290296
Version string

events/apigw_test.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,67 @@ func TestApiGatewayCustomAuthorizerResponseMarshaling(t *testing.T) {
177177
assert.JSONEq(t, string(inputJSON), string(outputJSON))
178178
}
179179

180+
func TestAPIGatewayV2CustomAuthorizerSimpleResponseMarshalling(t *testing.T) {
181+
var tests = []struct {
182+
desc string
183+
in APIGatewayV2CustomAuthorizerSimpleResponse
184+
out string
185+
}{
186+
{
187+
"defaults",
188+
APIGatewayV2CustomAuthorizerSimpleResponse{},
189+
`{"isAuthorized":false}`,
190+
},
191+
{
192+
"without context",
193+
APIGatewayV2CustomAuthorizerSimpleResponse{IsAuthorized: true},
194+
`{"isAuthorized":true}`,
195+
},
196+
{
197+
"context is nil",
198+
APIGatewayV2CustomAuthorizerSimpleResponse{Context: nil},
199+
`{"isAuthorized":false}`,
200+
},
201+
{
202+
"context is empty",
203+
APIGatewayV2CustomAuthorizerSimpleResponse{Context: map[string]interface{}{}},
204+
`{"isAuthorized":false}`,
205+
},
206+
{
207+
"context with basic types",
208+
APIGatewayV2CustomAuthorizerSimpleResponse{Context: map[string]interface{}{"string": "value", "bool": true, "number": 1234}},
209+
`{"isAuthorized":false,"context":{"string":"value","bool":true,"number":1234}}`,
210+
},
211+
{
212+
"context with array",
213+
APIGatewayV2CustomAuthorizerSimpleResponse{Context: map[string]interface{}{"array": []string{"value1", "value2"}}},
214+
`{"isAuthorized":false,"context":{"array":["value1","value2"]}}`,
215+
},
216+
{
217+
"context with map",
218+
APIGatewayV2CustomAuthorizerSimpleResponse{Context: map[string]interface{}{"map": map[string]string{"key": "value"}}},
219+
`{"isAuthorized":false,"context":{"map":{"key":"value"}}}`,
220+
},
221+
{
222+
"context with nil value",
223+
APIGatewayV2CustomAuthorizerSimpleResponse{Context: map[string]interface{}{"nil": nil}},
224+
`{"isAuthorized":false,"context":{"nil":null}}`,
225+
},
226+
}
227+
228+
for _, tt := range tests {
229+
tt := tt
230+
t.Run(tt.desc, func(t *testing.T) {
231+
outputJSON, err := json.Marshal(tt.in)
232+
if err != nil {
233+
t.Errorf("could not marshal event. details: %v", err)
234+
}
235+
236+
assert.JSONEq(t, tt.out, string(outputJSON))
237+
})
238+
}
239+
}
240+
180241
func TestApiGatewayCustomAuthorizerResponseMalformedJson(t *testing.T) {
181242
test.TestMalformedJson(t, APIGatewayCustomAuthorizerResponse{})
182243
}

events/kafka_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ func TestKafkaEventMarshaling(t *testing.T) {
3939
}
4040
}
4141
}
42+
43+
// 3. serialize to JSON
44+
outputJson, err := json.Marshal(inputEvent)
45+
if err != nil {
46+
t.Errorf("could not marshal event. details: %v", err)
47+
}
48+
49+
// 4. check result
50+
assert.JSONEq(t, string(inputJson), string(outputJson))
4251
}
4352

4453
func TestKafkaMarshalingMalformedJson(t *testing.T) {

events/testdata/kafka-event.json

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,7 @@
1414
"value": "OGQ1NTk2YjQtMTgxMy00MjM4LWIyNGItNmRhZDhlM2QxYzBj",
1515
"headers": [
1616
{
17-
"headerKey": [
18-
104,
19-
101,
20-
97,
21-
100,
22-
101,
23-
114,
24-
86,
25-
97,
26-
108,
27-
117,
28-
101
29-
]
17+
"headerKey": "aGVhZGVyVmFsdWU="
3018
}
3119
]
3220
}

0 commit comments

Comments
 (0)