diff --git a/events/autoscaling_test.go b/events/autoscaling_test.go index d00d7a7a..e32c2ccb 100644 --- a/events/autoscaling_test.go +++ b/events/autoscaling_test.go @@ -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 diff --git a/events/cloudwatch_logs_test.go b/events/cloudwatch_logs_test.go index 961c779a..1d60902f 100644 --- a/events/cloudwatch_logs_test.go +++ b/events/cloudwatch_logs_test.go @@ -4,6 +4,8 @@ import ( "encoding/json" "reflect" "testing" + + tst "github.com/aws/aws-lambda-go/events/test" ) func TestCloudwatchLogs(t *testing.T) { @@ -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) @@ -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 { diff --git a/events/connect_test.go b/events/connect_test.go index f288db84..e8f80288 100644 --- a/events/connect_test.go +++ b/events/connect_test.go @@ -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 diff --git a/events/dynamodb_test.go b/events/dynamodb_test.go index 3cb8d46e..1da0e7b2 100644 --- a/events/dynamodb_test.go +++ b/events/dynamodb_test.go @@ -4,7 +4,6 @@ package events import ( "encoding/json" - "io/ioutil" "testing" "github.com/aws/aws-lambda-go/events/test" @@ -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 @@ -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 -} diff --git a/events/firehose_test.go b/events/firehose_test.go index 5ca84ed8..0aef155d 100644 --- a/events/firehose_test.go +++ b/events/firehose_test.go @@ -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 @@ -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 diff --git a/events/iot_button_test.go b/events/iot_button_test.go index f00f9a25..78ba3c5f 100644 --- a/events/iot_button_test.go +++ b/events/iot_button_test.go @@ -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 diff --git a/events/kinesis_analytics.go b/events/kinesis_analytics.go new file mode 100644 index 00000000..d44a9519 --- /dev/null +++ b/events/kinesis_analytics.go @@ -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 +} diff --git a/events/kinesis_analytics_test.go b/events/kinesis_analytics_test.go new file mode 100644 index 00000000..14e91fe1 --- /dev/null +++ b/events/kinesis_analytics_test.go @@ -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)) +} diff --git a/events/kinesis_test.go b/events/kinesis_test.go index 474a01d0..11db4238 100644 --- a/events/kinesis_test.go +++ b/events/kinesis_test.go @@ -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 diff --git a/events/lex_test.go b/events/lex_test.go index d6416b98..75bd0671 100644 --- a/events/lex_test.go +++ b/events/lex_test.go @@ -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 { diff --git a/events/s3_test.go b/events/s3_test.go index f1d45ea4..cdaec90e 100644 --- a/events/s3_test.go +++ b/events/s3_test.go @@ -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 diff --git a/events/ses_test.go b/events/ses_test.go index c8e069bd..0c83dcbc 100644 --- a/events/ses_test.go +++ b/events/ses_test.go @@ -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 { diff --git a/events/sns_test.go b/events/sns_test.go index 09d60655..6773c8f8 100644 --- a/events/sns_test.go +++ b/events/sns_test.go @@ -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 diff --git a/events/sqs_test.go b/events/sqs_test.go index ea0f2e0c..cc87d673 100644 --- a/events/sqs_test.go +++ b/events/sqs_test.go @@ -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 diff --git a/events/test/readjson.go b/events/test/readjson.go new file mode 100644 index 00000000..ce7361ec --- /dev/null +++ b/events/test/readjson.go @@ -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 +} diff --git a/events/testdata/kinesis-analytics-output-delivery-event.json b/events/testdata/kinesis-analytics-output-delivery-event.json new file mode 100644 index 00000000..7d963737 --- /dev/null +++ b/events/testdata/kinesis-analytics-output-delivery-event.json @@ -0,0 +1,10 @@ +{ + "invocationId": "invocationIdExample", + "applicationArn": "arn:aws:kinesisanalytics:us-west-2:123456789012:application/example-application", + "records": [ + { + "recordId": "49571347871967966406409637155186850213682522142927749122", + "data": "VGhpcyBpcyBhIHRlc3QgZnJvbSBLaW5lc2lzIEFuYWx5dGljcw==" + } + ] +} \ No newline at end of file diff --git a/events/testdata/kinesis-analytics-output-delivery-response.json b/events/testdata/kinesis-analytics-output-delivery-response.json new file mode 100644 index 00000000..3b3de116 --- /dev/null +++ b/events/testdata/kinesis-analytics-output-delivery-response.json @@ -0,0 +1,8 @@ +{ + "records": [ + { + "recordId": "49571347871967966406409637155186850213682522142927749122", + "result": "Ok" + } + ] +} \ No newline at end of file