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

     1  // Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
     2  
     3  package test
     4  
     5  import (
     6  	"encoding/json"
     7  	"testing"
     8  )
     9  
    10  func TestMalformedJson(t *testing.T, objectToDeserialize interface{}) {
    11  	// 1. read JSON from file
    12  	inputJson := GetMalformedJson()
    13  
    14  	// 2. de-serialize into Go object
    15  	err := json.Unmarshal(inputJson, objectToDeserialize)
    16  	if err == nil {
    17  		t.Errorf("unmarshal should have failed but succeeded instead")
    18  	}
    19  
    20  	_, isSyntaxError := err.(*json.SyntaxError)
    21  	if !isSyntaxError {
    22  		t.Errorf("unmarshal should have returned a json.SyntaxError")
    23  	}
    24  }