Files
kubevela/e2e/cli.go
2020-08-14 15:51:51 +08:00

50 lines
1.0 KiB
Go

package e2e
import (
"os"
"os/exec"
"path"
"strings"
"time"
"github.com/onsi/gomega"
"github.com/onsi/ginkgo"
"github.com/onsi/gomega/gexec"
)
var (
rudrPath = ""
)
//GetCliBinary is to build rudr binary.
func GetCliBinary() (string, error) {
cwd, _ := os.Getwd()
rudrPath = path.Join(cwd, "..")
mainPath := path.Join(rudrPath, "../cmd/vela/main.go")
cmd := exec.Command("go", "build", "-o", path.Join(rudrPath, "vela"), mainPath)
_, err := cmd.Output()
return rudrPath, err
}
func Exec(cli string) (string, error) {
c := strings.Fields(cli)
commandName := path.Join(rudrPath, c[0])
command := exec.Command(commandName, c[1:]...)
var output []byte
session, err := gexec.Start(command, ginkgo.GinkgoWriter, ginkgo.GinkgoWriter)
if err != nil {
return string(output), err
}
s := session.Wait(10 * time.Second)
return string(s.Out.Contents()) + string(s.Err.Contents()), nil
}
func BeforeSuit() {
_, err := GetCliBinary()
gomega.Expect(err).NotTo(gomega.HaveOccurred())
Exec("vela system:init")
}