Skip to content

Commit

Permalink
Fix DefaultFmtTemplate and TestPlanTemplateExecute
Browse files Browse the repository at this point in the history
  • Loading branch information
albertorm95 committed Dec 9, 2022
1 parent 23531a2 commit e9192df
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 10 deletions.
9 changes: 8 additions & 1 deletion terraform/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,17 @@ const (
DefaultFmtTemplate = `
{{ .Title }}
{{ .Message }}
{{if .Result}}
<pre><code>{{ .Result }}
</code></pre>
{{end}}
<details><summary>Details (Click me)</summary>
<pre><code>{{ .Body }}
</pre></code></details>
</code></pre></details>
`

// DefaultPlanTemplate is a default template for terraform plan
Expand Down
46 changes: 37 additions & 9 deletions terraform/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ b
</code></pre></details>
`,
},

{
template: "",
value: CommonTemplate{
Expand Down Expand Up @@ -193,7 +192,10 @@ func TestFmtTemplateExecute(t *testing.T) {
<details><summary>Details (Click me)</summary>
<pre><code>
</code></pre></details>
`,
},
{
Expand All @@ -208,7 +210,10 @@ message
<details><summary>Details (Click me)</summary>
<pre><code>
</code></pre></details>
`,
},
{
Expand All @@ -225,11 +230,16 @@ a
b
<pre><code>c
</code></pre>
c
<details><summary>Details (Click me)</summary>
<pre><code>d
</code></pre></details>
`,
},

{
template: "",
value: CommonTemplate{
Expand All @@ -244,8 +254,14 @@ a
b
<pre><code>c
</code></pre>
<details><summary>Details (Click me)</summary>
c
<pre><code>d
</code></pre></details>
`,
},
{
Expand All @@ -262,8 +278,14 @@ a
b
<pre><code>This is a &#34;result&#34;.
</code></pre>
<details><summary>Details (Click me)</summary>
This is a &#34;result&#34;.
<pre><code>d
</code></pre></details>
`,
},
{
Expand All @@ -281,19 +303,25 @@ a
b
<pre><code>This is a "result".
</code></pre>
This is a "result".
<details><summary>Details (Click me)</summary>
<pre><code>d
</code></pre></details>
`,
},
{
template: `{{ .Title }}-{{ .Message }}-{{ .Result }}-{{ .Body }}`,
value: CommonTemplate{
Title: "a",
Message: "b",
Result: "should be used as body",
Body: "should be empty",
Result: "c",
Body: "d",
},
resp: `a-b--should be used as body`,
resp: `a-b-c-d`,
},
}
for _, testCase := range testCases {
Expand Down

0 comments on commit e9192df

Please sign in to comment.