github.com/Foodji/aws-lambda-go@v1.20.2/events/config_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 "io/ioutil" 7 "testing" 8 9 "github.com/aws/aws-lambda-go/events/test" 10 "github.com/stretchr/testify/assert" 11 ) 12 13 func TestConfigEventMarshaling(t *testing.T) { 14 // read json from file 15 inputJSON, err := ioutil.ReadFile("./testdata/config-event.json") 16 if err != nil { 17 t.Errorf("could not open test file. details: %v", err) 18 } 19 20 // de-serialize into Go object 21 var inputEvent ConfigEvent 22 if err := json.Unmarshal(inputJSON, &inputEvent); err != nil { 23 t.Errorf("could not unmarshal event. details: %v", err) 24 } 25 26 // serialize to json 27 outputJSON, err := json.Marshal(inputEvent) 28 if err != nil { 29 t.Errorf("could not marshal event. details: %v", err) 30 } 31 32 assert.JSONEq(t, string(inputJSON), string(outputJSON)) 33 } 34 35 func TestConfigMarshalingMalformedJson(t *testing.T) { 36 test.TestMalformedJson(t, ConfigEvent{}) 37 }