@@ -205,11 +205,16 @@ func TestNewStruct_complex(t *testing.T) {
205
205
t .Parallel ()
206
206
207
207
type myStruct struct {
208
- Slice []string `tfsdk:"slice "`
209
- SliceOfStructs []struct {
208
+ ListSlice []string `tfsdk:"list_slice "`
209
+ ListSliceOfStructs []struct {
210
210
A string `tfsdk:"a"`
211
211
B int `tfsdk:"b"`
212
- } `tfsdk:"slice_of_structs"`
212
+ } `tfsdk:"list_slice_of_structs"`
213
+ SetSlice []string `tfsdk:"set_slice"`
214
+ SetSliceOfStructs []struct {
215
+ A string `tfsdk:"a"`
216
+ B int `tfsdk:"b"`
217
+ } `tfsdk:"set_slice_of_structs"`
213
218
Struct struct {
214
219
A bool `tfsdk:"a"`
215
220
Slice []float64 `tfsdk:"slice"`
@@ -226,10 +231,21 @@ func TestNewStruct_complex(t *testing.T) {
226
231
var s myStruct
227
232
result , diags := refl .Struct (context .Background (), types.ObjectType {
228
233
AttrTypes : map [string ]attr.Type {
229
- "slice " : types.ListType {
234
+ "list_slice " : types.ListType {
230
235
ElemType : types .StringType ,
231
236
},
232
- "slice_of_structs" : types.ListType {
237
+ "list_slice_of_structs" : types.ListType {
238
+ ElemType : types.ObjectType {
239
+ AttrTypes : map [string ]attr.Type {
240
+ "a" : types .StringType ,
241
+ "b" : types .NumberType ,
242
+ },
243
+ },
244
+ },
245
+ "set_slice" : types.SetType {
246
+ ElemType : types .StringType ,
247
+ },
248
+ "set_slice_of_structs" : types.SetType {
233
249
ElemType : types.ObjectType {
234
250
AttrTypes : map [string ]attr.Type {
235
251
"a" : types .StringType ,
@@ -260,10 +276,21 @@ func TestNewStruct_complex(t *testing.T) {
260
276
},
261
277
}, tftypes .NewValue (tftypes.Object {
262
278
AttributeTypes : map [string ]tftypes.Type {
263
- "slice " : tftypes.List {
279
+ "list_slice " : tftypes.List {
264
280
ElementType : tftypes .String ,
265
281
},
266
- "slice_of_structs" : tftypes.List {
282
+ "list_slice_of_structs" : tftypes.List {
283
+ ElementType : tftypes.Object {
284
+ AttributeTypes : map [string ]tftypes.Type {
285
+ "a" : tftypes .String ,
286
+ "b" : tftypes .Number ,
287
+ },
288
+ },
289
+ },
290
+ "set_slice" : tftypes.Set {
291
+ ElementType : tftypes .String ,
292
+ },
293
+ "set_slice_of_structs" : tftypes.Set {
267
294
ElementType : tftypes.Object {
268
295
AttributeTypes : map [string ]tftypes.Type {
269
296
"a" : tftypes .String ,
@@ -293,14 +320,48 @@ func TestNewStruct_complex(t *testing.T) {
293
320
"unhandled_unknown" : tftypes .String ,
294
321
},
295
322
}, map [string ]tftypes.Value {
296
- "slice" : tftypes .NewValue (tftypes.List {
323
+ "list_slice" : tftypes .NewValue (tftypes.List {
324
+ ElementType : tftypes .String ,
325
+ }, []tftypes.Value {
326
+ tftypes .NewValue (tftypes .String , "red" ),
327
+ tftypes .NewValue (tftypes .String , "blue" ),
328
+ tftypes .NewValue (tftypes .String , "green" ),
329
+ }),
330
+ "list_slice_of_structs" : tftypes .NewValue (tftypes.List {
331
+ ElementType : tftypes.Object {
332
+ AttributeTypes : map [string ]tftypes.Type {
333
+ "a" : tftypes .String ,
334
+ "b" : tftypes .Number ,
335
+ },
336
+ },
337
+ }, []tftypes.Value {
338
+ tftypes .NewValue (tftypes.Object {
339
+ AttributeTypes : map [string ]tftypes.Type {
340
+ "a" : tftypes .String ,
341
+ "b" : tftypes .Number ,
342
+ },
343
+ }, map [string ]tftypes.Value {
344
+ "a" : tftypes .NewValue (tftypes .String , "hello, world" ),
345
+ "b" : tftypes .NewValue (tftypes .Number , 123 ),
346
+ }),
347
+ tftypes .NewValue (tftypes.Object {
348
+ AttributeTypes : map [string ]tftypes.Type {
349
+ "a" : tftypes .String ,
350
+ "b" : tftypes .Number ,
351
+ },
352
+ }, map [string ]tftypes.Value {
353
+ "a" : tftypes .NewValue (tftypes .String , "goodnight, moon" ),
354
+ "b" : tftypes .NewValue (tftypes .Number , 456 ),
355
+ }),
356
+ }),
357
+ "set_slice" : tftypes .NewValue (tftypes.Set {
297
358
ElementType : tftypes .String ,
298
359
}, []tftypes.Value {
299
360
tftypes .NewValue (tftypes .String , "red" ),
300
361
tftypes .NewValue (tftypes .String , "blue" ),
301
362
tftypes .NewValue (tftypes .String , "green" ),
302
363
}),
303
- "slice_of_structs " : tftypes .NewValue (tftypes.List {
364
+ "set_slice_of_structs " : tftypes .NewValue (tftypes.Set {
304
365
ElementType : tftypes.Object {
305
366
AttributeTypes : map [string ]tftypes.Type {
306
367
"a" : tftypes .String ,
@@ -380,8 +441,22 @@ func TestNewStruct_complex(t *testing.T) {
380
441
}
381
442
str := "pointed"
382
443
expected := myStruct {
383
- Slice : []string {"red" , "blue" , "green" },
384
- SliceOfStructs : []struct {
444
+ ListSlice : []string {"red" , "blue" , "green" },
445
+ ListSliceOfStructs : []struct {
446
+ A string `tfsdk:"a"`
447
+ B int `tfsdk:"b"`
448
+ }{
449
+ {
450
+ A : "hello, world" ,
451
+ B : 123 ,
452
+ },
453
+ {
454
+ A : "goodnight, moon" ,
455
+ B : 456 ,
456
+ },
457
+ },
458
+ SetSlice : []string {"red" , "blue" , "green" },
459
+ SetSliceOfStructs : []struct {
385
460
A string `tfsdk:"a"`
386
461
B int `tfsdk:"b"`
387
462
}{
@@ -471,11 +546,16 @@ func TestFromStruct_complex(t *testing.T) {
471
546
t .Parallel ()
472
547
473
548
type myStruct struct {
474
- Slice []string `tfsdk:"slice"`
475
- SliceOfStructs []struct {
549
+ ListSlice []string `tfsdk:"list_slice"`
550
+ ListSliceOfStructs []struct {
551
+ A string `tfsdk:"a"`
552
+ B int `tfsdk:"b"`
553
+ } `tfsdk:"list_slice_of_structs"`
554
+ SetSlice []string `tfsdk:"set_slice"`
555
+ SetSliceOfStructs []struct {
476
556
A string `tfsdk:"a"`
477
557
B int `tfsdk:"b"`
478
- } `tfsdk:"slice_of_structs "`
558
+ } `tfsdk:"set_slice_of_structs "`
479
559
Struct struct {
480
560
A bool `tfsdk:"a"`
481
561
Slice []float64 `tfsdk:"slice"`
@@ -492,8 +572,22 @@ func TestFromStruct_complex(t *testing.T) {
492
572
}
493
573
str := "pointed"
494
574
s := myStruct {
495
- Slice : []string {"red" , "blue" , "green" },
496
- SliceOfStructs : []struct {
575
+ ListSlice : []string {"red" , "blue" , "green" },
576
+ ListSliceOfStructs : []struct {
577
+ A string `tfsdk:"a"`
578
+ B int `tfsdk:"b"`
579
+ }{
580
+ {
581
+ A : "hello, world" ,
582
+ B : 123 ,
583
+ },
584
+ {
585
+ A : "goodnight, moon" ,
586
+ B : 456 ,
587
+ },
588
+ },
589
+ SetSlice : []string {"red" , "blue" , "green" },
590
+ SetSliceOfStructs : []struct {
497
591
A string `tfsdk:"a"`
498
592
B int `tfsdk:"b"`
499
593
}{
@@ -536,10 +630,21 @@ func TestFromStruct_complex(t *testing.T) {
536
630
}
537
631
result , diags := refl .FromStruct (context .Background (), types.ObjectType {
538
632
AttrTypes : map [string ]attr.Type {
539
- "slice " : types.ListType {
633
+ "list_slice " : types.ListType {
540
634
ElemType : types .StringType ,
541
635
},
542
- "slice_of_structs" : types.ListType {
636
+ "list_slice_of_structs" : types.ListType {
637
+ ElemType : types.ObjectType {
638
+ AttrTypes : map [string ]attr.Type {
639
+ "a" : types .StringType ,
640
+ "b" : types .NumberType ,
641
+ },
642
+ },
643
+ },
644
+ "set_slice" : types.SetType {
645
+ ElemType : types .StringType ,
646
+ },
647
+ "set_slice_of_structs" : types.SetType {
543
648
ElemType : types.ObjectType {
544
649
AttrTypes : map [string ]attr.Type {
545
650
"a" : types .StringType ,
@@ -575,10 +680,21 @@ func TestFromStruct_complex(t *testing.T) {
575
680
}
576
681
expected := types.Object {
577
682
AttrTypes : map [string ]attr.Type {
578
- "slice" : types.ListType {
683
+ "list_slice" : types.ListType {
684
+ ElemType : types .StringType ,
685
+ },
686
+ "list_slice_of_structs" : types.ListType {
687
+ ElemType : types.ObjectType {
688
+ AttrTypes : map [string ]attr.Type {
689
+ "a" : types .StringType ,
690
+ "b" : types .NumberType ,
691
+ },
692
+ },
693
+ },
694
+ "set_slice" : types.SetType {
579
695
ElemType : types .StringType ,
580
696
},
581
- "slice_of_structs " : types.ListType {
697
+ "set_slice_of_structs " : types.SetType {
582
698
ElemType : types.ObjectType {
583
699
AttrTypes : map [string ]attr.Type {
584
700
"a" : types .StringType ,
@@ -609,15 +725,53 @@ func TestFromStruct_complex(t *testing.T) {
609
725
"uint" : types .NumberType ,
610
726
},
611
727
Attrs : map [string ]attr.Value {
612
- "slice" : types.List {
728
+ "list_slice" : types.List {
729
+ ElemType : types .StringType ,
730
+ Elems : []attr.Value {
731
+ types.String {Value : "red" },
732
+ types.String {Value : "blue" },
733
+ types.String {Value : "green" },
734
+ },
735
+ },
736
+ "list_slice_of_structs" : types.List {
737
+ ElemType : types.ObjectType {
738
+ AttrTypes : map [string ]attr.Type {
739
+ "a" : types .StringType ,
740
+ "b" : types .NumberType ,
741
+ },
742
+ },
743
+ Elems : []attr.Value {
744
+ types.Object {
745
+ AttrTypes : map [string ]attr.Type {
746
+ "a" : types .StringType ,
747
+ "b" : types .NumberType ,
748
+ },
749
+ Attrs : map [string ]attr.Value {
750
+ "a" : types.String {Value : "hello, world" },
751
+ "b" : types.Number {Value : big .NewFloat (123 )},
752
+ },
753
+ },
754
+ types.Object {
755
+ AttrTypes : map [string ]attr.Type {
756
+ "a" : types .StringType ,
757
+ "b" : types .NumberType ,
758
+ },
759
+ Attrs : map [string ]attr.Value {
760
+ "a" : types.String {Value : "goodnight, moon" },
761
+ "b" : types.Number {Value : big .NewFloat (456 )},
762
+ },
763
+ },
764
+ },
765
+ },
766
+ "set_slice" : types.Set {
613
767
ElemType : types .StringType ,
614
768
Elems : []attr.Value {
615
769
types.String {Value : "red" },
616
770
types.String {Value : "blue" },
617
771
types.String {Value : "green" },
618
772
},
619
773
},
620
- "slice_of_structs " : types.List {
774
+ "set_slice_of_structs " : types.Set {
621
775
ElemType : types.ObjectType {
622
776
AttrTypes : map [string ]attr.Type {
623
777
"a" : types .StringType ,
0 commit comments