Check dependency tools before running tests 79/17779/1 6.99.1 6.99.2 guppy/6.99.1 guppy/6.99.2 guppy_6.99.1 guppy_6.99.2
authorSebastien Douheret <sebastien.douheret@iot.bzh>
Tue, 6 Nov 2018 17:17:32 +0000 (18:17 +0100)
committerSebastien Douheret <sebastien.douheret@iot.bzh>
Tue, 6 Nov 2018 17:17:32 +0000 (18:17 +0100)
Add a check of all dependency tools before running tests in order to
report a clear error instead of a cryptic test failure.

Change-Id: I7b642428fb4ada7eec2de0c4c45f612ae6888b33
Signed-off-by: Sebastien Douheret <sebastien.douheret@iot.bzh>
test/config.go
test/main_test.go

index 0b3ce76..804b0b1 100644 (file)
@@ -33,3 +33,13 @@ const (
        helloworldFixturesDir    = "fixtures/helloworld"
        sshFixturesDir           = "fixtures/ssh"
 )
+
+var dependency_tools = [...]string{
+       "cmake",
+       "make",
+       "gcc",
+       "c++",
+       "python3",
+       "wget",
+       "jq",
+}
index 273df09..bdea40c 100644 (file)
@@ -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