Skip to content

Commit

Permalink
Test: Update template_test
Browse files Browse the repository at this point in the history
  • Loading branch information
albertorm95 committed Dec 12, 2022
1 parent ff6cc0b commit b01673c
Showing 1 changed file with 161 additions and 0 deletions.
161 changes: 161 additions & 0 deletions terraform/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,167 @@ b
}
}

func TestValidateTemplateExecute(t *testing.T) {
testCases := []struct {
template string
value CommonTemplate
resp string
}{
{
template: DefaultValidateTemplate,
value: CommonTemplate{},
resp: `
## Validate result
<details><summary>Details (Click me)</summary>
<pre><code>
</code></pre></details>
`,
},
{
template: DefaultValidateTemplate,
value: CommonTemplate{
Message: "message",
},
resp: `
## Validate result
message
<details><summary>Details (Click me)</summary>
<pre><code>
</code></pre></details>
`,
},
{
template: DefaultValidateTemplate,
value: CommonTemplate{
Title: "a",
Message: "b",
Result: "c",
Body: "d",
},
resp: `
a
b
<pre><code>c
</code></pre>
<details><summary>Details (Click me)</summary>
<pre><code>d
</code></pre></details>
`,
},
{
template: "",
value: CommonTemplate{
Title: "a",
Message: "b",
Result: "c",
Body: "d",
},
resp: `
a
b
<pre><code>c
</code></pre>
<details><summary>Details (Click me)</summary>
<pre><code>d
</code></pre></details>
`,
},
{
template: "",
value: CommonTemplate{
Title: "a",
Message: "b",
Result: `This is a "result".`,
Body: "d",
},
resp: `
a
b
<pre><code>This is a &#34;result&#34;.
</code></pre>
<details><summary>Details (Click me)</summary>
<pre><code>d
</code></pre></details>
`,
},
{
template: "",
value: CommonTemplate{
Title: "a",
Message: "b",
Result: `This is a "result".`,
Body: "d",
UseRawOutput: true,
},
resp: `
a
b
<pre><code>This is a "result".
</code></pre>
<details><summary>Details (Click me)</summary>
<pre><code>d
</code></pre></details>
`,
},
{
template: `{{ .Title }}-{{ .Message }}-{{ .Result }}-{{ .Body }}`,
value: CommonTemplate{
Title: "a",
Message: "b",
Result: "c",
Body: "d",
},
resp: `a-b-c-d`,
},
}
for _, testCase := range testCases {
template := NewValidateTemplate(testCase.template)
template.SetValue(testCase.value)
resp, err := template.Execute()
if err != nil {
t.Fatal(err)
}
if resp != testCase.resp {
t.Errorf("got %q but want %q", resp, testCase.resp)
}
}
}

func TestPlanTemplateExecute(t *testing.T) {
testCases := []struct {
template string
Expand Down

0 comments on commit b01673c

Please sign in to comment.