kubevela/e2e/cli.go

55 lines
1.2 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/gomega"
2020-07-31 18:26:36 +08:00
"github.com/onsi/ginkgo"
"github.com/onsi/gomega/gexec"
)
var (
rudrPath = "/tmp"
2020-07-31 18:26:36 +08:00
)
//GetCliBinary is to build rudr binary.
func GetCliBinary() (string, error) {
cwd, _ := os.Getwd()
mainPath := path.Join(cwd, "../../cmd/vela/main.go")
2020-08-10 10:43:02 +08:00
cmd := exec.Command("go", "build", "-o", path.Join(rudrPath, "vela"), mainPath)
2020-07-31 18:26:36 +08:00
_, err := cmd.Output()
return rudrPath, err
}
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() {
_, err := GetCliBinary()
gomega.Expect(err).NotTo(gomega.HaveOccurred())
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
}