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 4816525
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 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
18 changes: 12 additions & 6 deletions test/e2e/alphagenerate/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,27 +68,27 @@ 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)
regenerateProject(kbc)
validateProjectFile(kbc, projectFilePath)
})

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 +185,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 4816525

Please sign in to comment.