Skip to content

Commit

Permalink
fix: panic when using relative paths with context=root (#732)
Browse files Browse the repository at this point in the history
  • Loading branch information
i4ki committed Nov 25, 2022
1 parent 8547f00 commit 46f6324
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
5 changes: 4 additions & 1 deletion generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,10 @@ func doRootGeneration(cfg *config.Tree) Report {
continue
}

targetDir := project.NewPath(path.Dir(block.Label))
// TODO(i4k): generate report must be redesigned for context=root
// Here we use path.Clean("/"+path.Dir(label)) to ensure the
// report.Dir is always absolute.
targetDir := project.NewPath(path.Clean("/" + path.Dir(block.Label)))
err = validateRootGenerateBlock(cfg, block)
if err != nil {
report.addFailure(targetDir, err)
Expand Down
23 changes: 23 additions & 0 deletions generate/generate_root_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,29 @@ func TestGenerateRootContext(t *testing.T) {
},
},
},
{
name: "generate.context=root must have absolute path in label",
configs: []hclconfig{
{
path: "/",
add: GenerateFile(
Labels("file.txt"),
Str("content", "test"),
Expr("context", "root"),
),
},
},
wantReport: generate.Report{
Failures: []generate.FailureResult{
{
Result: generate.Result{
Dir: "/",
},
Error: errors.E(generate.ErrInvalidGenBlockLabel),
},
},
},
},
{
name: "generate.context=root inside stack generating elsewhere",
layout: []string{
Expand Down

0 comments on commit 46f6324

Please sign in to comment.