Skip to content

Commit

Permalink
fix: alpha generate command. If the output-dir path is not informed t…
Browse files Browse the repository at this point in the history
…han it should be the current directory
  • Loading branch information
camilamacedo86 committed Jan 17, 2025
1 parent 990251e commit da40c5e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
4 changes: 1 addition & 3 deletions pkg/cli/alpha/internal/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Check failure on line 240 in pkg/cli/alpha/internal/generate.go

View workflow job for this annotation

GitHub Actions / ubuntu-latest

fmt.Sprintf format %s reads arg #2, but call has 1 arg

Check failure on line 240 in pkg/cli/alpha/internal/generate.go

View workflow job for this annotation

GitHub Actions / golangci-lint

printf: fmt.Sprintf format %s reads arg #2, but call has 1 arg (govet)

Check failure on line 240 in pkg/cli/alpha/internal/generate.go

View workflow job for this annotation

GitHub Actions / macos-latest

fmt.Sprintf format %s reads arg #2, but call has 1 arg
}
if _, err := os.Stat(outputPath); err == nil {
return "", fmt.Errorf("output path %s already exists", outputPath)
Expand Down
21 changes: 14 additions & 7 deletions test/e2e/alphagenerate/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit da40c5e

Please sign in to comment.