Skip to content

Commit da40c5e

Browse files
fix: alpha generate command. If the output-dir path is not informed than it should be the current directory
1 parent 990251e commit da40c5e

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

pkg/cli/alpha/internal/generate.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ type Generate struct {
4444
OutputDir string
4545
}
4646

47-
const defaultOutputDir = "output-dir"
48-
4947
// Generate handles the migration and scaffolding process.
5048
func (opts *Generate) Generate() error {
5149
config, err := loadProjectConfig(opts.InputDir)
@@ -239,7 +237,7 @@ func getInputPath(currentWorkingDirectory, inputPath string) (string, error) {
239237
// Helper function to get output path.
240238
func getOutputPath(currentWorkingDirectory, outputPath string) (string, error) {
241239
if outputPath == "" {
242-
outputPath = fmt.Sprintf("%s/%s", currentWorkingDirectory, defaultOutputDir)
240+
outputPath = fmt.Sprintf("%s/%s", currentWorkingDirectory)
243241
}
244242
if _, err := os.Stat(outputPath); err == nil {
245243
return "", fmt.Errorf("output path %s already exists", outputPath)

test/e2e/alphagenerate/generate_test.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,27 +68,28 @@ var _ = Describe("kubebuilder", func() {
6868
kbc.Destroy()
6969
})
7070

71-
It("should regenerate the project with success", func() {
71+
It("should regenerate the project in current directory with success", func() {
7272
generateProject(kbc)
73-
regenerateProject(kbc, projectOutputDir)
74-
validateProjectFile(kbc, projectFilePath)
73+
regenerateProject(kbc)
74+
By("checking that the project file was generated in the current directory")
75+
validateProjectFile(kbc, filepath.Join(kbc.Dir, "PROJECT"))
7576
})
7677

7778
It("should regenerate project with grafana plugin with success", func() {
7879
generateProjectWithGrafanaPlugin(kbc)
79-
regenerateProject(kbc, projectOutputDir)
80+
regenerateProjectWith(kbc, projectOutputDir)
8081
validateGrafanaPlugin(projectFilePath)
8182
})
8283

8384
It("should regenerate project with DeployImage plugin with success", func() {
8485
generateProjectWithDeployImagePlugin(kbc)
85-
regenerateProject(kbc, projectOutputDir)
86+
regenerateProjectWith(kbc, projectOutputDir)
8687
validateDeployImagePlugin(projectFilePath)
8788
})
8889

8990
It("should regenerate project with helm plugin with success", func() {
9091
generateProjectWithHelmPlugin(kbc)
91-
regenerateProject(kbc, projectOutputDir)
92+
regenerateProjectWith(kbc, projectOutputDir)
9293
validateHelmPlugin(projectFilePath)
9394
})
9495
})
@@ -185,7 +186,13 @@ func generateProject(kbc *utils.TestContext) {
185186
Expect(err).NotTo(HaveOccurred(), "Failed to scaffold API with external API")
186187
}
187188

188-
func regenerateProject(kbc *utils.TestContext, projectOutputDir string) {
189+
func regenerateProject(kbc *utils.TestContext) {
190+
By("regenerating the project")
191+
err := kbc.Regenerate()
192+
Expect(err).NotTo(HaveOccurred(), "Failed to regenerate project")
193+
}
194+
195+
func regenerateProjectWith(kbc *utils.TestContext, projectOutputDir string) {
189196
By("regenerating the project")
190197
err := kbc.Regenerate(
191198
fmt.Sprintf("--input-dir=%s", kbc.Dir),

0 commit comments

Comments
 (0)