1// Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. 2package events 3 4import ( 5 "encoding/json" 6 "testing" 7 8 "github.com/aws/aws-lambda-go/events/test" 9 "github.com/stretchr/testify/assert" 10) 11 12func 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 32func TestIoTButtonEventMarshaling(t *testing.T) { 33 test.TestMalformedJson(t, IoTButtonEvent{}) 34} 35