This repository was archived by the owner on Nov 20, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +9
-6
lines changed Expand file tree Collapse file tree 2 files changed +9
-6
lines changed Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ func (t *TerraformCloudClient) GetStateVersionDownloadURL(workspaceID string) (s
2424
2525func convertValueToString (val cty.Value ) string {
2626 if val .IsNull () {
27- return ""
27+ return "null "
2828 }
2929 ty := val .Type ()
3030 switch {
@@ -76,17 +76,19 @@ func convertValueToString(val cty.Value) string {
7676 var b bytes.Buffer
7777
7878 i := 0
79+ valLen := val .LengthInt ()
7980 for it := val .ElementIterator (); it .Next (); {
8081 key , value := it .Element ()
8182 k := convertValueToString (key )
8283 v := convertValueToString (value )
8384 if k == "" || v == "" {
85+ valLen --
8486 continue
8587 }
8688 b .WriteString (k )
8789 b .WriteString (":" )
8890 b .WriteString (v )
89- if i < (val . LengthInt () - 1 ) {
91+ if i < (valLen - 1 ) {
9092 b .WriteString ("," )
9193 }
9294 i ++
@@ -109,19 +111,20 @@ func convertValueToString(val cty.Value) string {
109111
110112 var b bytes.Buffer
111113 i := 0
114+ atysLen := len (atys )
112115 for _ , attr := range attrNames {
113116 val := val .GetAttr (attr )
114117 v := convertValueToString (val )
115118 if v == "" {
119+ atysLen --
116120 continue
117121 }
118-
119122 b .WriteString (`"` )
120123 b .WriteString (attr )
121124 b .WriteString (`"` )
122125 b .WriteString (":" )
123126 b .WriteString (v )
124- if i < (len ( atys ) - 1 ) {
127+ if i < (atysLen - 1 ) {
125128 b .WriteString ("," )
126129 }
127130 i ++
Original file line number Diff line number Diff line change @@ -70,7 +70,7 @@ func TestShouldReturnStringFromObject(t *testing.T) {
7070}
7171
7272func TestShouldReturnEmptyStringFromNullObject (t * testing.T ) {
73- expected := ""
73+ expected := "null "
7474 value := cty .NullVal (cty .Map (cty .String ))
7575 formatted := convertValueToString (value )
7676 assert .Equal (t , expected , formatted )
@@ -126,7 +126,7 @@ func TestOutputsFromState(t *testing.T) {
126126 }
127127 }
128128 }` ,
129- want : []* v1alpha1.OutputStatus {},
129+ want : []* v1alpha1.OutputStatus {{ Key : "map1" , Value : "[{ \" null_map \" :null}]" } },
130130 },
131131 {
132132 name : "embedded JSON empty array returns no status" ,
You can’t perform that action at this time.
0 commit comments