aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorClément Bénier <clement.benier@iot.bzh>2018-07-19 15:25:26 +0200
committerClément Bénier <clement.benier@iot.bzh>2018-08-21 11:08:35 +0200
commit59ecda69d26eeb6461a6b2f9e2e5ec13a1cec311 (patch)
tree686c0cebcbf8e0f7d82dbc104bdd370a312154f5 /test
parent4121746213075b785adf24eec17eb0bdf49199c3 (diff)
functionnal test: update and add tests
- TestFolders: update - TestFoldersEmptyValues - TestFoldersPathMapConfig Change-Id: I04dcbcbe6d8fc80ed3ef2cabbcf5dfd2952d1635 Signed-off-by: Clément Bénier <clement.benier@iot.bzh>
Diffstat (limited to 'test')
-rw-r--r--test/xdsserver_test.go140
1 files changed, 120 insertions, 20 deletions
diff --git a/test/xdsserver_test.go b/test/xdsserver_test.go
index bab7f68..75f4f92 100644
--- a/test/xdsserver_test.go
+++ b/test/xdsserver_test.go
@@ -17,9 +17,11 @@
package xdsservertest
import (
+ "io/ioutil"
"log"
"net"
"os"
+ "os/exec"
"regexp"
"strings"
"testing"
@@ -35,6 +37,11 @@ var HTTPCli *common.HTTPClient
var logDir string
func initEnv() {
+ cmd := exec.Command("killall", "-9", "xds-server")
+ if err := cmd.Start(); err != nil {
+ log.Fatal(err)
+ }
+ cmd.Wait()
rootTestLog := "/tmp/xds-server-test"
if err := os.Setenv(envRootCfgDir, rootTestLog); err != nil {
log.Fatal(err)
@@ -137,20 +144,20 @@ func TestVersion(t *testing.T) {
}
func TestConfig(t *testing.T) {
- var datConfig map[string]interface{}
- assert.Nil(t, HTTPCli.Get("/config", &datConfig))
+ var cfg xsapiv1.APIConfig
+ assert.Nil(t, HTTPCli.Get("/config", &cfg))
- builder, present := datConfig["builder"].(map[string]interface{})
- assert.True(t, present)
- ip, present := builder["ip"]
+ 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
+ pathMap, present := cfg.SupportedSharing["PathMap"]
assert.True(t, present)
- assert.True(t, CheckIP(ip.(string)))
+ assert.True(t, pathMap)
+ assert.True(t, CheckIP(cfg.Builder.IP))
}
func TestFolders(t *testing.T) {
- var datFolder []interface{}
- assert.Nil(t, HTTPCli.Get("/folders", &datFolder))
- t.Log(datFolder)
- assert.Equal(t, len(datFolder), 0)
+ var cfgArray []xsapiv1.FolderConfig
+ assert.Nil(t, HTTPCli.Get("/folders", &cfgArray))
+ assert.Equal(t, len(cfgArray), 0)
fPrj := xsapiv1.FolderConfig{
Label: "testproject",
@@ -164,7 +171,6 @@ func TestFolders(t *testing.T) {
var cfg xsapiv1.FolderConfig
assert.Nil(t, HTTPCli.Post("/folders", fPrj, &cfg))
assert.NotNil(t, cfg)
- t.Log(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]+$")
@@ -181,19 +187,113 @@ func TestFolders(t *testing.T) {
isCfgPrjMatch(fPrj, cfg)
var cfg2 xsapiv1.FolderConfig
assert.Nil(t, HTTPCli.Get("/folders/"+cfg.ID, &cfg2))
- t.Log(cfg2)
isCfgPrjMatch(fPrj, cfg2)
+ assert.Nil(t, HTTPCli.Get("/folders", &cfgArray))
+ assert.Equal(t, len(cfgArray), 1)
+
//call with the same uid create error
assert.NotNil(t, HTTPCli.Post("/folders", cfg, &cfg))
- //assert.Equal(t, cfg.DefaultSdk, "true")
- //call with the same uid
- //serverpath nil
- //serverpath already exists
+ /*create/delete folders*/
+ var cfgArrayBis []xsapiv1.FolderConfig
+ assert.Nil(t, HTTPCli.Post("/folders", fPrj, &cfg))
+ assert.Nil(t, HTTPCli.Post("/folders", fPrj, &cfg))
+ assert.Nil(t, HTTPCli.Get("/folders", &cfgArray))
+ assert.Equal(t, len(cfgArray), 3)
+ assert.Nil(t, HTTPCli.Delete("/folders/"+cfgArray[1].ID, &cfg))
+ 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))
+ 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))
+ assert.Equal(t, cfg, cfgArray[2])
+ assert.Nil(t, HTTPCli.Get("/folders", &cfgArrayBis))
+ assert.Equal(t, len(cfgArrayBis), 0)
}
-//func TestRegister(t *testing.T) {
-// var client := common.HTTPClient
-// client.Get("/folders", folders)
-//}
+func TestFoldersEmptyValues(t *testing.T) {
+ fPrj := xsapiv1.FolderConfig{
+ Label: "testproject",
+ ClientPath: logDir + "testproject",
+ Type: xsapiv1.TypePathMap,
+ ClientData: "clientdatatest",
+ DataPathMap: xsapiv1.PathMapConfig{
+ ServerPath: "",
+ },
+ }
+ var cfg xsapiv1.FolderConfig
+ /*ServerPath is empty*/
+ assert.NotNil(t, HTTPCli.Post("/folders", fPrj, &cfg))
+
+ fPrj.DataPathMap.ServerPath = logDir + "sameserverpath"
+ fPrj.ClientPath = ""
+ /*ClientPath is Empty*/
+ assert.NotNil(t, HTTPCli.Post("/folders", fPrj, &cfg))
+
+ fPrj.ClientPath = "logDir"
+ fPrj.Type = ""
+ /*Type is empty*/
+ assert.NotNil(t, HTTPCli.Post("/folders", fPrj, &cfg))
+
+ var cfgArray []xsapiv1.FolderConfig
+ assert.Nil(t, HTTPCli.Get("/folders", &cfgArray))
+ assert.Equal(t, len(cfgArray), 0)
+}
+
+func TestFoldersPathMapConfig(t *testing.T) {
+ fPrj := xsapiv1.FolderConfig{
+ Label: "testproject",
+ ClientPath: logDir + "clientpathtest",
+ Type: xsapiv1.TypePathMap,
+ ClientData: "clientdatatest",
+ DataPathMap: xsapiv1.PathMapConfig{
+ ServerPath: logDir + "serverpath",
+ CheckFile: "checkfile",
+ },
+ }
+ var cfg xsapiv1.FolderConfig
+ /*file not present*/
+ assert.NotNil(t, HTTPCli.Post("/folders", fPrj, &cfg))
+
+ var checkFileClient = fPrj.ClientPath + "/checkfile"
+ var checkFileServer = fPrj.DataPathMap.ServerPath + "/checkfile"
+
+ /*create file*/
+ os.MkdirAll(fPrj.ClientPath, 0755)
+ fPrj.DataPathMap.CheckFile = checkFileClient
+ 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)
+ }
+ if err := os.Symlink(checkFileClient, checkFileServer); err != nil {
+ t.Log(err)
+ }
+ /*file content differ*/
+ assert.NotNil(t, HTTPCli.Post("/folders", fPrj, &cfg))
+
+ /*write same message*/
+ if _, err := file.WriteString(fPrj.DataPathMap.CheckContent); err != nil {
+ t.Log(err)
+ }
+ assert.Nil(t, HTTPCli.Post("/folders", fPrj, &cfg))
+
+ /*check server msg: ServerUID needed*/
+ 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)
+ }
+ assert.Equal(t, msg, string(data))
+
+ assert.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)
+}