11package tftypes
22
33import (
4+ "fmt"
45 "math/big"
56 "testing"
67
@@ -10,9 +11,10 @@ import (
1011func TestValueFromJSON (t * testing.T ) {
1112 t .Parallel ()
1213 type testCase struct {
13- value Value
14- typ Type
15- json string
14+ value Value
15+ typ Type
16+ json string
17+ expectedError error
1618 }
1719 tests := map [string ]testCase {
1820 // Primitives
@@ -211,6 +213,30 @@ func TestValueFromJSON(t *testing.T) {
211213 },
212214 json : `{}` ,
213215 },
216+ "object-attribute-key-token-error" : {
217+ value : Value {},
218+ typ : Object {
219+ AttributeTypes : map [string ]Type {},
220+ },
221+ json : `{{}}` ,
222+ expectedError : AttributePathError {
223+ Path : NewAttributePath (),
224+ err : fmt .Errorf ("error reading object attribute key token: invalid character '{'" ),
225+ },
226+ },
227+ "object-attribute-key-missing-error" : {
228+ value : Value {},
229+ typ : Object {
230+ AttributeTypes : map [string ]Type {
231+ "test" : String ,
232+ },
233+ },
234+ json : `{"not-test": "test-value"}` ,
235+ expectedError : AttributePathError {
236+ Path : NewAttributePath ().WithAttributeName ("not-test" ),
237+ err : fmt .Errorf ("unsupported attribute \" not-test\" " ),
238+ },
239+ },
214240 "object-of-bool_number" : {
215241 value : NewValue (Object {
216242 AttributeTypes : map [string ]Type {
@@ -371,8 +397,8 @@ func TestValueFromJSON(t *testing.T) {
371397 t .Run (name , func (t * testing.T ) {
372398 t .Parallel ()
373399 val , err := ValueFromJSON ([]byte (test .json ), test .typ )
374- if err != nil {
375- t .Fatalf ("unexpected error unmarshaling : %s" , err )
400+ if diff := cmp . Diff ( test . expectedError , err ); diff != "" {
401+ t .Errorf ("unexpected error difference : %s" , diff )
376402 }
377403 if diff := cmp .Diff (test .value , val ); diff != "" {
378404 t .Errorf ("Unexpected results (-wanted +got): %s" , diff )
0 commit comments