structured renderer: fix closing json tags when rendering with no symbols (#32642)

This commit is contained in:
Liam Cervante 2023-02-08 16:47:12 +01:00 committed by GitHub
parent 7ab4e6fe2d
commit 4fa7cd0a68
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View File

@ -217,7 +217,7 @@ func (renderer primitiveRenderer) renderStringDiffAsJson(diff computed.Diff, ind
} }
if strings.Contains(renderedJsonDiff, "\n") { if strings.Contains(renderedJsonDiff, "\n") {
return fmt.Sprintf("jsonencode(%s\n%s%s%s%s\n%s)%s", whitespace, formatIndent(indent+1), writeDiffActionSymbol(action, opts), renderedJsonDiff, replace, formatIndent(indent+1), nullSuffix(diff.Action, opts)) return fmt.Sprintf("jsonencode(%s\n%s%s%s%s\n%s%s)%s", whitespace, formatIndent(indent+1), writeDiffActionSymbol(action, opts), renderedJsonDiff, replace, formatIndent(indent), writeDiffActionSymbol(plans.NoOp, opts), nullSuffix(diff.Action, opts))
} }
return fmt.Sprintf("jsonencode(%s)%s%s", renderedJsonDiff, whitespace, replace) return fmt.Sprintf("jsonencode(%s)%s%s", renderedJsonDiff, whitespace, replace)
} }

View File

@ -2062,6 +2062,23 @@ jsonencode(
+ 0, + 0,
+ 1, + 1,
] ]
`,
},
"json_string_no_symbols": {
diff: computed.Diff{
Renderer: Primitive("{\"key\":\"value\"}", "{\"key\":\"value\"}", cty.String),
Action: plans.NoOp,
},
opts: computed.RenderHumanOpts{
HideDiffActionSymbols: true,
ShowUnchangedChildren: true,
},
expected: `
jsonencode(
{
key = "value"
}
)
`, `,
}, },
} }