aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorClément Bénier <clement.benier@iot.bzh>2018-08-21 17:56:10 +0200
committerClément Bénier <clement.benier@iot.bzh>2018-08-21 17:56:10 +0200
commitb1d091a8c6b2269601a1683e963d0e382cd0f7f6 (patch)
treeec60f14ec47211e929d144bde128fbbff5f7c0dc /test
parent4192072863ac0997b0c3cb4131ea913e6f85f83e (diff)
test logs: hide log
logs are printable with VERBOSE != "" Change-Id: I170aed2e73db673ba6276410b1dddd3389239457 Signed-off-by: Clément Bénier <clement.benier@iot.bzh>
Diffstat (limited to 'test')
-rw-r--r--test/config_test.go2
-rw-r--r--test/exec_test.go8
-rw-r--r--test/folders_test.go38
-rw-r--r--test/sdks_test.go16
-rw-r--r--test/target_test.go36
-rw-r--r--test/version_test.go4
-rw-r--r--test/xdsserver_test.go12
7 files changed, 64 insertions, 52 deletions
diff --git a/test/config_test.go b/test/config_test.go
index da56188..2b95e85 100644
--- a/test/config_test.go
+++ b/test/config_test.go
@@ -42,7 +42,7 @@ func CheckIP(ipconfig string) bool {
func TestConfig(t *testing.T) {
var cfg xsapiv1.APIConfig
assert.Nil(t, HTTPCli.Get("/config", &cfg))
- t.Logf("Config is %v", 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
diff --git a/test/exec_test.go b/test/exec_test.go
index 8759dbd..1ab781a 100644
--- a/test/exec_test.go
+++ b/test/exec_test.go
@@ -29,7 +29,7 @@ import (
)
func InitExec(t *testing.T) string {
- t.Logf("Create helloworld directory with app-templates")
+ Debugf(t, "Create helloworld directory with app-templates")
/*copy helloworld from fixtures to envRootCfgDir*/
helloworldDir := path.Join(os.Getenv(envRootCfgDir), "helloworld")
cmd := exec.Command("cp", "-r", helloworldFixturesDir, helloworldDir)
@@ -115,7 +115,7 @@ func TestExec(t *testing.T) {
Cmd: cmd,
}
var execRes xsapiv1.ExecArgs
- t.Logf("exec cmake cmd(%v)", cmd)
+ Debugf(t, "exec cmake cmd(%v)", cmd)
assert.Nil(t, HTTPCli.Post("/exec", exec, &execRes))
flushChannelExec(chExec, 1000) //waiting for execOutMsg
@@ -131,12 +131,12 @@ func TestExec(t *testing.T) {
cmd = cmd + "make"
exec.Cmd = cmd
/*post exec cmd make*/
- t.Logf("exec make cmd(%v)", cmd)
+ Debugf(t, "exec make cmd(%v)", cmd)
assert.Nil(t, HTTPCli.Post("/exec", exec, &execRes))
flushChannelExec(chExec, 1000) //waiting for execOutMsg
/*check if helloworld.so exists*/
- t.Log("check that 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)
diff --git a/test/folders_test.go b/test/folders_test.go
index 065e3e3..10f1dc6 100644
--- a/test/folders_test.go
+++ b/test/folders_test.go
@@ -28,7 +28,7 @@ import (
func TestFolders(t *testing.T) {
/*init: check there is no folder*/
- t.Log("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)
@@ -43,10 +43,10 @@ func TestFolders(t *testing.T) {
},
}
var cfg xsapiv1.FolderConfig
- t.Logf("create folder: \n%v", fPrj)
+ Debugf(t, "create folder: \n%v", fPrj)
assert.Nil(t, HTTPCli.Post("/folders", fPrj, &cfg))
assert.NotNil(t, cfg)
- t.Logf("result folder: \n%v", 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]+$")
@@ -74,23 +74,23 @@ func TestFolders(t *testing.T) {
/*create/delete folders*/
var cfgArrayBis []xsapiv1.FolderConfig
assert.Nil(t, HTTPCli.Post("/folders", fPrj, &cfg))
- t.Logf("create folder with id=%v", cfg.ID)
+ Debugf(t, "create folder with id=%v", cfg.ID)
assert.Nil(t, HTTPCli.Post("/folders", fPrj, &cfg))
- t.Logf("create folder with id=%v", cfg.ID)
+ 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))
- t.Logf("delete folder with id=%v", cfg.ID)
+ 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))
- t.Logf("delete folder with id=%v", cfg.ID)
+ 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))
- t.Logf("delete folder with id=%v", cfg.ID)
+ 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)
@@ -109,19 +109,19 @@ func TestFoldersEmptyValues(t *testing.T) {
var cfg xsapiv1.FolderConfig
/*ServerPath is empty*/
assert.NotNil(t, HTTPCli.Post("/folders", fPrj, &cfg))
- t.Logf("error while creating folder with empty serverpath \n%v", fPrj)
+ 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))
- t.Logf("error while creating folder with empty clientpath \n%v", fPrj)
+ 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))
- t.Logf("error while creating folder with empty type \n%v", fPrj)
+ Debugf(t, "error while creating folder with empty type \n%v", fPrj)
var cfgArray []xsapiv1.FolderConfig
assert.Nil(t, HTTPCli.Get("/folders", &cfgArray))
@@ -142,7 +142,7 @@ func TestFoldersPathMapConfig(t *testing.T) {
var cfg xsapiv1.FolderConfig
/*file not present*/
assert.NotNil(t, HTTPCli.Post("/folders", fPrj, &cfg))
- t.Logf("error while creating folder with no checkfile \n%v", fPrj)
+ Debugf(t, "error while creating folder with no checkfile \n%v", fPrj)
var checkFileClient = fPrj.ClientPath + "/checkfile"
var checkFileServer = fPrj.DataPathMap.ServerPath + "/checkfile"
@@ -153,30 +153,30 @@ func TestFoldersPathMapConfig(t *testing.T) {
fPrj.DataPathMap.CheckContent = "CheckContent From Client\n"
file, err := os.OpenFile(checkFileClient, os.O_CREATE|os.O_RDWR, 0644)
if err != nil {
- t.Log(err)
+ Debug(t, err)
}
if err := os.Symlink(checkFileClient, checkFileServer); err != nil {
- t.Log(err)
+ Debug(t, err)
}
/*file content differ*/
assert.NotNil(t, HTTPCli.Post("/folders", fPrj, &cfg))
- t.Logf("error while creating folder with different checkfiles \n%v", fPrj)
+ Debugf(t, "error while creating folder with different checkfiles \n%v", fPrj)
/*write same message*/
if _, err := file.WriteString(fPrj.DataPathMap.CheckContent); err != nil {
- t.Log(err)
+ Debug(t, err)
}
assert.Nil(t, HTTPCli.Post("/folders", fPrj, &cfg))
- t.Logf("create folder with same checkfiles \n%v", fPrj)
+ Debugf(t, "create folder with same checkfiles \n%v", fPrj)
/*check server msg: ServerUID needed*/
- t.Logf("check server msg")
+ Debugf(t, "check server msg")
var APIcfg xsapiv1.APIConfig
assert.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 {
- t.Log(err)
+ Debug(t, err)
}
assert.Equal(t, msg, string(data))
diff --git a/test/sdks_test.go b/test/sdks_test.go
index 1e3298f..1395b16 100644
--- a/test/sdks_test.go
+++ b/test/sdks_test.go
@@ -73,7 +73,7 @@ func InitSdkDir() {
}
func RemoveSdk(t *testing.T, sdk xsapiv1.SDK, chSdks chan xsapiv1.SDK) {
- t.Logf("remove sdk %v", sdk.ID)
+ Debugf(t, "remove sdk %v", sdk.ID)
assert.Nil(t, HTTPCli.Delete("/sdks/"+sdk.ID, &sdk))
sdkFromEvt := <-chSdks //waiting for event Uninstalling
assert.Equal(t, sdk.ID, sdkFromEvt.ID)
@@ -109,7 +109,7 @@ func TestSdks(t *testing.T) {
var sdkRes xsapiv1.SDK
/*install sdk*/
- t.Logf("install sdk %v", sdk.Name)
+ Debugf(t, "install sdk %v", sdk.Name)
assert.Nil(t, HTTPCli.Post("/sdks", sdk, &sdkRes))
assert.Equal(t, sdkRes.Status, "Installing")
sdkFromEvent := <-chSdks //waiting for installing event
@@ -117,7 +117,7 @@ func TestSdks(t *testing.T) {
assert.Equal(t, sdkFromEvent.Status, "Installing")
/*abort sdk install*/
- t.Logf("abort install sdk %v", sdk.Name)
+ Debugf(t, "abort install sdk %v", sdk.Name)
assert.Nil(t, HTTPCli.Post("/sdks/abortinstall", sdk, &sdkRes))
assert.Equal(t, sdkRes.Status, "Not Installed")
sdkFromEvent = <-chSdks //waiting for not installed status*/
@@ -130,7 +130,7 @@ func installFakeSdk(t *testing.T, sdkInstall xsapiv1.SDKInstallArgs, chSdks chan
InitSdkDir()
var sdkRes xsapiv1.SDK
assert.Nil(t, HTTPCli.Post("/sdks", sdkInstall, &sdkRes))
- t.Logf("Install fake sdk %v (force=%v)", sdkRes.Name, sdkInstall.Force)
+ Debugf(t, "Install fake sdk %v (force=%v)", sdkRes.Name, sdkInstall.Force)
assert.Equal(t, sdkRes.Status, "Installing")
sdkFromEvent := <-chSdks
assert.Equal(t, sdkRes.ID, sdkFromEvent.ID)
@@ -140,7 +140,7 @@ func installFakeSdk(t *testing.T, sdkInstall xsapiv1.SDKInstallArgs, chSdks chan
assert.Equal(t, sdkRes.ID, sdkFromEvent.ID)
assert.Equal(t, "Installed", sdkFromEvent.Status)
assert.Equal(t, sdkFromEvent.LastError, "")
- t.Logf("Fake sdk %v installed", sdkFromEvent.Name)
+ Debugf(t, "Fake sdk %v installed", sdkFromEvent.Name)
return sdkFromEvent
}
@@ -169,17 +169,17 @@ func TestSdksError(t *testing.T) {
Filename: "",
Force: false,
}
- t.Logf("error while installing sdk with no ID and no Filename")
+ 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))
sdk.ID = "42885c24-374e-3ef0-9723-0c8a05191aa"
- t.Logf("error while installing sdk with a fake id=%v", sdk.ID)
+ 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))
sdk.ID = ""
sdk.Filename = "fake"
- t.Logf("error while installing sdk with a fake filename=%v", sdk.Filename)
+ 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))
}
diff --git a/test/target_test.go b/test/target_test.go
index 50483ff..17ac6b8 100644
--- a/test/target_test.go
+++ b/test/target_test.go
@@ -111,7 +111,7 @@ func AddTargets(t *testing.T, nbTargets int, chTarget chan xsapiv1.TargetConfig)
}
/*add target*/
assert.Nil(t, HTTPCli.Post("/targets", target, &target))
- t.Logf("add target %v", target.Name)
+ Debugf(t, "add target %v", target.Name)
targetEvt := <-chTarget //waiting for event targetAdd
assert.Equal(t, target.ID, targetEvt.ID)
listID[i] = target.ID
@@ -134,7 +134,7 @@ 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))
- t.Logf("add terminal %v", term.Name)
+ Debugf(t, "add terminal %v", term.Name)
termEvt := <-chTermEvt //waiting for event terminalAdd*/
assert.Equal(t, term.ID, termEvt.ID)
listTermsID[i] = term.ID
@@ -166,7 +166,7 @@ func PostTerms(t *testing.T, post string, chTermEvt chan xsapiv1.TerminalConfig)
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))
- t.Logf("%v terminal %v", post, term.Name)
+ Debugf(t, "%v terminal %v", post, term.Name)
termEvt := <-chTermEvt //waiting for event terminalStateChange
assert.Equal(t, term.ID, termEvt.ID)
assert.Equal(t, term.Status, status)
@@ -178,7 +178,7 @@ func PostTerms(t *testing.T, post string, chTermEvt chan xsapiv1.TerminalConfig)
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))
- t.Logf("check that term status %v is %v", term.Name, post)
+ Debugf(t, "check that term status %v is %v", term.Name, post)
}
}
}
@@ -195,7 +195,7 @@ func RemoveTermsTargets(t *testing.T, chTarget chan xsapiv1.TargetConfig, chTerm
termEvt := <-chTermEvt
assert.Equal(t, term.ID, termEvt.ID)
assert.NotNil(t, HTTPCli.Delete("/targets/"+targets[i].ID+"/terminals/"+terms[j].ID, &term))
- t.Logf("remove terminal %v", term.Name)
+ Debugf(t, "remove terminal %v", term.Name)
}
var tgtRes xsapiv1.TargetConfig
assert.Nil(t, HTTPCli.Delete("/targets/"+targets[i].ID, &tgtRes))
@@ -273,7 +273,7 @@ func TestTarget(t *testing.T) {
totoFileCurrent := totoFile + strconv.Itoa(i)
/*send cmd though term*/
data := []byte("echo helloWorld" + strconv.Itoa(i) + " >> " + totoFileCurrent + "\n")
- t.Logf("send following command through terminal: %v", string(data))
+ Debugf(t, "send following command through terminal: %v", string(data))
assert.Nil(t, sCli.Conn.Emit(xsapiv1.TerminalInEvent, data))
flushChannelTerm(chTerm, 50) //waiting for terminal msg
@@ -283,7 +283,7 @@ func TestTarget(t *testing.T) {
/*send cmd though term*/
data = []byte("cat " + totoFileCurrent + "\n")
- t.Logf("send following command through terminal: %v", string(data))
+ Debugf(t, "send following command through terminal: %v", string(data))
assert.Nil(t, sCli.Conn.Emit(xsapiv1.TerminalInEvent, data))
<-chTerm //cmd sent
@@ -291,7 +291,7 @@ func TestTarget(t *testing.T) {
flushChannelTerm(chTerm, 50) //flushing what remains
/*check that terminal msg is what was written before*/
assert.Equal(t, string(termOut.Stdout), "helloWorld"+strconv.Itoa(i)+"\r\n")
- t.Logf("check terminal output msg: %v", string(termOut.Stdout))
+ Debugf(t, "check terminal output msg: %v", string(termOut.Stdout))
}
PostTerms(t, "close", chTermEvt)
@@ -307,28 +307,28 @@ func TestTargetErrors(t *testing.T) {
target := xsapiv1.TargetConfig{}
var targetRes xsapiv1.TargetConfig
assert.NotNil(t, HTTPCli.Post("/targets", target, &targetRes))
- t.Logf("error while creating empty target")
+ 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))
- t.Logf("error while creating target without IP")
+ Debugf(t, "error while creating target without IP")
target.IP = "127.0.0.1"
assert.Nil(t, HTTPCli.Post("/targets", target, &targetRes))
- t.Logf("create target %v", targetRes.Name)
+ 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))
- t.Logf("error while creating empty terminal")
+ Debugf(t, "error while creating empty terminal")
term.Type = xsapiv1.TypeTermSSH
assert.NotNil(t, HTTPCli.Post("/targets/"+"1010"+"/terminals", term, &termRes))
- t.Logf("error while creating terminal on an non existing target")
+ 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))
- t.Logf("create several terminals")
+ Debugf(t, "create several terminals")
/*remove targets and terms*/
var targetArray []xsapiv1.TargetConfig
@@ -338,15 +338,15 @@ func TestTargetErrors(t *testing.T) {
assert.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))
- t.Logf("delete terminal %v", termRes.Name)
+ Debugf(t, "delete terminal %v", termRes.Name)
assert.NotNil(t, HTTPCli.Delete("/targets/"+targetArray[i].ID+"/terminals/"+termArray[j].ID, &termRes))
- t.Logf("error while deleting an already deleted terminal %v", termRes.Name)
+ 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))
- t.Logf("delete target %v", tgtRes.Name)
+ 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))
- t.Logf("error while deleting an already deleted target %v", tgtRes.Name)
+ 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 275480b..5373a15 100644
--- a/test/version_test.go
+++ b/test/version_test.go
@@ -26,11 +26,11 @@ import (
func TestVersion(t *testing.T) {
var datVersion map[string]interface{}
assert.Nil(t, HTTPCli.Get("/version", &datVersion))
- t.Log(datVersion)
+ Debug(t, datVersion)
ver, present := datVersion["version"]
assert.True(t, present)
- t.Logf("version is %s", ver.(string))
+ Debugf(t, "version is %s", ver.(string))
re := regexp.MustCompile("^v*[0-9]+.[0-9]+.[0-9]+$")
assert.True(t, re.MatchString(ver.(string)))
}
diff --git a/test/xdsserver_test.go b/test/xdsserver_test.go
index b8e98b5..89f73a6 100644
--- a/test/xdsserver_test.go
+++ b/test/xdsserver_test.go
@@ -47,6 +47,18 @@ var HTTPCli *common.HTTPClient
var logDir string
var sCli *IOSockClient
+func Debug(t *testing.T, args ...interface{}) {
+ if os.Getenv("VERBOSE") != "" {
+ t.Log(args)
+ }
+}
+
+func Debugf(t *testing.T, format string, args ...interface{}) {
+ if os.Getenv("VERBOSE") != "" {
+ t.Logf(format, args)
+ }
+}
+
func Copy(src, dst string) error {
in, err := os.Open(src)
if err != nil {