diff --git a/pkg/cli/alpha/internal/generate.go b/pkg/cli/alpha/internal/generate.go index 8de380ba7ef..17fda51c2c3 100644 --- a/pkg/cli/alpha/internal/generate.go +++ b/pkg/cli/alpha/internal/generate.go @@ -42,6 +42,9 @@ type Generate struct { OutputDir string } +// Define a variable to allow overriding the behavior of getExecutablePath for testing. +var getExecutablePathFunc = getExecutablePath + // Generate handles the migration and scaffolding process. func (opts *Generate) Generate() error { projectConfig, err := common.LoadProjectConfig(opts.InputDir) @@ -144,7 +147,7 @@ func (opts *Generate) Validate() error { return fmt.Errorf("error getting input path %q: %w", opts.InputDir, err) } - _, err = getExecutablePath() + _, err = getExecutablePathFunc() if err != nil { return err } @@ -188,7 +191,7 @@ func changeWorkingDirectory(outputDir string) error { // Initializes the project with Kubebuilder. func kubebuilderInit(s store.Store) error { args := append([]string{"init"}, getInitArgs(s)...) - execPath, err := getExecutablePath() + execPath, err := getExecutablePathFunc() if err != nil { return err }