Skip to content

Commit c941d49

Browse files
vinujohnbmoffatt
authored andcommitted
Feature/add kinesis analytics event (#169)
* added event for kinesis analytics output delivery * added tests for kinesis analytics * Arn -> ARN * fix bad merge conflict resolution inputJson -> inputJSON
1 parent fec1e14 commit c941d49

17 files changed

+119
-24
lines changed

events/autoscaling_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func TestAutoScalingEventMarshaling(t *testing.T) {
1818

1919
t.Logf("Running test for %s\n", sampleFile)
2020
// 1. read JSON from file
21-
inputJson := readJsonFromFile(t, "./testdata/"+sampleFile)
21+
inputJson := test.ReadJSONFromFile(t, "./testdata/"+sampleFile)
2222

2323
// 2. de-serialize into Go object
2424
var inputEvent AutoScalingEvent

events/cloudwatch_logs_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"encoding/json"
55
"reflect"
66
"testing"
7+
8+
tst "github.com/aws/aws-lambda-go/events/test"
79
)
810

911
func TestCloudwatchLogs(t *testing.T) {
@@ -24,7 +26,7 @@ func TestCloudwatchLogs(t *testing.T) {
2426
},
2527
} {
2628
t.Run(test.name, func(t *testing.T) {
27-
inputJson := readJsonFromFile(t, test.eventJson)
29+
inputJson := tst.ReadJSONFromFile(t, test.eventJson)
2830

2931
var inputEvent CloudwatchLogsEvent
3032
err := json.Unmarshal(inputJson, &inputEvent)
@@ -70,7 +72,7 @@ func TestCloudwatchLogsParse(t *testing.T) {
7072
},
7173
} {
7274
t.Run(test.name, func(t *testing.T) {
73-
inputJson := readJsonFromFile(t, test.eventJson)
75+
inputJson := tst.ReadJSONFromFile(t, test.eventJson)
7476

7577
var inputEvent CloudwatchLogsEvent
7678
if err := json.Unmarshal(inputJson, &inputEvent); err != nil {

events/connect_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
func TestConnectMarshaling(t *testing.T) {
1414

1515
// 1. read JSON from file
16-
inputJson := readJsonFromFile(t, "./testdata/connect-event.json")
16+
inputJson := test.ReadJSONFromFile(t, "./testdata/connect-event.json")
1717

1818
// 2. de-serialize into Go object
1919
var inputEvent ConnectEvent

events/dynamodb_test.go

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ package events
44

55
import (
66
"encoding/json"
7-
"io/ioutil"
87
"testing"
98

109
"github.com/aws/aws-lambda-go/events/test"
@@ -14,7 +13,7 @@ import (
1413
func TestDynamoDBEventMarshaling(t *testing.T) {
1514

1615
// 1. read JSON from file
17-
inputJson := readJsonFromFile(t, "./testdata/dynamodb-event.json")
16+
inputJson := test.ReadJSONFromFile(t, "./testdata/dynamodb-event.json")
1817

1918
// 2. de-serialize into Go object
2019
var inputEvent DynamoDBEvent
@@ -35,12 +34,3 @@ func TestDynamoDBEventMarshaling(t *testing.T) {
3534
func TestDynamoDBEventMarshalingMalformedJson(t *testing.T) {
3635
test.TestMalformedJson(t, DynamoDBEvent{})
3736
}
38-
39-
func readJsonFromFile(t *testing.T, inputFile string) []byte {
40-
inputJson, err := ioutil.ReadFile(inputFile)
41-
if err != nil {
42-
t.Errorf("could not open test file. details: %v", err)
43-
}
44-
45-
return inputJson
46-
}

events/firehose_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func testFirehoseResponseMarshaling(t *testing.T) {
2222
func testMarshaling(t *testing.T, jsonFile string) {
2323

2424
// 1. read JSON from file
25-
inputJson := readJsonFromFile(t, jsonFile)
25+
inputJson := test.ReadJSONFromFile(t, jsonFile)
2626

2727
// 2. de-serialize into Go object
2828
var inputEvent KinesisFirehoseEvent
@@ -42,7 +42,7 @@ func testMarshaling(t *testing.T, jsonFile string) {
4242

4343
func TestSampleTransformation(t *testing.T) {
4444

45-
inputJson := readJsonFromFile(t, "./testdata/kinesis-firehose-event.json")
45+
inputJson := test.ReadJSONFromFile(t, "./testdata/kinesis-firehose-event.json")
4646

4747
// de-serialize into Go object
4848
var inputEvent KinesisFirehoseEvent

events/iot_button_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
func TestIoTButtonMalformedJson(t *testing.T) {
1313

1414
// 1. read JSON from file
15-
inputJson := readJsonFromFile(t, "./testdata/iot-button-event.json")
15+
inputJson := test.ReadJSONFromFile(t, "./testdata/iot-button-event.json")
1616

1717
// 2. de-serialize into Go object
1818
var inputEvent IoTButtonEvent

events/kinesis_analytics.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
3+
package events
4+
5+
type KinesisAnalyticsOutputDeliveryEvent struct {
6+
InvocationID string `json:"invocationId"`
7+
ApplicationARN string `json:"applicationArn"`
8+
Records []KinesisAnalyticsOutputDeliveryEventRecord `json:"records"`
9+
}
10+
11+
type KinesisAnalyticsOutputDeliveryEventRecord struct {
12+
RecordID string `json:"recordId"`
13+
Data []byte `json:"data"`
14+
}
15+
16+
type KinesisAnalyticsOutputDeliveryResponse struct {
17+
Records []KinesisAnalyticsOutputDeliveryResponseRecord `json:"records"`
18+
}
19+
20+
const (
21+
KinesisAnalyticsOutputDeliveryOK = "Ok"
22+
KinesisAnalyticsOutputDeliveryFailed = "DeliveryFailed"
23+
)
24+
25+
type KinesisAnalyticsOutputDeliveryResponseRecord struct {
26+
RecordID string `json:"recordId"`
27+
Result string `json:"result"` //possible values include Ok and DeliveryFailed
28+
}

events/kinesis_analytics_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
package events
3+
4+
import (
5+
"encoding/json"
6+
"testing"
7+
8+
"github.com/aws/aws-lambda-go/events/test"
9+
"github.com/stretchr/testify/assert"
10+
)
11+
12+
func TestKinesisAnalyticsOutputDeliveryEventMarshaling(t *testing.T) {
13+
testKinesisAnalyticsOutputMarshaling(t, KinesisAnalyticsOutputDeliveryEvent{}, "./testdata/kinesis-analytics-output-delivery-event.json")
14+
}
15+
16+
func TestKinesisAnalyticsOutputDeliveryResponseMarshaling(t *testing.T) {
17+
testKinesisAnalyticsOutputMarshaling(t, KinesisAnalyticsOutputDeliveryResponse{}, "./testdata/kinesis-analytics-output-delivery-response.json")
18+
}
19+
20+
func TestKinesisOutputDeliveryEventMarshalingMalformedJson(t *testing.T) {
21+
test.TestMalformedJson(t, KinesisAnalyticsOutputDeliveryEvent{})
22+
}
23+
24+
func testKinesisAnalyticsOutputMarshaling(t *testing.T, inputEvent interface{}, jsonFile string) {
25+
26+
// 1. read JSON from file
27+
inputJSON := test.ReadJSONFromFile(t, jsonFile)
28+
29+
// 2. de-serialize into Go object
30+
if err := json.Unmarshal(inputJSON, &inputEvent); err != nil {
31+
t.Errorf("could not unmarshal event. details: %v", err)
32+
}
33+
34+
// 3. serialize to JSON
35+
outputJSON, err := json.Marshal(inputEvent)
36+
if err != nil {
37+
t.Errorf("could not marshal event. details: %v", err)
38+
}
39+
40+
// 4. check result
41+
assert.JSONEq(t, string(inputJSON), string(outputJSON))
42+
}

events/kinesis_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
func TestKinesisEventMarshaling(t *testing.T) {
1313

1414
// 1. read JSON from file
15-
inputJson := readJsonFromFile(t, "./testdata/kinesis-event.json")
15+
inputJson := test.ReadJSONFromFile(t, "./testdata/kinesis-event.json")
1616

1717
// 2. de-serialize into Go object
1818
var inputEvent KinesisEvent

events/lex_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func TestLexEventMarshaling(t *testing.T) {
1414
}{{"./testdata/lex-response.json"}, {"./testdata/lex-event.json"}}
1515

1616
for _, te := range tests {
17-
inputJSON := readJsonFromFile(t, te.filePath)
17+
inputJSON := test.ReadJSONFromFile(t, te.filePath)
1818

1919
var inputEvent LexEvent
2020
if err := json.Unmarshal(inputJSON, &inputEvent); err != nil {

events/s3_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
func TestS3EventMarshaling(t *testing.T) {
1313

1414
// 1. read JSON from file
15-
inputJSON := readJsonFromFile(t, "./testdata/s3-event.json")
15+
inputJSON := test.ReadJSONFromFile(t, "./testdata/s3-event.json")
1616

1717
// 2. de-serialize into Go object
1818
var inputEvent S3Event

events/ses_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
)
1010

1111
func TestSESEventMarshaling(t *testing.T) {
12-
inputJSON := readJsonFromFile(t, "./testdata/ses-event.json")
12+
inputJSON := test.ReadJSONFromFile(t, "./testdata/ses-event.json")
1313

1414
var inputEvent SimpleEmailEvent
1515
if err := json.Unmarshal(inputJSON, &inputEvent); err != nil {

events/sns_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
func TestSnsEventMarshaling(t *testing.T) {
1313

1414
// 1. read JSON from file
15-
inputJson := readJsonFromFile(t, "./testdata/sns-event.json")
15+
inputJson := test.ReadJSONFromFile(t, "./testdata/sns-event.json")
1616

1717
// 2. de-serialize into Go object
1818
var inputEvent SNSEvent

events/sqs_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
func TestSqsEventMarshaling(t *testing.T) {
1313

1414
// 1. read JSON from file
15-
inputJson := readJsonFromFile(t, "./testdata/sqs-event.json")
15+
inputJson := test.ReadJSONFromFile(t, "./testdata/sqs-event.json")
1616

1717
// 2. de-serialize into Go object
1818
var inputEvent SQSEvent

events/test/readjson.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package test
2+
3+
import (
4+
"io/ioutil"
5+
"testing"
6+
)
7+
8+
func ReadJSONFromFile(t *testing.T, inputFile string) []byte {
9+
inputJSON, err := ioutil.ReadFile(inputFile)
10+
if err != nil {
11+
t.Errorf("could not open test file. details: %v", err)
12+
}
13+
14+
return inputJSON
15+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"invocationId": "invocationIdExample",
3+
"applicationArn": "arn:aws:kinesisanalytics:us-west-2:123456789012:application/example-application",
4+
"records": [
5+
{
6+
"recordId": "49571347871967966406409637155186850213682522142927749122",
7+
"data": "VGhpcyBpcyBhIHRlc3QgZnJvbSBLaW5lc2lzIEFuYWx5dGljcw=="
8+
}
9+
]
10+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"records": [
3+
{
4+
"recordId": "49571347871967966406409637155186850213682522142927749122",
5+
"result": "Ok"
6+
}
7+
]
8+
}

0 commit comments

Comments
 (0)