From 2121bc95ecf297802f8cd6e32213d7e37b5493b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20Kivim=C3=A4ki?= Date: Fri, 15 Nov 2024 13:43:17 +0200 Subject: [PATCH] fix: make sure that the filenames are created with slash to recipe --- pkg/recipe/execute.go | 3 ++- test/features/execute-recipes.feature | 2 +- test/main_test.go | 6 +++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/pkg/recipe/execute.go b/pkg/recipe/execute.go index 207533b6..107bc7cd 100644 --- a/pkg/recipe/execute.go +++ b/pkg/recipe/execute.go @@ -3,6 +3,7 @@ package recipe import ( "errors" "maps" + "path/filepath" "strings" "github.com/gofrs/uuid" @@ -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 diff --git a/test/features/execute-recipes.feature b/test/features/execute-recipes.feature index a56faedd..d6afa443 100644 --- a/test/features/execute-recipes.feature +++ b/test/features/execute-recipes.feature @@ -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$" diff --git a/test/main_test.go b/test/main_test.go index 5907f5be..baf4ff9a 100644 --- a/test/main_test.go +++ b/test/main_test.go @@ -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) } @@ -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 }