diff --git a/terraform/template_test.go b/terraform/template_test.go
index 8cccc6c..82c318d 100644
--- a/terraform/template_test.go
+++ b/terraform/template_test.go
@@ -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 (Click me)
+
+
+
+`,
+ },
+ {
+ template: DefaultValidateTemplate,
+ value: CommonTemplate{
+ Message: "message",
+ },
+ resp: `
+## Validate result
+
+message
+
+
+
+Details (Click me)
+
+
+
+`,
+ },
+ {
+ template: DefaultValidateTemplate,
+ value: CommonTemplate{
+ Title: "a",
+ Message: "b",
+ Result: "c",
+ Body: "d",
+ },
+ resp: `
+a
+
+b
+
+
+
c
+
+
+
+Details (Click me)
+
+d
+
+`,
+ },
+ {
+ template: "",
+ value: CommonTemplate{
+ Title: "a",
+ Message: "b",
+ Result: "c",
+ Body: "d",
+ },
+ resp: `
+a
+
+b
+
+
+c
+
+
+
+Details (Click me)
+
+d
+
+`,
+ },
+ {
+ template: "",
+ value: CommonTemplate{
+ Title: "a",
+ Message: "b",
+ Result: `This is a "result".`,
+ Body: "d",
+ },
+ resp: `
+a
+
+b
+
+
+This is a "result".
+
+
+
+Details (Click me)
+
+d
+
+`,
+ },
+ {
+ template: "",
+ value: CommonTemplate{
+ Title: "a",
+ Message: "b",
+ Result: `This is a "result".`,
+ Body: "d",
+ UseRawOutput: true,
+ },
+ resp: `
+a
+
+b
+
+
+This is a "result".
+
+
+
+Details (Click me)
+
+d
+
+`,
+ },
+ {
+ 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