summaryrefslogtreecommitdiffstats
path: root/test/folders_test.go
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 /test/folders_test.go
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>
Diffstat (limited to 'test/folders_test.go')
-rw-r--r--test/folders_test.go94
1 files changed, 47 insertions, 47 deletions
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)
}