Skip to content

Commit

Permalink
add exec.LookPath to check operator-sdk is in $PATH
Browse files Browse the repository at this point in the history
Signed-off-by: Adam D. Cornett <[email protected]>
  • Loading branch information
acornett21 committed Oct 21, 2024
1 parent 3a93f15 commit e64988a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions internal/operatorsdk/operatorsdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 8 additions & 0 deletions internal/operatorsdk/operatorsdk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"os/exec"
"path/filepath"
"testing"

"github.com/redhat-openshift-ecosystem/openshift-preflight/artifacts"
Expand All @@ -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() {
Expand Down

0 comments on commit e64988a

Please sign in to comment.