Skip to content

Commit

Permalink
Ensure flux bin is on path
Browse files Browse the repository at this point in the history
  • Loading branch information
Callisto13 committed Jan 13, 2021
1 parent c2f7b09 commit 6a22b14
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
11 changes: 9 additions & 2 deletions pkg/flux/flux.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package flux

import (
"errors"
"fmt"
"io/ioutil"
"os"
"os/exec"

"github.com/kris-nova/logger"
api "github.com/weaveworks/eksctl/pkg/apis/eksctl.io/v1alpha5"
"github.com/weaveworks/eksctl/pkg/executor"
)

const fluxCommand = "flux"
const fluxBin = "flux"

type Client struct {
Executor executor.Executor
Expand Down Expand Up @@ -57,6 +59,11 @@ func setEnvVars(tokenPath, gitProvider string) []string {
}

func (c *Client) PreFlight() error {
if _, err := exec.LookPath(fluxBin); err != nil {
logger.Warning(err.Error())
return errors.New("flux not found, required")
}

return c.runFluxCmd("check", "--pre")
}

Expand All @@ -81,5 +88,5 @@ func (c *Client) Bootstrap(opts *api.Toolkit) error {

func (c *Client) runFluxCmd(args ...string) error {
logger.Debug(fmt.Sprintf("running flux %v ", args))
return c.Executor.Exec(fluxCommand, args...)
return c.Executor.Exec(fluxBin, args...)
}
20 changes: 19 additions & 1 deletion pkg/flux/flux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package flux_test

import (
"errors"
"os"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -29,7 +30,24 @@ var _ = Describe("Flux", func() {
Expect(receivedArgs).To(Equal([]string{"check", "--pre"}))
})

Context("when execution fails", func() {
When("the flux binary is not found on the path", func() {
var pathEnv string

BeforeEach(func() {
pathEnv = os.Getenv("PATH")
Expect(os.Unsetenv("PATH")).To(Succeed())
})

AfterEach(func() {
Expect(os.Setenv("PATH", pathEnv)).To(Succeed())
})

It("returns the error", func() {
Expect(fluxClient.PreFlight()).To(MatchError("flux not found, required"))
})
})

When("execution fails", func() {
BeforeEach(func() {
fakeExecutor.ExecReturns(errors.New("omg"))
})
Expand Down

0 comments on commit 6a22b14

Please sign in to comment.