diff --git a/internal/operatorsdk/operatorsdk.go b/internal/operatorsdk/operatorsdk.go index ffa1415c..ae5a9047 100644 --- a/internal/operatorsdk/operatorsdk.go +++ b/internal/operatorsdk/operatorsdk.go @@ -34,6 +34,12 @@ type execContext = func(name string, arg ...string) *exec.Cmd func (o operatorSdk) Scorecard(ctx context.Context, image string, opts OperatorSdkScorecardOptions) (*OperatorSdkScorecardReport, error) { logger := logr.FromContextOrDiscard(ctx) + // checking to make sure operator-sdk is in the $PATH + _, err := exec.LookPath("operator-sdk") + if err != nil { + return nil, err + } + cmdArgs := []string{"scorecard"} if opts.OutputFormat == "" { opts.OutputFormat = "json" diff --git a/internal/operatorsdk/operatorsdk_test.go b/internal/operatorsdk/operatorsdk_test.go index 49a0c838..e839dee9 100644 --- a/internal/operatorsdk/operatorsdk_test.go +++ b/internal/operatorsdk/operatorsdk_test.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "os/exec" + "path/filepath" "testing" "github.com/redhat-openshift-ecosystem/openshift-preflight/artifacts" @@ -29,6 +30,13 @@ var _ = Describe("OperatorSdk", func() { aw, err := artifacts.NewFilesystemWriter(artifacts.WithDirectory(tmpdir)) Expect(err).ToNot(HaveOccurred()) + err = os.WriteFile(filepath.Join(tmpdir, "operator-sdk"), []byte("testcontents"), 0o755) + Expect(err).ToNot(HaveOccurred()) + + // updating PATH env to include the directory created in the test + err = os.Setenv("PATH", os.Getenv("PATH")+":"+tmpdir) + Expect(err).ToNot(HaveOccurred()) + testcontext = artifacts.ContextWithWriter(context.Background(), aw) }) When("The Scorecard result is good", func() {