about summary refs log tree commit diff
path: root/templater
diff options
context:
space:
mode:
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" }}