about summary refs log tree commit diff
path: root/templater
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@gmail.com>2018-07-14T19·40+0200
committerVincent Ambo <github@tazj.in>2018-07-14T21·21+0200
commitdf1a9a1625f01478b1ce6a5754363468f4342924 (patch)
treeacec7b145a8ffc30adce5221290a4ab509a311c9 /templater
parentab059ad41c7195e5c4a3f456b7f590d881884dcf (diff)
test(templater): Add a test for the `default` template function
Diffstat (limited to 'templater')
-rw-r--r--templater/templater_test.go17
-rw-r--r--templater/testdata/test-default.txt1
2 files changed, 18 insertions, 0 deletions
diff --git a/templater/templater_test.go b/templater/templater_test.go
index f6b12c758057..2a9ddaa2bb10 100644
--- a/templater/templater_test.go
+++ b/templater/templater_test.go
@@ -162,3 +162,20 @@ func TestFailOnMissingKeys(t *testing.T) {
 		t.Errorf("Templating failed with unexpected error: %v\n", err)
 	}
 }
+
+func TestDefaultTemplateFunction(t *testing.T) {
+	ctx := context.Context{}
+	resourceSet := context.ResourceSet{}
+
+	res, err := templateFile(&ctx, &resourceSet, "testdata/test-default.txt")
+
+	if err != nil {
+		t.Errorf("Templating with default values should have succeeded.\n")
+		t.Fail()
+	}
+
+	if res.Rendered != "defaultValue\n" {
+		t.Error("Result does not contain expected rendered default value.")
+		t.Fail()
+	}
+}
diff --git a/templater/testdata/test-default.txt b/templater/testdata/test-default.txt
new file mode 100644
index 000000000000..4f7997bd69d2
--- /dev/null
+++ b/templater/testdata/test-default.txt
@@ -0,0 +1 @@
+{{ default "defaultValue" "missingVar" }}