Skip to content

Feature/add kinesis analytics event #169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion events/autoscaling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestAutoScalingEventMarshaling(t *testing.T) {

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

// 2. de-serialize into Go object
var inputEvent AutoScalingEvent
Expand Down
6 changes: 4 additions & 2 deletions events/cloudwatch_logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"encoding/json"
"reflect"
"testing"

tst "github.com/aws/aws-lambda-go/events/test"
)

func TestCloudwatchLogs(t *testing.T) {
Expand All @@ -24,7 +26,7 @@ func TestCloudwatchLogs(t *testing.T) {
},
} {
t.Run(test.name, func(t *testing.T) {
inputJson := readJsonFromFile(t, test.eventJson)
inputJson := tst.ReadJSONFromFile(t, test.eventJson)

var inputEvent CloudwatchLogsEvent
err := json.Unmarshal(inputJson, &inputEvent)
Expand Down Expand Up @@ -70,7 +72,7 @@ func TestCloudwatchLogsParse(t *testing.T) {
},
} {
t.Run(test.name, func(t *testing.T) {
inputJson := readJsonFromFile(t, test.eventJson)
inputJson := tst.ReadJSONFromFile(t, test.eventJson)

var inputEvent CloudwatchLogsEvent
if err := json.Unmarshal(inputJson, &inputEvent); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion events/connect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
func TestConnectMarshaling(t *testing.T) {

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

// 2. de-serialize into Go object
var inputEvent ConnectEvent
Expand Down
12 changes: 1 addition & 11 deletions events/dynamodb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package events

import (
"encoding/json"
"io/ioutil"
"testing"

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

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

// 2. de-serialize into Go object
var inputEvent DynamoDBEvent
Expand All @@ -35,12 +34,3 @@ func TestDynamoDBEventMarshaling(t *testing.T) {
func TestDynamoDBEventMarshalingMalformedJson(t *testing.T) {
test.TestMalformedJson(t, DynamoDBEvent{})
}

func readJsonFromFile(t *testing.T, inputFile string) []byte {
inputJson, err := ioutil.ReadFile(inputFile)
if err != nil {
t.Errorf("could not open test file. details: %v", err)
}

return inputJson
}
4 changes: 2 additions & 2 deletions events/firehose_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func testFirehoseResponseMarshaling(t *testing.T) {
func testMarshaling(t *testing.T, jsonFile string) {

// 1. read JSON from file
inputJson := readJsonFromFile(t, jsonFile)
inputJson := test.ReadJSONFromFile(t, jsonFile)

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

func TestSampleTransformation(t *testing.T) {

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

// de-serialize into Go object
var inputEvent KinesisFirehoseEvent
Expand Down
2 changes: 1 addition & 1 deletion events/iot_button_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
func TestIoTButtonMalformedJson(t *testing.T) {

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

// 2. de-serialize into Go object
var inputEvent IoTButtonEvent
Expand Down
28 changes: 28 additions & 0 deletions events/kinesis_analytics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.

package events

type KinesisAnalyticsOutputDeliveryEvent struct {
InvocationID string `json:"invocationId"`
ApplicationARN string `json:"applicationArn"`
Records []KinesisAnalyticsOutputDeliveryEventRecord `json:"records"`
}

type KinesisAnalyticsOutputDeliveryEventRecord struct {
RecordID string `json:"recordId"`
Data []byte `json:"data"`
}

type KinesisAnalyticsOutputDeliveryResponse struct {
Records []KinesisAnalyticsOutputDeliveryResponseRecord `json:"records"`
}

const (
KinesisAnalyticsOutputDeliveryOK = "Ok"
KinesisAnalyticsOutputDeliveryFailed = "DeliveryFailed"
)

type KinesisAnalyticsOutputDeliveryResponseRecord struct {
RecordID string `json:"recordId"`
Result string `json:"result"` //possible values include Ok and DeliveryFailed
}
42 changes: 42 additions & 0 deletions events/kinesis_analytics_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
package events

import (
"encoding/json"
"testing"

"github.com/aws/aws-lambda-go/events/test"
"github.com/stretchr/testify/assert"
)

func TestKinesisAnalyticsOutputDeliveryEventMarshaling(t *testing.T) {
testKinesisAnalyticsOutputMarshaling(t, KinesisAnalyticsOutputDeliveryEvent{}, "./testdata/kinesis-analytics-output-delivery-event.json")
}

func TestKinesisAnalyticsOutputDeliveryResponseMarshaling(t *testing.T) {
testKinesisAnalyticsOutputMarshaling(t, KinesisAnalyticsOutputDeliveryResponse{}, "./testdata/kinesis-analytics-output-delivery-response.json")
}

func TestKinesisOutputDeliveryEventMarshalingMalformedJson(t *testing.T) {
test.TestMalformedJson(t, KinesisAnalyticsOutputDeliveryEvent{})
}

func testKinesisAnalyticsOutputMarshaling(t *testing.T, inputEvent interface{}, jsonFile string) {

// 1. read JSON from file
inputJSON := test.ReadJSONFromFile(t, jsonFile)

// 2. de-serialize into Go object
if err := json.Unmarshal(inputJSON, &inputEvent); err != nil {
t.Errorf("could not unmarshal event. details: %v", err)
}

// 3. serialize to JSON
outputJSON, err := json.Marshal(inputEvent)
if err != nil {
t.Errorf("could not marshal event. details: %v", err)
}

// 4. check result
assert.JSONEq(t, string(inputJSON), string(outputJSON))
}
2 changes: 1 addition & 1 deletion events/kinesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
func TestKinesisEventMarshaling(t *testing.T) {

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

// 2. de-serialize into Go object
var inputEvent KinesisEvent
Expand Down
2 changes: 1 addition & 1 deletion events/lex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestLexEventMarshaling(t *testing.T) {
}{{"./testdata/lex-response.json"}, {"./testdata/lex-event.json"}}

for _, te := range tests {
inputJSON := readJsonFromFile(t, te.filePath)
inputJSON := test.ReadJSONFromFile(t, te.filePath)

var inputEvent LexEvent
if err := json.Unmarshal(inputJSON, &inputEvent); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion events/s3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
func TestS3EventMarshaling(t *testing.T) {

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

// 2. de-serialize into Go object
var inputEvent S3Event
Expand Down
2 changes: 1 addition & 1 deletion events/ses_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

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

var inputEvent SimpleEmailEvent
if err := json.Unmarshal(inputJSON, &inputEvent); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion events/sns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
func TestSnsEventMarshaling(t *testing.T) {

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

// 2. de-serialize into Go object
var inputEvent SNSEvent
Expand Down
2 changes: 1 addition & 1 deletion events/sqs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
func TestSqsEventMarshaling(t *testing.T) {

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

// 2. de-serialize into Go object
var inputEvent SQSEvent
Expand Down
15 changes: 15 additions & 0 deletions events/test/readjson.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package test

import (
"io/ioutil"
"testing"
)

func ReadJSONFromFile(t *testing.T, inputFile string) []byte {
inputJSON, err := ioutil.ReadFile(inputFile)
if err != nil {
t.Errorf("could not open test file. details: %v", err)
}

return inputJSON
}
10 changes: 10 additions & 0 deletions events/testdata/kinesis-analytics-output-delivery-event.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"invocationId": "invocationIdExample",
"applicationArn": "arn:aws:kinesisanalytics:us-west-2:123456789012:application/example-application",
"records": [
{
"recordId": "49571347871967966406409637155186850213682522142927749122",
"data": "VGhpcyBpcyBhIHRlc3QgZnJvbSBLaW5lc2lzIEFuYWx5dGljcw=="
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"records": [
{
"recordId": "49571347871967966406409637155186850213682522142927749122",
"result": "Ok"
}
]
}