Skip to content

Commit 2100507

Browse files
committed
Add unit tests for cli alpha generate.go
lint fix Modify Tests Minor-1 Minor fix Minor fix 1 Minor fix 2 Minor fix 3 Minor fix 4 Fix - 4 Comments - 1 Use testContext func Fix UT after rebase
1 parent 803e091 commit 2100507

File tree

2 files changed

+758
-2
lines changed

2 files changed

+758
-2
lines changed

pkg/cli/alpha/internal/generate.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ type Generate struct {
4343
OutputDir string
4444
}
4545

46+
// Define a variable to allow overriding the behavior of getExecutablePath for testing.
47+
var getExecutablePathFunc = getExecutablePath
48+
4649
// Generate handles the migration and scaffolding process.
4750
func (opts *Generate) Generate() error {
4851
projectConfig, err := common.LoadProjectConfig(opts.InputDir)
@@ -145,7 +148,7 @@ func (opts *Generate) Validate() error {
145148
return fmt.Errorf("error getting input path %q: %w", opts.InputDir, err)
146149
}
147150

148-
_, err = getExecutablePath()
151+
_, err = getExecutablePathFunc()
149152
if err != nil {
150153
return err
151154
}
@@ -189,7 +192,7 @@ func changeWorkingDirectory(outputDir string) error {
189192
// Initializes the project with Kubebuilder.
190193
func kubebuilderInit(s store.Store) error {
191194
args := append([]string{"init"}, getInitArgs(s)...)
192-
execPath, err := getExecutablePath()
195+
execPath, err := getExecutablePathFunc()
193196
if err != nil {
194197
return err
195198
}

0 commit comments

Comments
 (0)