From da40c5e80149bafb14c35214e8ea26b148d202ef Mon Sep 17 00:00:00 2001 From: Camila Macedo <7708031+camilamacedo86@users.noreply.github.com> Date: Fri, 17 Jan 2025 18:48:35 +0000 Subject: [PATCH] fix: alpha generate command. If the output-dir path is not informed than it should be the current directory --- pkg/cli/alpha/internal/generate.go | 4 +--- test/e2e/alphagenerate/generate_test.go | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/pkg/cli/alpha/internal/generate.go b/pkg/cli/alpha/internal/generate.go index 192670e43c5..a968722b49c 100644 --- a/pkg/cli/alpha/internal/generate.go +++ b/pkg/cli/alpha/internal/generate.go @@ -44,8 +44,6 @@ type Generate struct { OutputDir string } -const defaultOutputDir = "output-dir" - // Generate handles the migration and scaffolding process. func (opts *Generate) Generate() error { config, err := loadProjectConfig(opts.InputDir) @@ -239,7 +237,7 @@ func getInputPath(currentWorkingDirectory, inputPath string) (string, error) { // Helper function to get output path. func getOutputPath(currentWorkingDirectory, outputPath string) (string, error) { if outputPath == "" { - outputPath = fmt.Sprintf("%s/%s", currentWorkingDirectory, defaultOutputDir) + outputPath = fmt.Sprintf("%s/%s", currentWorkingDirectory) } if _, err := os.Stat(outputPath); err == nil { return "", fmt.Errorf("output path %s already exists", outputPath) diff --git a/test/e2e/alphagenerate/generate_test.go b/test/e2e/alphagenerate/generate_test.go index 0e631f0ea25..1dfb6859946 100644 --- a/test/e2e/alphagenerate/generate_test.go +++ b/test/e2e/alphagenerate/generate_test.go @@ -68,27 +68,28 @@ var _ = Describe("kubebuilder", func() { kbc.Destroy() }) - It("should regenerate the project with success", func() { + It("should regenerate the project in current directory with success", func() { generateProject(kbc) - regenerateProject(kbc, projectOutputDir) - validateProjectFile(kbc, projectFilePath) + regenerateProject(kbc) + By("checking that the project file was generated in the current directory") + validateProjectFile(kbc, filepath.Join(kbc.Dir, "PROJECT")) }) It("should regenerate project with grafana plugin with success", func() { generateProjectWithGrafanaPlugin(kbc) - regenerateProject(kbc, projectOutputDir) + regenerateProjectWith(kbc, projectOutputDir) validateGrafanaPlugin(projectFilePath) }) It("should regenerate project with DeployImage plugin with success", func() { generateProjectWithDeployImagePlugin(kbc) - regenerateProject(kbc, projectOutputDir) + regenerateProjectWith(kbc, projectOutputDir) validateDeployImagePlugin(projectFilePath) }) It("should regenerate project with helm plugin with success", func() { generateProjectWithHelmPlugin(kbc) - regenerateProject(kbc, projectOutputDir) + regenerateProjectWith(kbc, projectOutputDir) validateHelmPlugin(projectFilePath) }) }) @@ -185,7 +186,13 @@ func generateProject(kbc *utils.TestContext) { Expect(err).NotTo(HaveOccurred(), "Failed to scaffold API with external API") } -func regenerateProject(kbc *utils.TestContext, projectOutputDir string) { +func regenerateProject(kbc *utils.TestContext) { + By("regenerating the project") + err := kbc.Regenerate() + Expect(err).NotTo(HaveOccurred(), "Failed to regenerate project") +} + +func regenerateProjectWith(kbc *utils.TestContext, projectOutputDir string) { By("regenerating the project") err := kbc.Regenerate( fmt.Sprintf("--input-dir=%s", kbc.Dir),