github.com/Foodji/aws-lambda-go@v1.20.2/events/kinesis_analytics_test.go (about)

     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  }