From e43d96c9e967d2efc74587b6b17916b685e9aa4e Mon Sep 17 00:00:00 2001 From: mayuka-c Date: Tue, 16 Sep 2025 07:29:17 +0530 Subject: [PATCH] Introduce Mockable getExecutablePath for Testing in Generate --- pkg/cli/alpha/internal/generate.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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 }