Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix template initialization from current working directory #976

Merged
merged 5 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions libs/template/materialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ func Materialize(ctx context.Context, configFilePath, templateRoot, outputDir st

// If the given templateRoot matches
func prepareBuiltinTemplates(templateRoot string, tempDir string) (string, error) {
// Check that `templateRoot` is a clean basename, i.e. `some_path` and not `./some_path` or "."
// Return early if that's not the case.
if templateRoot == "." || path.Base(templateRoot) != templateRoot {
return templateRoot, nil
}

shreyas-goenka marked this conversation as resolved.
Show resolved Hide resolved
_, err := fs.Stat(builtinTemplates, path.Join("templates", templateRoot))
if err != nil {
// The given path doesn't appear to be using out built-in templates
Expand Down
12 changes: 12 additions & 0 deletions libs/template/renderer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@ func assertBuiltinTemplateValid(t *testing.T, settings map[string]any, target st
}
}

func TestPrepareBuiltInTemplatesWithRelativePaths(t *testing.T) {
// CWD should not be resolved as a built in template
dir, err := prepareBuiltinTemplates(".", t.TempDir())
assert.NoError(t, err)
assert.Equal(t, ".", dir)

// relative path should not be resolved as a built in template
dir, err = prepareBuiltinTemplates("./default-python", t.TempDir())
assert.NoError(t, err)
assert.Equal(t, "./default-python", dir)
}

func TestBuiltinTemplateValid(t *testing.T) {
// Test option combinations
options := []string{"yes", "no"}
Expand Down