2023-07-25 14:42:53 +00:00
|
|
|
package template
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2023-07-25 15:18:43 +00:00
|
|
|
"strings"
|
2023-07-25 14:42:53 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2023-07-25 15:18:43 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2023-07-25 14:42:53 +00:00
|
|
|
func TestTemplateRegexpCompileFunction(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
|
|
|
tmpDir := t.TempDir()
|
|
|
|
|
|
|
|
r, err := newRenderer(ctx, nil, "./testdata/regexp-compile/template", "./testdata/regexp-compile/library", tmpDir)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
err = r.walk()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
assert.Len(t, r.files, 1)
|
|
|
|
content := string(r.files[0].content)
|
|
|
|
assert.Contains(t, content, "0:food")
|
|
|
|
assert.Contains(t, content, "1:fool")
|
|
|
|
}
|
2023-07-27 09:51:31 +00:00
|
|
|
|
|
|
|
func TestTemplateUrlFunction(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
|
|
|
tmpDir := t.TempDir()
|
|
|
|
|
|
|
|
r, err := newRenderer(ctx, nil, "./testdata/urlparse-function/template", "./testdata/urlparse-function/library", tmpDir)
|
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
err = r.walk()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
assert.Len(t, r.files, 1)
|
|
|
|
assert.Equal(t, "https://www.databricks.com", string(r.files[0].content))
|
|
|
|
}
|