Use go module as dependency tool instead of glide
[src/xds/xds-server.git] / test / exec_test.go
index f4d1ac4..e7992d6 100644 (file)
@@ -23,8 +23,8 @@ import (
        "path"
        "testing"
 
-       "gerrit.automotivelinux.org/gerrit/src/xds/xds-server/lib/xsapiv1"
-       "github.com/stretchr/testify/assert"
+       "gerrit.automotivelinux.org/gerrit/src/xds/xds-server.git/lib/xsapiv1"
+       "github.com/stretchr/testify/require"
 )
 
 func InitExec(t *testing.T) string {
@@ -34,14 +34,14 @@ func InitExec(t *testing.T) string {
        cmd := exec.Command("cp", "-r", helloworldFixturesDir, helloworldDir)
        var out bytes.Buffer
        cmd.Stdout = &out
-       assert.Nil(t, cmd.Run())
+       require.Nil(t, cmd.Run())
 
        /*clone submodules app templates into helloworld*/
        subHelloworldAppTemplateDir := path.Join(helloworldDir, "conf.d", "app-templates")
        cmd = exec.Command("git", "clone", "-b", "flounder",
                "https://gerrit.automotivelinux.org/gerrit/p/apps/app-templates.git",
                subHelloworldAppTemplateDir)
-       assert.Nil(t, cmd.Run())
+       require.Nil(t, cmd.Run())
        return helloworldDir
 }
 
@@ -60,8 +60,8 @@ func TestExec(t *testing.T) {
 
        /*check there is no project*/
        var cfgArray []xsapiv1.FolderConfig
-       assert.Nil(t, HTTPCli.Get("/folders", &cfgArray))
-       assert.Equal(t, len(cfgArray), 0)
+       require.Nil(t, HTTPCli.Get("/folders", &cfgArray))
+       require.Equal(t, len(cfgArray), 0)
 
        fPrj := xsapiv1.FolderConfig{
                Label:      "testproject",
@@ -74,8 +74,8 @@ func TestExec(t *testing.T) {
        }
        /*create project*/
        var cfg xsapiv1.FolderConfig
-       assert.Nil(t, HTTPCli.Post("/folders", fPrj, &cfg))
-       assert.NotNil(t, cfg)
+       require.Nil(t, HTTPCli.Post("/folders", fPrj, &cfg))
+       require.NotNil(t, cfg)
 
        /*channel for ExecExitMsg*/
        chExec := make(chan xsapiv1.ExecExitMsg)
@@ -89,20 +89,30 @@ func TestExec(t *testing.T) {
        sCli.Conn.On(xsapiv1.ExecOutEvent, func(ev xsapiv1.ExecOutMsg) {
                cmdOut += ev.Stdout + ev.Stderr
        })
-
-       /*basic check: verify that environment is set correctly (use the right sdk)*/
+       /*error when exec with fakeid*/
        var execRes xsapiv1.ExecArgs
        cmd := "pwd && echo \"SDKTARGETSYSROOT=<$SDKTARGETSYSROOT>\""
        exec := xsapiv1.ExecArgs{
+               ID:    cfg.ID,
+               Cmd:   cmd,
+               SdkID: "11111-invalid",
+       }
+       Debugf(t, "exec cmake cmd(%v)", cmd)
+       cmdOut = ""
+       require.NotNil(t, HTTPCli.Post("/exec", exec, &execRes))
+
+       /*basic check: verify that environment is set correctly (use the right sdk)*/
+       cmd = "pwd && echo \"SDKTARGETSYSROOT=<$SDKTARGETSYSROOT>\""
+       exec = xsapiv1.ExecArgs{
                ID:    cfg.ID,
                Cmd:   cmd,
                SdkID: sdkRes.ID,
        }
        Debugf(t, "exec cmake cmd(%v)", cmd)
        cmdOut = ""
-       assert.Nil(t, HTTPCli.Post("/exec", exec, &execRes))
+       require.Nil(t, HTTPCli.Post("/exec", exec, &execRes))
        exitMsg := <-chExec
-       assert.Equal(t, exitMsg.Code, 0)
+       require.Equal(t, exitMsg.Code, 0)
 
        /*cmake helloworld project with fake sdk*/
        cmd = "cd " + fPrj.ClientPath
@@ -119,9 +129,9 @@ func TestExec(t *testing.T) {
                Cmd: cmd,
        }
        Debugf(t, "exec cmake cmd(%v)", cmd)
-       assert.Nil(t, HTTPCli.Post("/exec", exec, &execRes))
+       require.Nil(t, HTTPCli.Post("/exec", exec, &execRes))
        exitMsg = <-chExec
-       assert.Equal(t, exitMsg.Code, 0)
+       require.Equal(t, exitMsg.Code, 0)
 
        /*make helloworld project with fake sdk*/
        cmd = "cd " + fPrj.ClientPath
@@ -132,17 +142,17 @@ func TestExec(t *testing.T) {
        exec.Cmd = cmd
        /*post exec cmd make*/
        Debugf(t, "exec make cmd(%v)", cmd)
-       assert.Nil(t, HTTPCli.Post("/exec", exec, &execRes))
+       require.Nil(t, HTTPCli.Post("/exec", exec, &execRes))
        exitMsg = <-chExec
-       assert.Equal(t, exitMsg.Code, 0)
+       require.Equal(t, exitMsg.Code, 0)
 
        /*check if helloworld.so exists*/
        Debug(t, "check that helloworld.so exists")
        _, err := os.Stat(path.Join(fPrj.ClientPath, "build/helloworld/helloworld.so"))
-       assert.Nil(t, err)
+       require.Nil(t, err)
 
        /*deinit*/
-       assert.Nil(t, HTTPCli.Delete("/folders/"+cfg.ID, &cfg))
+       require.Nil(t, HTTPCli.Delete("/folders/"+cfg.ID, &cfg))
        RemoveSdk(t, sdkRes, chSdks)
        DisconnectSDKStateChange(t, sCli)
 }