From 7e1cef367ee42d82ed94ee09deedcdda2664ffa8 Mon Sep 17 00:00:00 2001 From: Charlie Voiselle <464492+angrycub@users.noreply.github.com> Date: Wed, 6 Sep 2023 17:28:11 -0400 Subject: [PATCH] Add test for converting map of objects --- sdk/pack/variables/convert_test.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/sdk/pack/variables/convert_test.go b/sdk/pack/variables/convert_test.go index 9fa85d4c..abe550a6 100644 --- a/sdk/pack/variables/convert_test.go +++ b/sdk/pack/variables/convert_test.go @@ -90,4 +90,31 @@ func TestConvertCtyToInterface(t *testing.T) { _, ok = tempMapOfMaps["test"].(map[string]any) must.True(t, ok) }) + + // test map of objects + t.Run("map of objects", func(t *testing.T) { + ci.Parallel(t) // Parallel has to be set on the subtest also + testMapOfObj := cty.MapVal(map[string]cty.Value{ + "t1": cty.ObjectVal(map[string]cty.Value{"b": cty.BoolVal(true)}), + "t2": cty.ObjectVal(map[string]cty.Value{"b": cty.BoolVal(false)}), + }) + + restMapOfObj, err := ConvertCtyToInterface(testMapOfObj) + must.NoError(t, err) + + tempMapOfObj, ok := restMapOfObj.(map[string]any) + must.True(t, ok) + + tp1, ok := tempMapOfObj["t1"].(map[string]any) + must.True(t, ok) + tp2, ok := tempMapOfObj["t2"].(map[string]any) + must.True(t, ok) + + b1, ok := tp1["b"].(bool) + must.True(t, ok) + must.True(t, b1) + b2, ok := tp2["b"].(bool) + must.True(t, ok) + must.False(t, b2) + }) }