@@ -190,11 +190,16 @@ func TestNewStruct_complex(t *testing.T) {
190
190
t .Parallel ()
191
191
192
192
type myStruct struct {
193
- Slice []string `tfsdk:"slice "`
194
- SliceOfStructs []struct {
193
+ ListSlice []string `tfsdk:"list_slice "`
194
+ ListSliceOfStructs []struct {
195
195
A string `tfsdk:"a"`
196
196
B int `tfsdk:"b"`
197
- } `tfsdk:"slice_of_structs"`
197
+ } `tfsdk:"list_slice_of_structs"`
198
+ SetSlice []string `tfsdk:"set_slice"`
199
+ SetSliceOfStructs []struct {
200
+ A string `tfsdk:"a"`
201
+ B int `tfsdk:"b"`
202
+ } `tfsdk:"set_slice_of_structs"`
198
203
Struct struct {
199
204
A bool `tfsdk:"a"`
200
205
Slice []float64 `tfsdk:"slice"`
@@ -211,10 +216,21 @@ func TestNewStruct_complex(t *testing.T) {
211
216
var s myStruct
212
217
result , diags := refl .Struct (context .Background (), types.ObjectType {
213
218
AttrTypes : map [string ]attr.Type {
214
- "slice " : types.ListType {
219
+ "list_slice " : types.ListType {
215
220
ElemType : types .StringType ,
216
221
},
217
- "slice_of_structs" : types.ListType {
222
+ "list_slice_of_structs" : types.ListType {
223
+ ElemType : types.ObjectType {
224
+ AttrTypes : map [string ]attr.Type {
225
+ "a" : types .StringType ,
226
+ "b" : types .NumberType ,
227
+ },
228
+ },
229
+ },
230
+ "set_slice" : types.SetType {
231
+ ElemType : types .StringType ,
232
+ },
233
+ "set_slice_of_structs" : types.SetType {
218
234
ElemType : types.ObjectType {
219
235
AttrTypes : map [string ]attr.Type {
220
236
"a" : types .StringType ,
@@ -245,10 +261,21 @@ func TestNewStruct_complex(t *testing.T) {
245
261
},
246
262
}, tftypes .NewValue (tftypes.Object {
247
263
AttributeTypes : map [string ]tftypes.Type {
248
- "slice " : tftypes.List {
264
+ "list_slice " : tftypes.List {
249
265
ElementType : tftypes .String ,
250
266
},
251
- "slice_of_structs" : tftypes.List {
267
+ "list_slice_of_structs" : tftypes.List {
268
+ ElementType : tftypes.Object {
269
+ AttributeTypes : map [string ]tftypes.Type {
270
+ "a" : tftypes .String ,
271
+ "b" : tftypes .Number ,
272
+ },
273
+ },
274
+ },
275
+ "set_slice" : tftypes.Set {
276
+ ElementType : tftypes .String ,
277
+ },
278
+ "set_slice_of_structs" : tftypes.Set {
252
279
ElementType : tftypes.Object {
253
280
AttributeTypes : map [string ]tftypes.Type {
254
281
"a" : tftypes .String ,
@@ -278,14 +305,48 @@ func TestNewStruct_complex(t *testing.T) {
278
305
"unhandled_unknown" : tftypes .String ,
279
306
},
280
307
}, map [string ]tftypes.Value {
281
- "slice" : tftypes .NewValue (tftypes.List {
308
+ "list_slice" : tftypes .NewValue (tftypes.List {
309
+ ElementType : tftypes .String ,
310
+ }, []tftypes.Value {
311
+ tftypes .NewValue (tftypes .String , "red" ),
312
+ tftypes .NewValue (tftypes .String , "blue" ),
313
+ tftypes .NewValue (tftypes .String , "green" ),
314
+ }),
315
+ "list_slice_of_structs" : tftypes .NewValue (tftypes.List {
316
+ ElementType : tftypes.Object {
317
+ AttributeTypes : map [string ]tftypes.Type {
318
+ "a" : tftypes .String ,
319
+ "b" : tftypes .Number ,
320
+ },
321
+ },
322
+ }, []tftypes.Value {
323
+ tftypes .NewValue (tftypes.Object {
324
+ AttributeTypes : map [string ]tftypes.Type {
325
+ "a" : tftypes .String ,
326
+ "b" : tftypes .Number ,
327
+ },
328
+ }, map [string ]tftypes.Value {
329
+ "a" : tftypes .NewValue (tftypes .String , "hello, world" ),
330
+ "b" : tftypes .NewValue (tftypes .Number , 123 ),
331
+ }),
332
+ tftypes .NewValue (tftypes.Object {
333
+ AttributeTypes : map [string ]tftypes.Type {
334
+ "a" : tftypes .String ,
335
+ "b" : tftypes .Number ,
336
+ },
337
+ }, map [string ]tftypes.Value {
338
+ "a" : tftypes .NewValue (tftypes .String , "goodnight, moon" ),
339
+ "b" : tftypes .NewValue (tftypes .Number , 456 ),
340
+ }),
341
+ }),
342
+ "set_slice" : tftypes .NewValue (tftypes.Set {
282
343
ElementType : tftypes .String ,
283
344
}, []tftypes.Value {
284
345
tftypes .NewValue (tftypes .String , "red" ),
285
346
tftypes .NewValue (tftypes .String , "blue" ),
286
347
tftypes .NewValue (tftypes .String , "green" ),
287
348
}),
288
- "slice_of_structs " : tftypes .NewValue (tftypes.List {
349
+ "set_slice_of_structs " : tftypes .NewValue (tftypes.Set {
289
350
ElementType : tftypes.Object {
290
351
AttributeTypes : map [string ]tftypes.Type {
291
352
"a" : tftypes .String ,
@@ -365,8 +426,22 @@ func TestNewStruct_complex(t *testing.T) {
365
426
}
366
427
str := "pointed"
367
428
expected := myStruct {
368
- Slice : []string {"red" , "blue" , "green" },
369
- SliceOfStructs : []struct {
429
+ ListSlice : []string {"red" , "blue" , "green" },
430
+ ListSliceOfStructs : []struct {
431
+ A string `tfsdk:"a"`
432
+ B int `tfsdk:"b"`
433
+ }{
434
+ {
435
+ A : "hello, world" ,
436
+ B : 123 ,
437
+ },
438
+ {
439
+ A : "goodnight, moon" ,
440
+ B : 456 ,
441
+ },
442
+ },
443
+ SetSlice : []string {"red" , "blue" , "green" },
444
+ SetSliceOfStructs : []struct {
370
445
A string `tfsdk:"a"`
371
446
B int `tfsdk:"b"`
372
447
}{
@@ -456,11 +531,16 @@ func TestFromStruct_complex(t *testing.T) {
456
531
t .Parallel ()
457
532
458
533
type myStruct struct {
459
- Slice []string `tfsdk:"slice"`
460
- SliceOfStructs []struct {
534
+ ListSlice []string `tfsdk:"list_slice"`
535
+ ListSliceOfStructs []struct {
536
+ A string `tfsdk:"a"`
537
+ B int `tfsdk:"b"`
538
+ } `tfsdk:"list_slice_of_structs"`
539
+ SetSlice []string `tfsdk:"set_slice"`
540
+ SetSliceOfStructs []struct {
461
541
A string `tfsdk:"a"`
462
542
B int `tfsdk:"b"`
463
- } `tfsdk:"slice_of_structs "`
543
+ } `tfsdk:"set_slice_of_structs "`
464
544
Struct struct {
465
545
A bool `tfsdk:"a"`
466
546
Slice []float64 `tfsdk:"slice"`
@@ -477,8 +557,22 @@ func TestFromStruct_complex(t *testing.T) {
477
557
}
478
558
str := "pointed"
479
559
s := myStruct {
480
- Slice : []string {"red" , "blue" , "green" },
481
- SliceOfStructs : []struct {
560
+ ListSlice : []string {"red" , "blue" , "green" },
561
+ ListSliceOfStructs : []struct {
562
+ A string `tfsdk:"a"`
563
+ B int `tfsdk:"b"`
564
+ }{
565
+ {
566
+ A : "hello, world" ,
567
+ B : 123 ,
568
+ },
569
+ {
570
+ A : "goodnight, moon" ,
571
+ B : 456 ,
572
+ },
573
+ },
574
+ SetSlice : []string {"red" , "blue" , "green" },
575
+ SetSliceOfStructs : []struct {
482
576
A string `tfsdk:"a"`
483
577
B int `tfsdk:"b"`
484
578
}{
@@ -521,10 +615,21 @@ func TestFromStruct_complex(t *testing.T) {
521
615
}
522
616
result , diags := refl .FromStruct (context .Background (), types.ObjectType {
523
617
AttrTypes : map [string ]attr.Type {
524
- "slice " : types.ListType {
618
+ "list_slice " : types.ListType {
525
619
ElemType : types .StringType ,
526
620
},
527
- "slice_of_structs" : types.ListType {
621
+ "list_slice_of_structs" : types.ListType {
622
+ ElemType : types.ObjectType {
623
+ AttrTypes : map [string ]attr.Type {
624
+ "a" : types .StringType ,
625
+ "b" : types .NumberType ,
626
+ },
627
+ },
628
+ },
629
+ "set_slice" : types.SetType {
630
+ ElemType : types .StringType ,
631
+ },
632
+ "set_slice_of_structs" : types.SetType {
528
633
ElemType : types.ObjectType {
529
634
AttrTypes : map [string ]attr.Type {
530
635
"a" : types .StringType ,
@@ -560,10 +665,21 @@ func TestFromStruct_complex(t *testing.T) {
560
665
}
561
666
expected := types.Object {
562
667
AttrTypes : map [string ]attr.Type {
563
- "slice" : types.ListType {
668
+ "list_slice" : types.ListType {
669
+ ElemType : types .StringType ,
670
+ },
671
+ "list_slice_of_structs" : types.ListType {
672
+ ElemType : types.ObjectType {
673
+ AttrTypes : map [string ]attr.Type {
674
+ "a" : types .StringType ,
675
+ "b" : types .NumberType ,
676
+ },
677
+ },
678
+ },
679
+ "set_slice" : types.SetType {
564
680
ElemType : types .StringType ,
565
681
},
566
- "slice_of_structs " : types.ListType {
682
+ "set_slice_of_structs " : types.SetType {
567
683
ElemType : types.ObjectType {
568
684
AttrTypes : map [string ]attr.Type {
569
685
"a" : types .StringType ,
@@ -594,15 +710,53 @@ func TestFromStruct_complex(t *testing.T) {
594
710
"uint" : types .NumberType ,
595
711
},
596
712
Attrs : map [string ]attr.Value {
597
- "slice" : types.List {
713
+ "list_slice" : types.List {
714
+ ElemType : types .StringType ,
715
+ Elems : []attr.Value {
716
+ types.String {Value : "red" },
717
+ types.String {Value : "blue" },
718
+ types.String {Value : "green" },
719
+ },
720
+ },
721
+ "list_slice_of_structs" : types.List {
722
+ ElemType : types.ObjectType {
723
+ AttrTypes : map [string ]attr.Type {
724
+ "a" : types .StringType ,
725
+ "b" : types .NumberType ,
726
+ },
727
+ },
728
+ Elems : []attr.Value {
729
+ types.Object {
730
+ AttrTypes : map [string ]attr.Type {
731
+ "a" : types .StringType ,
732
+ "b" : types .NumberType ,
733
+ },
734
+ Attrs : map [string ]attr.Value {
735
+ "a" : types.String {Value : "hello, world" },
736
+ "b" : types.Number {Value : big .NewFloat (123 )},
737
+ },
738
+ },
739
+ types.Object {
740
+ AttrTypes : map [string ]attr.Type {
741
+ "a" : types .StringType ,
742
+ "b" : types .NumberType ,
743
+ },
744
+ Attrs : map [string ]attr.Value {
745
+ "a" : types.String {Value : "goodnight, moon" },
746
+ "b" : types.Number {Value : big .NewFloat (456 )},
747
+ },
748
+ },
749
+ },
750
+ },
751
+ "set_slice" : types.Set {
598
752
ElemType : types .StringType ,
599
753
Elems : []attr.Value {
600
754
types.String {Value : "red" },
601
755
types.String {Value : "blue" },
602
756
types.String {Value : "green" },
603
757
},
604
758
},
605
- "slice_of_structs " : types.List {
759
+ "set_slice_of_structs " : types.Set {
606
760
ElemType : types.ObjectType {
607
761
AttrTypes : map [string ]attr.Type {
608
762
"a" : types .StringType ,
0 commit comments