From b01673c6e1676c6fd1cd55212b7add480a9ff8bd Mon Sep 17 00:00:00 2001 From: Alberto Rojas Date: Fri, 9 Dec 2022 12:26:19 -0700 Subject: [PATCH] Test: Update template_test --- terraform/template_test.go | 161 +++++++++++++++++++++++++++++++++++++ 1 file changed, 161 insertions(+) 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