X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?p=src%2Fxds%2Fxds-server.git;a=blobdiff_plain;f=test%2Fmain_test.go;h=bdea40c2347f972aa2e93f168758bb923b086eb5;hp=273df09a015d6f0d04cccb55852ecd924186df5c;hb=be47274f79eb0843da4d805cfc417fbf7921379c;hpb=4b57ec13022e836bdd8cb7f02b3d77f1924d4c35 diff --git a/test/main_test.go b/test/main_test.go index 273df09..bdea40c 100644 --- a/test/main_test.go +++ b/test/main_test.go @@ -82,6 +82,35 @@ func Copy(src, dst string) error { return out.Close() } +// init function will run once before execution of test functions begins. +func init() { + // Check dependency + err := checkTestDep() + if err != nil { + log.Fatal(err) + } +} + +// isCommandAvailable verify if a command/utility is available +func isCommandAvailable(name string) bool { + cmd := exec.Command("/bin/sh", "-c", "command -v "+name) + if err := cmd.Run(); err != nil { + return false + } + return true +} + +// checkTestDep checks if all dependency tools are available to be able to run tests +func checkTestDep() error { + for _, cmd := range dependency_tools { + if !isCommandAvailable(cmd) { + return fmt.Errorf(cmd + " is not installed and is mandatory to run tests") + } + } + return nil +} + +// initEnv func initEnv(launchProcess bool) { if launchProcess { /*kill xds-server if needed*/ @@ -133,6 +162,7 @@ func launchXdsServer(proc **os.Process) *os.File { return file } +// getHTTPClient func getHTTPClient(lvl int) (*common.HTTPClient, *os.File) { logFile := logDir + logFileClient file, err := os.OpenFile(logFile, os.O_CREATE|os.O_WRONLY, 0644) @@ -192,7 +222,10 @@ func NewIoSocketClient(url, clientID string) (*IOSockClient, error) { log.Printf("Connect websocket with url=%v clientId=%v\n", prefixURL, HTTPCli.GetClientID()) return sCli, nil } + +// TestMain is the main entry point of testsuite func TestMain(m *testing.M) { + /* useful for debugging, preventing from launching xds-server * it can be launch separately */ launchProcess := true