@@ -40,7 +40,7 @@ func TestPrimitiveTfType(t *testing.T) {
4040 t .Run (test .Value .GoString (), func (t * testing.T ) {
4141 t .Parallel ()
4242
43- got := PrimitiveTfValue (test .Value )
43+ got := ToTfValue (test .Value )
4444
4545 if diff := cmp .Diff (test .Want , got ); diff != "" {
4646 t .Errorf ("unexpected differences: %s" , diff )
@@ -147,35 +147,13 @@ func TestListTfType(t *testing.T) {
147147 }),
148148 }),
149149 },
150- {
151- Value : cty .ListVal ([]cty.Value {
152- cty .ObjectVal (map [string ]cty.Value {
153- "enforcement" : cty .NullVal (cty .String ),
154- }),
155- }),
156- Want : tftypes .NewValue (tftypes.List {
157- ElementType : tftypes.Object {
158- AttributeTypes : map [string ]tftypes.Type {
159- "enforcement" : tftypes .String ,
160- },
161- },
162- }, []tftypes.Value {
163- tftypes .NewValue (tftypes.Object {
164- AttributeTypes : map [string ]tftypes.Type {
165- "enforcement" : tftypes .String ,
166- },
167- }, map [string ]tftypes.Value {
168- "enforcement" : tftypes .NewValue (tftypes .String , nil ),
169- }),
170- }),
171- },
172150 }
173151
174152 for _ , test := range tests {
175153 t .Run (test .Value .GoString (), func (t * testing.T ) {
176154 t .Parallel ()
177155
178- got := ListTfValue (test .Value )
156+ got := ToTfValue (test .Value )
179157
180158 if diff := cmp .Diff (test .Want , got ); diff != "" {
181159 t .Errorf ("unexpected differences: %s" , diff )
@@ -223,13 +201,150 @@ func TestSetTfType(t *testing.T) {
223201 tftypes .NewValue (tftypes .Number , 200 ),
224202 }),
225203 },
204+ {
205+ Value : cty .SetVal ([]cty.Value {
206+ cty .ObjectVal (map [string ]cty.Value {
207+ "name" : cty .StringVal ("Alice" ),
208+ "breed" : cty .StringVal ("Beagle" ),
209+ "weight" : cty .NumberIntVal (20 ),
210+ "toys" : cty .SetVal ([]cty.Value {cty .StringVal ("ball" ), cty .StringVal ("rope" )}),
211+ }),
212+ cty .ObjectVal (map [string ]cty.Value {
213+ "name" : cty .StringVal ("Bobby" ),
214+ "breed" : cty .StringVal ("Golden" ),
215+ "weight" : cty .NumberIntVal (30 ),
216+ "toys" : cty .SetVal ([]cty.Value {cty .StringVal ("dummy" ), cty .StringVal ("frisbee" )}),
217+ }),
218+ }),
219+ Want : tftypes .NewValue (tftypes.Set {
220+ ElementType : tftypes.Object {
221+ AttributeTypes : map [string ]tftypes.Type {
222+ "name" : tftypes .String ,
223+ "breed" : tftypes .String ,
224+ "weight" : tftypes .Number ,
225+ "toys" : tftypes.Set {ElementType : tftypes .String },
226+ },
227+ },
228+ }, []tftypes.Value {
229+ tftypes .NewValue (tftypes.Object {
230+ AttributeTypes : map [string ]tftypes.Type {
231+ "name" : tftypes .String ,
232+ "breed" : tftypes .String ,
233+ "weight" : tftypes .Number ,
234+ "toys" : tftypes.Set {ElementType : tftypes .String },
235+ },
236+ }, map [string ]tftypes.Value {
237+ "name" : tftypes .NewValue (tftypes .String , "Alice" ),
238+ "breed" : tftypes .NewValue (tftypes .String , "Beagle" ),
239+ "weight" : tftypes .NewValue (tftypes .Number , 20 ),
240+ "toys" : tftypes .NewValue (tftypes.Set {ElementType : tftypes .String }, []tftypes.Value {
241+ tftypes .NewValue (tftypes .String , "ball" ),
242+ tftypes .NewValue (tftypes .String , "rope" ),
243+ }),
244+ }),
245+ tftypes .NewValue (tftypes.Object {
246+ AttributeTypes : map [string ]tftypes.Type {
247+ "name" : tftypes .String ,
248+ "breed" : tftypes .String ,
249+ "weight" : tftypes .Number ,
250+ "toys" : tftypes.Set {ElementType : tftypes .String },
251+ },
252+ }, map [string ]tftypes.Value {
253+ "name" : tftypes .NewValue (tftypes .String , "Bobby" ),
254+ "breed" : tftypes .NewValue (tftypes .String , "Golden" ),
255+ "weight" : tftypes .NewValue (tftypes .Number , 30 ),
256+ "toys" : tftypes .NewValue (tftypes.Set {ElementType : tftypes .String }, []tftypes.Value {
257+ tftypes .NewValue (tftypes .String , "dummy" ),
258+ tftypes .NewValue (tftypes .String , "frisbee" ),
259+ }),
260+ }),
261+ }),
262+ },
226263 }
227264
228265 for _ , test := range tests {
229266 t .Run (test .Value .GoString (), func (t * testing.T ) {
230267 t .Parallel ()
231268
232- got := SetTfValue (test .Value )
269+ got := ToTfValue (test .Value )
270+
271+ if diff := cmp .Diff (test .Want , got ); diff != "" {
272+ t .Errorf ("unexpected differences: %s" , diff )
273+ }
274+ })
275+ }
276+ }
277+
278+ func TestMapTfType (t * testing.T ) {
279+ t .Parallel ()
280+
281+ tests := []struct {
282+ Value cty.Value
283+ Want tftypes.Value
284+ }{
285+ {
286+ Value : cty .MapVal (map [string ]cty.Value {
287+ "foo" : cty .StringVal ("bar" ),
288+ "baz" : cty .StringVal ("qux" ),
289+ }),
290+ Want : tftypes .NewValue (tftypes.Map {
291+ ElementType : tftypes .String ,
292+ }, map [string ]tftypes.Value {
293+ "foo" : tftypes .NewValue (tftypes .String , "bar" ),
294+ "baz" : tftypes .NewValue (tftypes .String , "qux" ),
295+ }),
296+ },
297+ {
298+ Value : cty .MapVal (map [string ]cty.Value {
299+ "foo" : cty .MapVal (map [string ]cty.Value {
300+ "foo" : cty .StringVal ("bar" ),
301+ "baz" : cty .StringVal ("qux" ),
302+ }),
303+ }),
304+ Want : tftypes .NewValue (tftypes.Map {
305+ ElementType : tftypes.Map {
306+ ElementType : tftypes .String ,
307+ }}, map [string ]tftypes.Value {
308+ "foo" : tftypes .NewValue (tftypes.Map {
309+ ElementType : tftypes .String ,
310+ }, map [string ]tftypes.Value {
311+ "foo" : tftypes .NewValue (tftypes .String , "bar" ),
312+ "baz" : tftypes .NewValue (tftypes .String , "qux" ),
313+ }),
314+ }),
315+ },
316+ {
317+ Value : cty .MapVal (map [string ]cty.Value {
318+ "foo" : cty .ObjectVal (map [string ]cty.Value {
319+ "fruits" : cty .MapVal (map [string ]cty.Value {
320+ "ananas" : cty .StringVal ("pineapple" ),
321+ "erdbeere" : cty .StringVal ("strawberry" ),
322+ }),
323+ }),
324+ }),
325+ Want : tftypes .NewValue (tftypes.Map {
326+ ElementType : tftypes.Object {
327+ AttributeTypes : map [string ]tftypes.Type {
328+ "fruits" : tftypes.Map {ElementType : tftypes .String },
329+ }}}, map [string ]tftypes.Value {
330+ "foo" : tftypes .NewValue (tftypes.Object {
331+ AttributeTypes : map [string ]tftypes.Type {
332+ "fruits" : tftypes.Map {ElementType : tftypes .String },
333+ }}, map [string ]tftypes.Value {
334+ "fruits" : tftypes .NewValue (tftypes.Map {ElementType : tftypes .String }, map [string ]tftypes.Value {
335+ "ananas" : tftypes .NewValue (tftypes .String , "pineapple" ),
336+ "erdbeere" : tftypes .NewValue (tftypes .String , "strawberry" ),
337+ }),
338+ }),
339+ }),
340+ },
341+ }
342+
343+ for _ , test := range tests {
344+ t .Run (test .Value .GoString (), func (t * testing.T ) {
345+ t .Parallel ()
346+
347+ got := ToTfValue (test .Value )
233348
234349 if diff := cmp .Diff (test .Want , got ); diff != "" {
235350 t .Errorf ("unexpected differences: %s" , diff )
@@ -255,12 +370,12 @@ func TestTupleTfType(t *testing.T) {
255370 Value : cty .TupleVal ([]cty.Value {
256371 cty .StringVal ("apple" ),
257372 cty .NumberIntVal (5 ),
258- cty .StringVal ("kangaroo" ),
373+ cty .TupleVal ([]cty. Value { cty . StringVal ("banana" ), cty . StringVal ( "pineapple" )} ),
259374 }),
260- Want : tftypes .NewValue (tftypes.Tuple {ElementTypes : []tftypes.Type {tftypes .String , tftypes .Number , tftypes .String }}, []tftypes.Value {
375+ Want : tftypes .NewValue (tftypes.Tuple {ElementTypes : []tftypes.Type {tftypes .String , tftypes .Number , tftypes.Tuple { ElementTypes : []tftypes. Type { tftypes . String , tftypes . String }} }}, []tftypes.Value {
261376 tftypes .NewValue (tftypes .String , "apple" ),
262377 tftypes .NewValue (tftypes .Number , 5 ),
263- tftypes .NewValue (tftypes .String , "kangaroo" ),
378+ tftypes .NewValue (tftypes.Tuple { ElementTypes : []tftypes. Type { tftypes . String , tftypes . String }}, []tftypes. Value { tftypes . NewValue ( tftypes . String , "banana" ), tftypes . NewValue ( tftypes . String , "pineapple" )} ),
264379 }),
265380 },
266381 }
@@ -269,7 +384,7 @@ func TestTupleTfType(t *testing.T) {
269384 t .Run (test .Value .GoString (), func (t * testing.T ) {
270385 t .Parallel ()
271386
272- got := TupleTfValue (test .Value )
387+ got := ToTfValue (test .Value )
273388
274389 if diff := cmp .Diff (test .Want , got ); diff != "" {
275390 t .Errorf ("unexpected differences: %s" , diff )
@@ -410,7 +525,7 @@ func TestObjectTfType(t *testing.T) {
410525 t .Run (test .Value .GoString (), func (t * testing.T ) {
411526 t .Parallel ()
412527
413- got := ObjectTfValue (test .Value )
528+ got := ToTfValue (test .Value )
414529
415530 if diff := cmp .Diff (test .Want , got ); diff != "" {
416531 t .Errorf ("unexpected differences: %s" , diff )
0 commit comments