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

     1  // Copyright 2017 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 TestIoTButtonMalformedJson(t *testing.T) {
    13  
    14  	// 1. read JSON from file
    15  	inputJson := test.ReadJSONFromFile(t, "./testdata/iot-button-event.json")
    16  
    17  	// 2. de-serialize into Go object
    18  	var inputEvent IoTButtonEvent
    19  	if err := json.Unmarshal(inputJson, &inputEvent); err != nil {
    20  		t.Errorf("could not unmarshal event. details: %v", err)
    21  	}
    22  
    23  	// 3. serialize to JSON
    24  	outputJson, err := json.Marshal(inputEvent)
    25  	if err != nil {
    26  		t.Errorf("could not marshal event. details: %v", err)
    27  	}
    28  	// 4. check result
    29  	assert.JSONEq(t, string(inputJson), string(outputJson))
    30  }
    31  
    32  func TestIoTButtonEventMarshaling(t *testing.T) {
    33  	test.TestMalformedJson(t, IoTButtonEvent{})
    34  }