Skip to content

Commit

Permalink
fix: make sure that the filenames are created with slash to recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
majori committed Nov 15, 2024
1 parent 54c7af2 commit 2121bc9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion pkg/recipe/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package recipe
import (
"errors"
"maps"
"path/filepath"
"strings"

"github.com/gofrs/uuid"
Expand Down Expand Up @@ -72,7 +73,7 @@ func (re *Recipe) Execute(engine RenderEngine, values VariableValues, id uuid.UU
continue
}

filename = strings.TrimSuffix(filename, re.TemplateExtension)
filename = filepath.ToSlash(strings.TrimSuffix(filename, re.TemplateExtension))

sauce.Files[filename] = NewFile(content)
idx += 1
Expand Down
2 changes: 1 addition & 1 deletion test/features/execute-recipes.feature
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Feature: Execute recipes
And no errors were printed
Then execution of the recipe has succeeded
And CLI produced an output "docs[\S\s]+└── README"
And the project directory should contain file "docs[/|\\]README"
And the project directory should contain file "docs/README"
And the sauce in index 0 which should have property "Files.README"
And the sauce in index 0 which should have property "SubPath" with value "^docs$"

Expand Down
6 changes: 3 additions & 3 deletions test/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ func iClearTheOutput(ctx context.Context) (context.Context, error) {

func theProjectDirectoryShouldContainFile(ctx context.Context, filename string) error {
dir := ctx.Value(projectDirectoryPathCtxKey{}).(string)
info, err := os.Stat(filepath.Join(dir, filename))
info, err := os.Stat(filepath.Join(dir, filepath.Clean(filename)))
if err == nil && !info.Mode().IsRegular() {
return fmt.Errorf("%s is not a regular file", filename)
}
Expand All @@ -446,11 +446,11 @@ func theProjectDirectoryShouldContainFile(ctx context.Context, filename string)

func iCreateAFileWithContentsToTheProjectDir(ctx context.Context, filename, contents string) error {
dir := ctx.Value(projectDirectoryPathCtxKey{}).(string)
return os.WriteFile(filepath.Join(dir, filename), []byte(contents), 0644)
return os.WriteFile(filepath.Join(dir, filepath.Clean(filename)), []byte(contents), 0644)
}

func theProjectDirectoryShouldContainFileWith(ctx context.Context, filename, searchTerm string) error {
content, err := readProjectDirectoryFile(ctx, filename)
content, err := readProjectDirectoryFile(ctx, filepath.Clean(filename))
if err != nil {
return err
}
Expand Down

0 comments on commit 2121bc9

Please sign in to comment.