From 34f196bb4eada73b97d468d121f6fca55317417d Mon Sep 17 00:00:00 2001 From: shreyas-goenka <88374338+shreyas-goenka@users.noreply.github.com> Date: Tue, 25 Jul 2023 17:18:43 +0200 Subject: [PATCH] Add unit test that raw strings are printed as is (#599) ## Changes Add unit test that raw strings are printed as is. This method is useful to print text that would otherwise be interpreted a go text template. --- libs/template/helpers_test.go | 16 ++++++++++++++++ .../print-without-processing/template/hello.tmpl | 1 + 2 files changed, 17 insertions(+) create mode 100644 libs/template/testdata/print-without-processing/template/hello.tmpl diff --git a/libs/template/helpers_test.go b/libs/template/helpers_test.go index fbb66ae2a..51c470efc 100644 --- a/libs/template/helpers_test.go +++ b/libs/template/helpers_test.go @@ -2,12 +2,28 @@ package template import ( "context" + "strings" "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) +func TestTemplatePrintStringWithoutProcessing(t *testing.T) { + ctx := context.Background() + tmpDir := t.TempDir() + + r, err := newRenderer(ctx, nil, "./testdata/print-without-processing/template", "./testdata/print-without-processing/library", tmpDir) + require.NoError(t, err) + + err = r.walk() + assert.NoError(t, err) + + assert.Len(t, r.files, 1) + cleanContent := strings.Trim(string(r.files[0].content), "\n\r") + assert.Equal(t, `{{ fail "abc" }}`, cleanContent) +} + func TestTemplateRegexpCompileFunction(t *testing.T) { ctx := context.Background() tmpDir := t.TempDir() diff --git a/libs/template/testdata/print-without-processing/template/hello.tmpl b/libs/template/testdata/print-without-processing/template/hello.tmpl new file mode 100644 index 000000000..735d02099 --- /dev/null +++ b/libs/template/testdata/print-without-processing/template/hello.tmpl @@ -0,0 +1 @@ +{{`{{ fail "abc" }}`}}