aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClément Bénier <clement.benier@iot.bzh>2018-10-23 15:09:06 +0200
committerJan-Simon Moeller <jsmoeller@linuxfoundation.org>2018-10-24 10:43:37 +0000
commita740425411f120ff7263f16f268e7efd7c19b311 (patch)
tree4ef142dfb4b5c57648e4e00243a234b2ad31f086
parent3e3222406a6f015a9fee3720e8ba76ecf58b087f (diff)
testify: assert replace by require
require handles tests to be aborted during an assertion contrary to assert Change-Id: I3062046515c74509ae7ea1b24b7242a42d0191c1 Signed-off-by: Clément Bénier <clement.benier@iot.bzh>
-rw-r--r--test/config_test.go12
-rw-r--r--test/exec_test.go32
-rw-r--r--test/folders_test.go94
-rw-r--r--test/sdks_test.go62
-rw-r--r--test/target_test.go128
-rw-r--r--test/version_test.go8
6 files changed, 168 insertions, 168 deletions
diff --git a/test/config_test.go b/test/config_test.go
index 2b95e85..1b3120f 100644
--- a/test/config_test.go
+++ b/test/config_test.go
@@ -23,7 +23,7 @@ import (
"testing"
"gerrit.automotivelinux.org/gerrit/src/xds/xds-server/lib/xsapiv1"
- "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func CheckIP(ipconfig string) bool {
@@ -41,13 +41,13 @@ func CheckIP(ipconfig string) bool {
func TestConfig(t *testing.T) {
var cfg xsapiv1.APIConfig
- assert.Nil(t, HTTPCli.Get("/config", &cfg))
+ require.Nil(t, HTTPCli.Get("/config", &cfg))
Debugf(t, "Config is %v", cfg)
re := regexp.MustCompile("^[0-9a-z]+-[0-9a-z]+-[0-9a-z]+-[0-9a-z]+-[0-9a-z]+$")
- assert.True(t, re.MatchString(cfg.ServerUID)) //ID
+ require.True(t, re.MatchString(cfg.ServerUID)) //ID
pathMap, present := cfg.SupportedSharing["PathMap"]
- assert.True(t, present)
- assert.True(t, pathMap)
- assert.True(t, CheckIP(cfg.Builder.IP))
+ require.True(t, present)
+ require.True(t, pathMap)
+ require.True(t, CheckIP(cfg.Builder.IP))
}
diff --git a/test/exec_test.go b/test/exec_test.go
index 39f00c6..6ffc350 100644
--- a/test/exec_test.go
+++ b/test/exec_test.go
@@ -24,7 +24,7 @@ import (
"testing"
"gerrit.automotivelinux.org/gerrit/src/xds/xds-server/lib/xsapiv1"
- "github.com/stretchr/testify/assert"
+ "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)
@@ -99,7 +99,7 @@ func TestExec(t *testing.T) {
}
Debugf(t, "exec cmake cmd(%v)", cmd)
cmdOut = ""
- assert.NotNil(t, HTTPCli.Post("/exec", exec, &execRes))
+ 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>\""
@@ -110,9 +110,9 @@ func TestExec(t *testing.T) {
}
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
@@ -129,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
@@ -142,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)
}
diff --git a/test/folders_test.go b/test/folders_test.go
index 10f1dc6..eb74f7d 100644
--- a/test/folders_test.go
+++ b/test/folders_test.go
@@ -23,15 +23,15 @@ import (
"testing"
"gerrit.automotivelinux.org/gerrit/src/xds/xds-server/lib/xsapiv1"
- "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestFolders(t *testing.T) {
/*init: check there is no folder*/
Debug(t, "check there is no folder")
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",
@@ -44,56 +44,56 @@ func TestFolders(t *testing.T) {
}
var cfg xsapiv1.FolderConfig
Debugf(t, "create folder: \n%v", fPrj)
- assert.Nil(t, HTTPCli.Post("/folders", fPrj, &cfg))
- assert.NotNil(t, cfg)
+ require.Nil(t, HTTPCli.Post("/folders", fPrj, &cfg))
+ require.NotNil(t, cfg)
Debugf(t, "result folder: \n%v", cfg)
isCfgPrjMatch := func(fPrj xsapiv1.FolderConfig, cfg xsapiv1.FolderConfig) {
re := regexp.MustCompile("^[0-9a-z]+-[0-9a-z]+-[0-9a-z]+-[0-9a-z]+-[0-9a-z]+$")
- assert.True(t, re.MatchString(cfg.ID)) //ID
- assert.Equal(t, cfg.Label, fPrj.Label) //Label
- assert.Equal(t, cfg.ClientPath, fPrj.ClientPath)
- assert.Equal(t, cfg.Type, fPrj.Type)
- assert.Equal(t, cfg.Status, "Enable")
- assert.Equal(t, cfg.IsInSync, true)
- assert.Equal(t, len(cfg.DefaultSdk), 0)
- assert.Equal(t, fPrj.ClientData, cfg.ClientData)
- assert.Equal(t, fPrj.DataPathMap.ServerPath, cfg.DataPathMap.ServerPath)
+ require.True(t, re.MatchString(cfg.ID)) //ID
+ require.Equal(t, cfg.Label, fPrj.Label) //Label
+ require.Equal(t, cfg.ClientPath, fPrj.ClientPath)
+ require.Equal(t, cfg.Type, fPrj.Type)
+ require.Equal(t, cfg.Status, "Enable")
+ require.Equal(t, cfg.IsInSync, true)
+ require.Equal(t, len(cfg.DefaultSdk), 0)
+ require.Equal(t, fPrj.ClientData, cfg.ClientData)
+ require.Equal(t, fPrj.DataPathMap.ServerPath, cfg.DataPathMap.ServerPath)
}
isCfgPrjMatch(fPrj, cfg)
var cfg2 xsapiv1.FolderConfig
- assert.Nil(t, HTTPCli.Get("/folders/"+cfg.ID, &cfg2))
+ require.Nil(t, HTTPCli.Get("/folders/"+cfg.ID, &cfg2))
isCfgPrjMatch(fPrj, cfg2)
- assert.Nil(t, HTTPCli.Get("/folders", &cfgArray))
- assert.Equal(t, len(cfgArray), 1)
+ require.Nil(t, HTTPCli.Get("/folders", &cfgArray))
+ require.Equal(t, len(cfgArray), 1)
//call with the same uid create error
- assert.NotNil(t, HTTPCli.Post("/folders", cfg, &cfg))
+ require.NotNil(t, HTTPCli.Post("/folders", cfg, &cfg))
/*create/delete folders*/
var cfgArrayBis []xsapiv1.FolderConfig
- assert.Nil(t, HTTPCli.Post("/folders", fPrj, &cfg))
+ require.Nil(t, HTTPCli.Post("/folders", fPrj, &cfg))
Debugf(t, "create folder with id=%v", cfg.ID)
- assert.Nil(t, HTTPCli.Post("/folders", fPrj, &cfg))
+ require.Nil(t, HTTPCli.Post("/folders", fPrj, &cfg))
Debugf(t, "create folder with id=%v", cfg.ID)
- assert.Nil(t, HTTPCli.Get("/folders", &cfgArray))
- assert.Equal(t, len(cfgArray), 3)
- assert.Nil(t, HTTPCli.Delete("/folders/"+cfgArray[1].ID, &cfg))
+ require.Nil(t, HTTPCli.Get("/folders", &cfgArray))
+ require.Equal(t, len(cfgArray), 3)
+ require.Nil(t, HTTPCli.Delete("/folders/"+cfgArray[1].ID, &cfg))
Debugf(t, "delete folder with id=%v", cfg.ID)
- assert.Equal(t, cfg, cfgArray[1])
- assert.Nil(t, HTTPCli.Get("/folders", &cfgArrayBis))
- assert.Equal(t, len(cfgArrayBis), 2)
- assert.Nil(t, HTTPCli.Delete("/folders/"+cfgArray[0].ID, &cfg))
+ require.Equal(t, cfg, cfgArray[1])
+ require.Nil(t, HTTPCli.Get("/folders", &cfgArrayBis))
+ require.Equal(t, len(cfgArrayBis), 2)
+ require.Nil(t, HTTPCli.Delete("/folders/"+cfgArray[0].ID, &cfg))
Debugf(t, "delete folder with id=%v", cfg.ID)
- assert.Equal(t, cfg, cfgArray[0])
- assert.Nil(t, HTTPCli.Get("/folders", &cfgArrayBis))
- assert.Equal(t, len(cfgArrayBis), 1)
- assert.Nil(t, HTTPCli.Delete("/folders/"+cfgArray[2].ID, &cfg))
+ require.Equal(t, cfg, cfgArray[0])
+ require.Nil(t, HTTPCli.Get("/folders", &cfgArrayBis))
+ require.Equal(t, len(cfgArrayBis), 1)
+ require.Nil(t, HTTPCli.Delete("/folders/"+cfgArray[2].ID, &cfg))
Debugf(t, "delete folder with id=%v", cfg.ID)
- assert.Equal(t, cfg, cfgArray[2])
- assert.Nil(t, HTTPCli.Get("/folders", &cfgArrayBis))
- assert.Equal(t, len(cfgArrayBis), 0)
+ require.Equal(t, cfg, cfgArray[2])
+ require.Nil(t, HTTPCli.Get("/folders", &cfgArrayBis))
+ require.Equal(t, len(cfgArrayBis), 0)
}
func TestFoldersEmptyValues(t *testing.T) {
@@ -108,24 +108,24 @@ func TestFoldersEmptyValues(t *testing.T) {
}
var cfg xsapiv1.FolderConfig
/*ServerPath is empty*/
- assert.NotNil(t, HTTPCli.Post("/folders", fPrj, &cfg))
+ require.NotNil(t, HTTPCli.Post("/folders", fPrj, &cfg))
Debugf(t, "error while creating folder with empty serverpath \n%v", fPrj)
fPrj.DataPathMap.ServerPath = logDir + "sameserverpath"
fPrj.ClientPath = ""
/*ClientPath is Empty*/
- assert.NotNil(t, HTTPCli.Post("/folders", fPrj, &cfg))
+ require.NotNil(t, HTTPCli.Post("/folders", fPrj, &cfg))
Debugf(t, "error while creating folder with empty clientpath \n%v", fPrj)
fPrj.ClientPath = "logDir"
fPrj.Type = ""
/*Type is empty*/
- assert.NotNil(t, HTTPCli.Post("/folders", fPrj, &cfg))
+ require.NotNil(t, HTTPCli.Post("/folders", fPrj, &cfg))
Debugf(t, "error while creating folder with empty type \n%v", fPrj)
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)
}
func TestFoldersPathMapConfig(t *testing.T) {
@@ -141,7 +141,7 @@ func TestFoldersPathMapConfig(t *testing.T) {
}
var cfg xsapiv1.FolderConfig
/*file not present*/
- assert.NotNil(t, HTTPCli.Post("/folders", fPrj, &cfg))
+ require.NotNil(t, HTTPCli.Post("/folders", fPrj, &cfg))
Debugf(t, "error while creating folder with no checkfile \n%v", fPrj)
var checkFileClient = fPrj.ClientPath + "/checkfile"
@@ -159,29 +159,29 @@ func TestFoldersPathMapConfig(t *testing.T) {
Debug(t, err)
}
/*file content differ*/
- assert.NotNil(t, HTTPCli.Post("/folders", fPrj, &cfg))
+ require.NotNil(t, HTTPCli.Post("/folders", fPrj, &cfg))
Debugf(t, "error while creating folder with different checkfiles \n%v", fPrj)
/*write same message*/
if _, err := file.WriteString(fPrj.DataPathMap.CheckContent); err != nil {
Debug(t, err)
}
- assert.Nil(t, HTTPCli.Post("/folders", fPrj, &cfg))
+ require.Nil(t, HTTPCli.Post("/folders", fPrj, &cfg))
Debugf(t, "create folder with same checkfiles \n%v", fPrj)
/*check server msg: ServerUID needed*/
Debugf(t, "check server msg")
var APIcfg xsapiv1.APIConfig
- assert.Nil(t, HTTPCli.Get("/config", &APIcfg))
+ require.Nil(t, HTTPCli.Get("/config", &APIcfg))
msg := "Pathmap checked message written by xds-server ID: " + APIcfg.ServerUID + "\n"
data, err := ioutil.ReadAll(file)
if err != nil {
Debug(t, err)
}
- assert.Equal(t, msg, string(data))
+ require.Equal(t, msg, string(data))
- assert.Nil(t, HTTPCli.Delete("/folders/"+cfg.ID, &cfg))
+ require.Nil(t, HTTPCli.Delete("/folders/"+cfg.ID, &cfg))
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)
}
diff --git a/test/sdks_test.go b/test/sdks_test.go
index 1395b16..15f78a3 100644
--- a/test/sdks_test.go
+++ b/test/sdks_test.go
@@ -26,7 +26,7 @@ import (
"time"
"gerrit.automotivelinux.org/gerrit/src/xds/xds-server/lib/xsapiv1"
- "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
var cpt int
@@ -51,12 +51,12 @@ func ConnectSDKStateChange(t *testing.T, sCli *IOSockClient, channel chan xsapiv
})
args := xsapiv1.EventRegisterArgs{Name: xsapiv1.EVTSDKStateChange}
- assert.Nil(t, HTTPCli.Post("/events/register", args, nil))
+ require.Nil(t, HTTPCli.Post("/events/register", args, nil))
}
func DisconnectSDKStateChange(t *testing.T, sCli *IOSockClient) {
args := xsapiv1.EventRegisterArgs{Name: xsapiv1.EVTSDKStateChange}
- assert.Nil(t, HTTPCli.Post("/events/unregister", args, nil))
+ require.Nil(t, HTTPCli.Post("/events/unregister", args, nil))
}
func InitSdkDir() {
@@ -74,12 +74,12 @@ func InitSdkDir() {
func RemoveSdk(t *testing.T, sdk xsapiv1.SDK, chSdks chan xsapiv1.SDK) {
Debugf(t, "remove sdk %v", sdk.ID)
- assert.Nil(t, HTTPCli.Delete("/sdks/"+sdk.ID, &sdk))
+ require.Nil(t, HTTPCli.Delete("/sdks/"+sdk.ID, &sdk))
sdkFromEvt := <-chSdks //waiting for event Uninstalling
- assert.Equal(t, sdk.ID, sdkFromEvt.ID)
- assert.Equal(t, sdkFromEvt.Status, "Un-installing")
+ require.Equal(t, sdk.ID, sdkFromEvt.ID)
+ require.Equal(t, sdkFromEvt.Status, "Un-installing")
sdkFromEvt = <-chSdks //waiting for event not installed
- assert.Equal(t, sdkFromEvt.Status, "Not Installed")
+ require.Equal(t, sdkFromEvt.Status, "Not Installed")
os.RemoveAll(path.Join(os.Getenv(envXdtSdk), sdk.Profile))
os.Remove(strings.Replace(sdk.URL, "file://", "", 1))
}
@@ -88,9 +88,9 @@ func TestSdks(t *testing.T) {
InitSdkDir()
/*get sdk list from sdk_latest.json*/
var sdkArray []xsapiv1.SDK
- assert.Nil(t, HTTPCli.Get("/sdks", &sdkArray))
+ require.Nil(t, HTTPCli.Get("/sdks", &sdkArray))
_, err := os.Stat(path.Join(os.Getenv(envXdtSdk), "sdks_latest.json"))
- assert.Nil(t, err)
+ require.Nil(t, err)
/*create channel fro SDK event*/
chSdks := make(chan xsapiv1.SDK)
@@ -100,46 +100,46 @@ func TestSdks(t *testing.T) {
/*checking startup installing of SDKs*/
for i := 0; i < len(sdkArray); i++ {
re := regexp.MustCompile("^[0-9a-z]+-[0-9a-z]+-[0-9a-z]+-[0-9a-z]+-[0-9a-z]+$")
- assert.True(t, re.MatchString(sdkArray[i].ID))
- assert.Equal(t, sdkArray[0].Status, "Not Installed")
+ require.True(t, re.MatchString(sdkArray[i].ID))
+ require.Equal(t, sdkArray[0].Status, "Not Installed")
var sdk xsapiv1.SDK
- assert.Nil(t, HTTPCli.Get("/sdks/"+sdkArray[i].ID, &sdk))
- assert.Equal(t, sdkArray[i], sdk)
+ require.Nil(t, HTTPCli.Get("/sdks/"+sdkArray[i].ID, &sdk))
+ require.Equal(t, sdkArray[i], sdk)
var sdkRes xsapiv1.SDK
/*install sdk*/
Debugf(t, "install sdk %v", sdk.Name)
- assert.Nil(t, HTTPCli.Post("/sdks", sdk, &sdkRes))
- assert.Equal(t, sdkRes.Status, "Installing")
+ require.Nil(t, HTTPCli.Post("/sdks", sdk, &sdkRes))
+ require.Equal(t, sdkRes.Status, "Installing")
sdkFromEvent := <-chSdks //waiting for installing event
- assert.Equal(t, sdkRes.ID, sdkFromEvent.ID)
- assert.Equal(t, sdkFromEvent.Status, "Installing")
+ require.Equal(t, sdkRes.ID, sdkFromEvent.ID)
+ require.Equal(t, sdkFromEvent.Status, "Installing")
/*abort sdk install*/
Debugf(t, "abort install sdk %v", sdk.Name)
- assert.Nil(t, HTTPCli.Post("/sdks/abortinstall", sdk, &sdkRes))
- assert.Equal(t, sdkRes.Status, "Not Installed")
+ require.Nil(t, HTTPCli.Post("/sdks/abortinstall", sdk, &sdkRes))
+ require.Equal(t, sdkRes.Status, "Not Installed")
sdkFromEvent = <-chSdks //waiting for not installed status*/
- assert.Equal(t, sdkRes.ID, sdkFromEvent.ID)
- assert.Equal(t, sdkRes.Status, sdkFromEvent.Status)
+ require.Equal(t, sdkRes.ID, sdkFromEvent.ID)
+ require.Equal(t, sdkRes.Status, sdkFromEvent.Status)
}
}
func installFakeSdk(t *testing.T, sdkInstall xsapiv1.SDKInstallArgs, chSdks chan xsapiv1.SDK) xsapiv1.SDK {
InitSdkDir()
var sdkRes xsapiv1.SDK
- assert.Nil(t, HTTPCli.Post("/sdks", sdkInstall, &sdkRes))
+ require.Nil(t, HTTPCli.Post("/sdks", sdkInstall, &sdkRes))
Debugf(t, "Install fake sdk %v (force=%v)", sdkRes.Name, sdkInstall.Force)
- assert.Equal(t, sdkRes.Status, "Installing")
+ require.Equal(t, sdkRes.Status, "Installing")
sdkFromEvent := <-chSdks
- assert.Equal(t, sdkRes.ID, sdkFromEvent.ID)
- assert.Equal(t, sdkFromEvent.Status, "Installing")
+ require.Equal(t, sdkRes.ID, sdkFromEvent.ID)
+ require.Equal(t, sdkFromEvent.Status, "Installing")
/*waiting for SDKStateChange event from channel*/
sdkFromEvent = <-chSdks
- assert.Equal(t, sdkRes.ID, sdkFromEvent.ID)
- assert.Equal(t, "Installed", sdkFromEvent.Status)
- assert.Equal(t, sdkFromEvent.LastError, "")
+ require.Equal(t, sdkRes.ID, sdkFromEvent.ID)
+ require.Equal(t, "Installed", sdkFromEvent.Status)
+ require.Equal(t, sdkFromEvent.LastError, "")
Debugf(t, "Fake sdk %v installed", sdkFromEvent.Name)
return sdkFromEvent
}
@@ -172,14 +172,14 @@ func TestSdksError(t *testing.T) {
Debugf(t, "error while installing sdk with no ID and no Filename")
var sdkRes xsapiv1.SDK
/*error with no ID no filename*/
- assert.NotNil(t, HTTPCli.Post("/sdks", sdk, &sdkRes))
+ require.NotNil(t, HTTPCli.Post("/sdks", sdk, &sdkRes))
sdk.ID = "42885c24-374e-3ef0-9723-0c8a05191aa"
Debugf(t, "error while installing sdk with a fake id=%v", sdk.ID)
/*error with fake ID*/
- assert.NotNil(t, HTTPCli.Post("/sdks", sdk, &sdkRes))
+ require.NotNil(t, HTTPCli.Post("/sdks", sdk, &sdkRes))
sdk.ID = ""
sdk.Filename = "fake"
Debugf(t, "error while installing sdk with a fake filename=%v", sdk.Filename)
/*error with fake filename*/
- assert.NotNil(t, HTTPCli.Post("/sdks", sdk, &sdkRes))
+ require.NotNil(t, HTTPCli.Post("/sdks", sdk, &sdkRes))
}
diff --git a/test/target_test.go b/test/target_test.go
index d7576c6..4e863fc 100644
--- a/test/target_test.go
+++ b/test/target_test.go
@@ -31,7 +31,7 @@ import (
common "gerrit.automotivelinux.org/gerrit/src/xds/xds-common.git/golib"
"gerrit.automotivelinux.org/gerrit/src/xds/xds-server/lib/xsapiv1"
- "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func launchSSHd(sshDir string, proc **os.Process, sshdCmd string) (*os.File, string) {
@@ -70,11 +70,11 @@ func InitSSH(t *testing.T, procSSHd **os.Process) (string, string) {
cmd := exec.Command("cp", "-r", sshFixturesDir, sshDir)
var out bytes.Buffer
cmd.Stdout = &out
- assert.Nil(t, cmd.Run())
+ require.Nil(t, cmd.Run())
cmd = exec.Command("ls", sshDir)
cmd.Stdout = &out
- assert.Nil(t, cmd.Run())
+ require.Nil(t, cmd.Run())
files := strings.Split(fmt.Sprint(cmd.Stdout), "\n")
@@ -83,7 +83,7 @@ func InitSSH(t *testing.T, procSSHd **os.Process) (string, string) {
file := sshDir + "/" + f
cmd = exec.Command("chmod", "600", file)
cmd.Stdout = &out
- assert.Nil(t, cmd.Run())
+ require.Nil(t, cmd.Run())
}
}
@@ -97,7 +97,7 @@ func InitSSH(t *testing.T, procSSHd **os.Process) (string, string) {
} else if common.Exists("/usr/bin/sshd") {
sshdCmd = "/usr/sbin/sshd"
} else {
- assert.FailNow(t, "Cannot find sshd command, please install it or set in your PATH")
+ require.FailNow(t, "Cannot find sshd command, please install it or set in your PATH")
}
} else {
sshdCmd = strings.TrimSpace(fmt.Sprint(cmd.Stdout))
@@ -137,7 +137,7 @@ func waitForPrompt(t *testing.T, channel chan xsapiv1.TerminalOutMsg, prompt str
case <-time.After(step):
current = current + step
if current >= timeout {
- assert.FailNow(t, "Never received prompt message from terminal (output:"+out+")")
+ require.FailNow(t, "Never received prompt message from terminal (output:"+out+")")
}
}
}
@@ -150,7 +150,7 @@ func ConnectTargetEvents(t *testing.T, channel chan xsapiv1.TargetConfig) {
})
args := xsapiv1.EventRegisterArgs{Name: xsapiv1.EVTTargetAdd}
- assert.Nil(t, HTTPCli.Post("/events/register", args, nil))
+ require.Nil(t, HTTPCli.Post("/events/register", args, nil))
sCli.Conn.On(xsapiv1.EVTTargetRemove, func(e xsapiv1.EventMsg) {
target, _ := e.DecodeTargetEvent()
@@ -158,14 +158,14 @@ func ConnectTargetEvents(t *testing.T, channel chan xsapiv1.TargetConfig) {
})
args = xsapiv1.EventRegisterArgs{Name: xsapiv1.EVTTargetRemove}
- assert.Nil(t, HTTPCli.Post("/events/register", args, nil))
+ require.Nil(t, HTTPCli.Post("/events/register", args, nil))
}
func DisconnectTargetEvents(t *testing.T) {
args := xsapiv1.EventRegisterArgs{Name: xsapiv1.EVTTargetAdd}
- assert.Nil(t, HTTPCli.Post("/events/unregister", args, nil))
+ require.Nil(t, HTTPCli.Post("/events/unregister", args, nil))
args = xsapiv1.EventRegisterArgs{Name: xsapiv1.EVTTargetRemove}
- assert.Nil(t, HTTPCli.Post("/events/unregister", args, nil))
+ require.Nil(t, HTTPCli.Post("/events/unregister", args, nil))
}
func ConnectTermEvents(t *testing.T, channel chan xsapiv1.TerminalConfig) {
@@ -175,7 +175,7 @@ func ConnectTermEvents(t *testing.T, channel chan xsapiv1.TerminalConfig) {
})
args := xsapiv1.EventRegisterArgs{Name: xsapiv1.EVTTargetTerminalAdd}
- assert.Nil(t, HTTPCli.Post("/events/register", args, nil))
+ require.Nil(t, HTTPCli.Post("/events/register", args, nil))
sCli.Conn.On(xsapiv1.EVTTargetTerminalStateChange, func(e xsapiv1.EventMsg) {
termEvt, _ := e.DecodeTerminalEvent()
@@ -183,7 +183,7 @@ func ConnectTermEvents(t *testing.T, channel chan xsapiv1.TerminalConfig) {
})
args = xsapiv1.EventRegisterArgs{Name: xsapiv1.EVTTargetTerminalStateChange}
- assert.Nil(t, HTTPCli.Post("/events/register", args, nil))
+ require.Nil(t, HTTPCli.Post("/events/register", args, nil))
sCli.Conn.On(xsapiv1.EVTTargetTerminalRemove, func(e xsapiv1.EventMsg) {
termEvt, _ := e.DecodeTerminalEvent()
@@ -191,16 +191,16 @@ func ConnectTermEvents(t *testing.T, channel chan xsapiv1.TerminalConfig) {
})
args = xsapiv1.EventRegisterArgs{Name: xsapiv1.EVTTargetTerminalRemove}
- assert.Nil(t, HTTPCli.Post("/events/register", args, nil))
+ require.Nil(t, HTTPCli.Post("/events/register", args, nil))
}
func DisconnectTermEvents(t *testing.T) {
args := xsapiv1.EventRegisterArgs{Name: xsapiv1.EVTTargetTerminalAdd}
- assert.Nil(t, HTTPCli.Post("/events/unregister", args, nil))
+ require.Nil(t, HTTPCli.Post("/events/unregister", args, nil))
args = xsapiv1.EventRegisterArgs{Name: xsapiv1.EVTTargetTerminalStateChange}
- assert.Nil(t, HTTPCli.Post("/events/unregister", args, nil))
+ require.Nil(t, HTTPCli.Post("/events/unregister", args, nil))
args = xsapiv1.EventRegisterArgs{Name: xsapiv1.EVTTargetTerminalRemove}
- assert.Nil(t, HTTPCli.Post("/events/unregister", args, nil))
+ require.Nil(t, HTTPCli.Post("/events/unregister", args, nil))
}
func AddTargets(t *testing.T, nbTargets int, chTarget chan xsapiv1.TargetConfig) []string {
@@ -213,16 +213,16 @@ func AddTargets(t *testing.T, nbTargets int, chTarget chan xsapiv1.TargetConfig)
IP: "127.0.0.1",
}
/*add target*/
- assert.Nil(t, HTTPCli.Post("/targets", target, &target))
+ require.Nil(t, HTTPCli.Post("/targets", target, &target))
Debugf(t, "add target %v", target.Name)
targetEvt := <-chTarget //waiting for event targetAdd
- assert.Equal(t, target.ID, targetEvt.ID)
+ require.Equal(t, target.ID, targetEvt.ID)
listID[i] = target.ID
}
for i := 0; i < nbTargets; i++ {
var target xsapiv1.TargetConfig
- assert.Nil(t, HTTPCli.Get("/targets/"+listID[i], &target))
- assert.Equal(t, target.Status, "Enable")
+ require.Nil(t, HTTPCli.Get("/targets/"+listID[i], &target))
+ require.Equal(t, target.Status, "Enable")
}
return listID
}
@@ -244,17 +244,17 @@ func AddTerms(t *testing.T, nbTerms int, listID []string, chTermEvt chan xsapiv1
},
}
/*add terminal on target*/
- assert.Nil(t, HTTPCli.Post("/targets/"+listID[j]+"/terminals", term, &term))
+ require.Nil(t, HTTPCli.Post("/targets/"+listID[j]+"/terminals", term, &term))
Debugf(t, "add terminal %v", term.Name)
termEvt := <-chTermEvt //waiting for event terminalAdd*/
- assert.Equal(t, term.ID, termEvt.ID)
+ require.Equal(t, term.ID, termEvt.ID)
listTermsID[i] = term.ID
}
- assert.Equal(t, len(listTermsID), nbTerms)
+ require.Equal(t, len(listTermsID), nbTerms)
for i := 0; i < nbTerms; i++ {
var term xsapiv1.TerminalConfig
- assert.Nil(t, HTTPCli.Get("/targets/"+listID[j]+"/terminals/"+listTermsID[i], &term))
- assert.Equal(t, term.Status, "Close")
+ require.Nil(t, HTTPCli.Get("/targets/"+listID[j]+"/terminals/"+listTermsID[i], &term))
+ require.Equal(t, term.Status, "Close")
}
}
}
@@ -269,32 +269,32 @@ func PostTerms(t *testing.T, post string, chTermEvt chan xsapiv1.TerminalConfig,
status = "Closing"
}
var targets []xsapiv1.TargetConfig
- assert.Nil(t, HTTPCli.Get("/targets", &targets))
+ require.Nil(t, HTTPCli.Get("/targets", &targets))
for i := 0; i < len(targets); i++ {
var terms []xsapiv1.TerminalConfig
- assert.Nil(t, HTTPCli.Get("/targets/"+targets[i].ID+"/terminals", &terms))
+ require.Nil(t, HTTPCli.Get("/targets/"+targets[i].ID+"/terminals", &terms))
listTermsID := make([]string, len(terms))
for j := 0; j < len(terms); j++ {
var term xsapiv1.TerminalConfig
/*post action on term*/
- assert.Nil(t, HTTPCli.Post("/targets/"+targets[i].ID+"/terminals/"+terms[j].ID+"/"+post, terms[j], &term))
+ require.Nil(t, HTTPCli.Post("/targets/"+targets[i].ID+"/terminals/"+terms[j].ID+"/"+post, terms[j], &term))
Debugf(t, "%v terminal %v", post, term.Name)
termEvt := <-chTermEvt //waiting for event terminalStateChange
if post == "open" {
data := []byte("PS1=" + prompt + " bash -norc\n")
- assert.Nil(t, sCli.Conn.Emit(xsapiv1.TerminalInEvent, data))
+ require.Nil(t, sCli.Conn.Emit(xsapiv1.TerminalInEvent, data))
waitForPrompt(t, chTerm, prompt)
}
- assert.Equal(t, term.ID, termEvt.ID)
- assert.Equal(t, term.Status, status)
- assert.Equal(t, termEvt.Status, status)
+ require.Equal(t, term.ID, termEvt.ID)
+ require.Equal(t, term.Status, status)
+ require.Equal(t, termEvt.Status, status)
listTermsID[i] = term.ID
}
time.Sleep(10 * time.Millisecond)
for j := 0; j < len(listTermsID); j++ {
var term xsapiv1.TerminalConfig
- assert.Nil(t, HTTPCli.Get("/targets/"+targets[i].ID+"/terminals/"+listTermsID[i], &term))
- assert.True(t, strings.EqualFold(term.Status, post))
+ require.Nil(t, HTTPCli.Get("/targets/"+targets[i].ID+"/terminals/"+listTermsID[i], &term))
+ require.True(t, strings.EqualFold(term.Status, post))
Debugf(t, "check that term status %v is %v", term.Name, post)
}
}
@@ -302,23 +302,23 @@ func PostTerms(t *testing.T, post string, chTermEvt chan xsapiv1.TerminalConfig,
func RemoveTermsTargets(t *testing.T, chTarget chan xsapiv1.TargetConfig, chTermEvt chan xsapiv1.TerminalConfig) {
var targets []xsapiv1.TargetConfig
- assert.Nil(t, HTTPCli.Get("/targets", &targets))
+ require.Nil(t, HTTPCli.Get("/targets", &targets))
for i := 0; i < len(targets); i++ {
var terms []xsapiv1.TerminalConfig
- assert.Nil(t, HTTPCli.Get("/targets/"+targets[i].ID+"/terminals", &terms))
+ require.Nil(t, HTTPCli.Get("/targets/"+targets[i].ID+"/terminals", &terms))
for j := 0; j < len(terms); j++ {
var term xsapiv1.TerminalConfig
- assert.Nil(t, HTTPCli.Delete("/targets/"+targets[i].ID+"/terminals/"+terms[j].ID, &term))
+ require.Nil(t, HTTPCli.Delete("/targets/"+targets[i].ID+"/terminals/"+terms[j].ID, &term))
termEvt := <-chTermEvt
- assert.Equal(t, term.ID, termEvt.ID)
- assert.NotNil(t, HTTPCli.Delete("/targets/"+targets[i].ID+"/terminals/"+terms[j].ID, &term))
+ require.Equal(t, term.ID, termEvt.ID)
+ require.NotNil(t, HTTPCli.Delete("/targets/"+targets[i].ID+"/terminals/"+terms[j].ID, &term))
Debugf(t, "remove terminal %v", term.Name)
}
var tgtRes xsapiv1.TargetConfig
- assert.Nil(t, HTTPCli.Delete("/targets/"+targets[i].ID, &tgtRes))
+ require.Nil(t, HTTPCli.Delete("/targets/"+targets[i].ID, &tgtRes))
targetEvt := <-chTarget //waiting for remove terminal event
- assert.Equal(t, tgtRes.ID, targetEvt.ID)
- assert.Equal(t, targets[i].ID, tgtRes.ID)
+ require.Equal(t, tgtRes.ID, targetEvt.ID)
+ require.Equal(t, targets[i].ID, tgtRes.ID)
}
}
func TestTarget(t *testing.T) {
@@ -341,8 +341,8 @@ func TestTarget(t *testing.T) {
/*check that targetArray is empty at startup*/
var targetArray []xsapiv1.TargetConfig
- assert.Nil(t, HTTPCli.Get("/targets", &targetArray))
- assert.Equal(t, len(targetArray), 0)
+ require.Nil(t, HTTPCli.Get("/targets", &targetArray))
+ require.Equal(t, len(targetArray), 0)
listID := AddTargets(t, nbTargets, chTarget)
AddTerms(t, nbTermsByTarget, listID, chTermEvt, sshDir, port)
@@ -369,23 +369,23 @@ func TestTarget(t *testing.T) {
/*send cmd though term*/
data := []byte("echo helloWorld" + strconv.Itoa(i) + " >> " + totoFileCurrent + "\n")
Debugf(t, "send following command through terminal: %v", string(data))
- assert.Nil(t, sCli.Conn.Emit(xsapiv1.TerminalInEvent, data))
+ require.Nil(t, sCli.Conn.Emit(xsapiv1.TerminalInEvent, data))
waitForPrompt(t, chTerm, prompt) //waiting for terminal prompt
/*check that toto file is created*/
_, err := os.Stat(totoFileCurrent)
- assert.Nil(t, err)
+ require.Nil(t, err)
/*send cmd though term*/
data = []byte("cat " + totoFileCurrent + "\n")
Debugf(t, "send following command through terminal: %v", string(data))
- assert.Nil(t, sCli.Conn.Emit(xsapiv1.TerminalInEvent, data))
+ require.Nil(t, sCli.Conn.Emit(xsapiv1.TerminalInEvent, data))
<-chTerm //cmd sent
termOut := <-chTerm //result of cat cmd
waitForPrompt(t, chTerm, prompt) //wait for terminal prompt
/*check that terminal msg is what was written before*/
- assert.Equal(t, string(termOut.Stdout), "helloWorld"+strconv.Itoa(i)+"\r\n")
+ require.Equal(t, string(termOut.Stdout), "helloWorld"+strconv.Itoa(i)+"\r\n")
Debugf(t, "check terminal output msg: %v", string(termOut.Stdout))
}
@@ -401,47 +401,47 @@ func TestTargetErrors(t *testing.T) {
/*cannot create empty target*/
target := xsapiv1.TargetConfig{}
var targetRes xsapiv1.TargetConfig
- assert.NotNil(t, HTTPCli.Post("/targets", target, &targetRes))
+ require.NotNil(t, HTTPCli.Post("/targets", target, &targetRes))
Debugf(t, "error while creating empty target")
/*check cannot create target with no IP*/
target.Type = xsapiv1.TypeTgtStandard
- assert.NotNil(t, HTTPCli.Post("/targets", target, &targetRes))
+ require.NotNil(t, HTTPCli.Post("/targets", target, &targetRes))
Debugf(t, "error while creating target without IP")
target.IP = "127.0.0.1"
- assert.Nil(t, HTTPCli.Post("/targets", target, &targetRes))
+ require.Nil(t, HTTPCli.Post("/targets", target, &targetRes))
Debugf(t, "create target %v", targetRes.Name)
/*cannot create empty terminal*/
term := xsapiv1.TerminalConfig{}
var termRes xsapiv1.TerminalConfig
- assert.NotNil(t, HTTPCli.Post("/targets/"+targetRes.ID+"/terminals", term, &termRes))
+ require.NotNil(t, HTTPCli.Post("/targets/"+targetRes.ID+"/terminals", term, &termRes))
Debugf(t, "error while creating empty terminal")
term.Type = xsapiv1.TypeTermSSH
- assert.NotNil(t, HTTPCli.Post("/targets/"+"1010"+"/terminals", term, &termRes))
+ require.NotNil(t, HTTPCli.Post("/targets/"+"1010"+"/terminals", term, &termRes))
Debugf(t, "error while creating terminal on an non existing target")
- assert.Nil(t, HTTPCli.Post("/targets/"+targetRes.ID+"/terminals", term, &termRes))
- assert.Nil(t, HTTPCli.Post("/targets/"+targetRes.ID+"/terminals", term, &termRes))
- assert.Nil(t, HTTPCli.Post("/targets/"+targetRes.ID+"/terminals", term, &termRes))
- assert.Nil(t, HTTPCli.Post("/targets/"+targetRes.ID+"/terminals", term, &termRes))
+ require.Nil(t, HTTPCli.Post("/targets/"+targetRes.ID+"/terminals", term, &termRes))
+ require.Nil(t, HTTPCli.Post("/targets/"+targetRes.ID+"/terminals", term, &termRes))
+ require.Nil(t, HTTPCli.Post("/targets/"+targetRes.ID+"/terminals", term, &termRes))
+ require.Nil(t, HTTPCli.Post("/targets/"+targetRes.ID+"/terminals", term, &termRes))
Debugf(t, "create several terminals")
/*remove targets and terms*/
var targetArray []xsapiv1.TargetConfig
- assert.Nil(t, HTTPCli.Get("/targets", &targetArray))
+ require.Nil(t, HTTPCli.Get("/targets", &targetArray))
for i := 0; i < len(targetArray); i++ {
var termArray []xsapiv1.TerminalConfig
- assert.Nil(t, HTTPCli.Get("/targets/"+targetArray[i].ID+"/terminals", &termArray))
+ require.Nil(t, HTTPCli.Get("/targets/"+targetArray[i].ID+"/terminals", &termArray))
for j := 0; j < len(termArray); j++ {
- assert.Nil(t, HTTPCli.Delete("/targets/"+targetArray[i].ID+"/terminals/"+termArray[j].ID, &termRes))
+ require.Nil(t, HTTPCli.Delete("/targets/"+targetArray[i].ID+"/terminals/"+termArray[j].ID, &termRes))
Debugf(t, "delete terminal %v", termRes.Name)
- assert.NotNil(t, HTTPCli.Delete("/targets/"+targetArray[i].ID+"/terminals/"+termArray[j].ID, &termRes))
+ require.NotNil(t, HTTPCli.Delete("/targets/"+targetArray[i].ID+"/terminals/"+termArray[j].ID, &termRes))
Debugf(t, "error while deleting an already deleted terminal %v", termRes.Name)
}
var tgtRes xsapiv1.TargetConfig
- assert.Nil(t, HTTPCli.Delete("/targets/"+targetArray[i].ID, &tgtRes))
+ require.Nil(t, HTTPCli.Delete("/targets/"+targetArray[i].ID, &tgtRes))
Debugf(t, "delete target %v", tgtRes.Name)
- assert.Equal(t, targetArray[i].ID, tgtRes.ID)
- assert.NotNil(t, HTTPCli.Delete("/targets/"+targetArray[i].ID, &tgtRes))
+ require.Equal(t, targetArray[i].ID, tgtRes.ID)
+ require.NotNil(t, HTTPCli.Delete("/targets/"+targetArray[i].ID, &tgtRes))
Debugf(t, "error while deleting an already deleted target %v", tgtRes.Name)
}
}
diff --git a/test/version_test.go b/test/version_test.go
index 5373a15..dab77ad 100644
--- a/test/version_test.go
+++ b/test/version_test.go
@@ -20,17 +20,17 @@ import (
"regexp"
"testing"
- "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestVersion(t *testing.T) {
var datVersion map[string]interface{}
- assert.Nil(t, HTTPCli.Get("/version", &datVersion))
+ require.Nil(t, HTTPCli.Get("/version", &datVersion))
Debug(t, datVersion)
ver, present := datVersion["version"]
- assert.True(t, present)
+ require.True(t, present)
Debugf(t, "version is %s", ver.(string))
re := regexp.MustCompile("^v*[0-9]+.[0-9]+.[0-9]+$")
- assert.True(t, re.MatchString(ver.(string)))
+ require.True(t, re.MatchString(ver.(string)))
}