Skip to content

Commit

Permalink
Merge pull request #122 from albertorm95/support-body-fmt
Browse files Browse the repository at this point in the history
feat: Support body from fmt command
  • Loading branch information
drlau authored Dec 12, 2022
2 parents baca5ec + e9192df commit 1a2db90
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 13 deletions.
14 changes: 10 additions & 4 deletions terraform/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,15 @@ const (
{{ .Message }}
{{ .Result }}
{{if .Result}}
<pre><code>{{ .Result }}
</code></pre>
{{end}}
<details><summary>Details (Click me)</summary>
{{ .Body }}
<pre><code>{{ .Body }}
</code></pre></details>
`

// DefaultPlanTemplate is a default template for terraform plan
Expand Down Expand Up @@ -242,8 +248,8 @@ func (t *FmtTemplate) Execute() (string, error) {
data := map[string]interface{}{
"Title": t.Title,
"Message": t.Message,
"Result": "",
"Body": t.Result,
"Result": t.Result,
"Body": t.Body,
"Link": t.Link,
}

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 1a2db90

Please sign in to comment.