kubevela/e2e/cli.go

47 lines
1.1 KiB
Go
Raw Normal View History

package e2e
2020-07-31 18:26:36 +08:00
import (
"os"
"os/exec"
"path"
"strings"
"time"
"github.com/onsi/ginkgo"
2020-09-26 12:58:30 +08:00
"github.com/onsi/gomega"
2020-07-31 18:26:36 +08:00
"github.com/onsi/gomega/gexec"
)
var rudrPath = GetCliBinary()
2020-07-31 18:26:36 +08:00
2020-09-11 17:52:14 +08:00
//GetCliBinary is to build kubevela binary.
func GetCliBinary() string {
2020-07-31 18:26:36 +08:00
cwd, _ := os.Getwd()
return path.Join(cwd, "../..", "./bin")
2020-07-31 18:26:36 +08:00
}
func Exec(cli string) (string, error) {
var output []byte
session, err := AsyncExec(cli)
2020-07-31 18:26:36 +08:00
if err != nil {
return string(output), err
}
s := session.Wait(10 * time.Second)
return string(s.Out.Contents()) + string(s.Err.Contents()), nil
}
2020-07-31 18:26:36 +08:00
func AsyncExec(cli string) (*gexec.Session, error) {
c := strings.Fields(cli)
commandName := path.Join(rudrPath, c[0])
command := exec.Command(commandName, c[1:]...)
session, err := gexec.Start(command, ginkgo.GinkgoWriter, ginkgo.GinkgoWriter)
return session, err
}
func BeforeSuit() {
2020-09-26 12:58:30 +08:00
_, err := Exec("vela install")
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
//Without this line, will hit issue like `<string>: Error: unknown command "scale" for "vela"`
2020-09-10 14:57:36 +08:00
_, _ = Exec("vela system update")
2020-07-31 18:26:36 +08:00
}