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 3 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
5 changes: 5 additions & 0 deletions libs/template/materialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ func Materialize(ctx context.Context, configFilePath, templateRoot, outputDir st

// If the given templateRoot matches
func prepareBuiltinTemplates(templateRoot string, tempDir string) (string, error) {
// User specified CWD. They do not want to use any built-in templates.
if 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
7 changes: 7 additions & 0 deletions libs/template/renderer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ func assertBuiltinTemplateValid(t *testing.T, settings map[string]any, target st
}
}

func TestPrepareBuiltInTemplatesWithCWD(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)
}

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