kubevela/e2e/cli.go

46 lines
1015 B
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"
"github.com/onsi/gomega/gexec"
)
var rudrPath = GetCliBinary()
2020-07-31 18:26:36 +08:00
//GetCliBinary is to build rudr 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() {
Exec("vela system init")
//Without this line, will hit issue like `<string>: Error: unknown command "scale" for "vela"`
Exec("vela system update")
AsyncExec("vela dashboard &")
2020-07-31 18:26:36 +08:00
}