@@ -64,6 +64,9 @@ func TestUnmarshalNestedAllTypes(t *testing.T) {
6464 AttrListListString types.List `tfsdk:"attr_list_list_string"`
6565 AttrSetListObj types.Set `tfsdk:"attr_set_list_obj"`
6666 AttrListObjKnown types.List `tfsdk:"attr_list_obj_known"`
67+ AttrMapSimple types.Map `tfsdk:"attr_map_simple"`
68+ AttrMapSimpleExisting types.Map `tfsdk:"attr_map_simple_existing"`
69+ AttrMapObj types.Map `tfsdk:"attr_map_obj"`
6770 }
6871 model := modelst {
6972 AttrObj : types .ObjectValueMust (objTypeTest .AttrTypes , map [string ]attr.Value {
@@ -92,6 +95,12 @@ func TestUnmarshalNestedAllTypes(t *testing.T) {
9295 "attr_bool" : types .BoolValue (true ),
9396 }),
9497 }),
98+ AttrMapSimple : types .MapNull (types .StringType ),
99+ AttrMapSimpleExisting : types .MapValueMust (types .StringType , map [string ]attr.Value {
100+ "existing" : types .StringValue ("valexisting" ),
101+ "existingCHANGE" : types .StringValue ("before" ),
102+ }),
103+ AttrMapObj : types .MapUnknown (objTypeTest ),
95104 }
96105 // attrUnexisting is ignored because it is in JSON but not in the model, no error is returned
97106 const (
@@ -195,7 +204,29 @@ func TestUnmarshalNestedAllTypes(t *testing.T) {
195204 "attrString": "val2",
196205 "attrInt": 2
197206 }
198- ]
207+ ],
208+ "attrMapSimple": {
209+ "keyOne": "val1",
210+ "KeyTwo": "val2"
211+ },
212+ "attrMapSimpleExisting": {
213+ "key": "val",
214+ "existingCHANGE": "after"
215+ },
216+ "attrMapObj": {
217+ "obj1": {
218+ "attrString": "str1",
219+ "attrInt": 11,
220+ "attrFloat": 11.1,
221+ "attrBool": false
222+ },
223+ "obj2": {
224+ "attrString": "str2",
225+ "attrInt": 22,
226+ "attrFloat": 22.2,
227+ "attrBool": true
228+ }
229+ }
199230 }
200231 `
201232 )
@@ -321,6 +352,29 @@ func TestUnmarshalNestedAllTypes(t *testing.T) {
321352 "attr_bool" : types .BoolValue (true ),
322353 }),
323354 }),
355+ AttrMapSimple : types .MapValueMust (types .StringType , map [string ]attr.Value {
356+ "keyOne" : types .StringValue ("val1" ),
357+ "KeyTwo" : types .StringValue ("val2" ), // don't change the key case when it's a map
358+ }),
359+ AttrMapSimpleExisting : types .MapValueMust (types .StringType , map [string ]attr.Value {
360+ "key" : types .StringValue ("val" ),
361+ "existing" : types .StringValue ("valexisting" ), // existing map values are kept
362+ "existingCHANGE" : types .StringValue ("after" ), // existing map values are changed if in JSON
363+ }),
364+ AttrMapObj : types .MapValueMust (objTypeTest , map [string ]attr.Value {
365+ "obj1" : types .ObjectValueMust (objTypeTest .AttrTypes , map [string ]attr.Value {
366+ "attr_string" : types .StringValue ("str1" ),
367+ "attr_int" : types .Int64Value (11 ),
368+ "attr_float" : types .Float64Value (11.1 ),
369+ "attr_bool" : types .BoolValue (false ),
370+ }),
371+ "obj2" : types .ObjectValueMust (objTypeTest .AttrTypes , map [string ]attr.Value {
372+ "attr_string" : types .StringValue ("str2" ),
373+ "attr_int" : types .Int64Value (22 ),
374+ "attr_float" : types .Float64Value (22.2 ),
375+ "attr_bool" : types .BoolValue (true ),
376+ }),
377+ }),
324378 }
325379 require .NoError (t , autogen .Unmarshal ([]byte (jsonResp ), & model ))
326380 assert .Equal (t , modelExpected , model )
@@ -476,26 +530,3 @@ func TestUnmarshalUnsupportedModel(t *testing.T) {
476530 })
477531 }
478532}
479-
480- // TestUnmarshalUnsupportedResponse has JSON response types not supported yet.
481- // It will be updated when we add support for them.
482- func TestUnmarshalUnsupportedResponse (t * testing.T ) {
483- testCases := map [string ]struct {
484- model any
485- responseJSON string
486- errorStr string
487- }{
488- "JSON maps not supported yet" : {
489- model : & struct {
490- AttrMap types.Map `tfsdk:"attr_map"`
491- }{},
492- responseJSON : `{"attrMap": {"key": "value"}}` ,
493- errorStr : "unmarshal of attribute attr_map expects type MapType but got Object with value: map[key:value]" ,
494- },
495- }
496- for name , tc := range testCases {
497- t .Run (name , func (t * testing.T ) {
498- assert .ErrorContains (t , autogen .Unmarshal ([]byte (tc .responseJSON ), tc .model ), tc .errorStr )
499- })
500- }
501- }
0 commit comments