aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--test/exec_test.go25
-rw-r--r--test/sdks_test.go76
-rw-r--r--test/target_test.go13
-rw-r--r--test/xdsserver_test.go17
4 files changed, 102 insertions, 29 deletions
diff --git a/test/exec_test.go b/test/exec_test.go
index f2d48ce..ff67322 100644
--- a/test/exec_test.go
+++ b/test/exec_test.go
@@ -53,6 +53,15 @@ func flushChannelExec(channel chan xsapiv1.ExecOutMsg, ms time.Duration) {
}
func TestExec(t *testing.T) {
helloworldDir := InitExec(t)
+ chSdks := make(chan xsapiv1.SDK)
+ defer close(chSdks)
+ sdk := xsapiv1.SDKInstallArgs{
+ ID: "",
+ Filename: sdkFileName,
+ Force: false,
+ }
+ ConnectSDKStateChange(t, sCli, chSdks)
+ sdkRes := installFakeSdk(t, sdk, chSdks)
var cfgArray []xsapiv1.FolderConfig
assert.Nil(t, HTTPCli.Get("/folders", &cfgArray))
@@ -77,7 +86,12 @@ func TestExec(t *testing.T) {
chExec <- ev
})
- cmd := "cd " + fPrj.ClientPath
+ sdkSourceFile := path.Join(sdkRes.Path, "environment-setup-corei7-64-native-linux")
+ cmd := "source " + sdkSourceFile
+ cmd = cmd + " && "
+ cmd = cmd + "unset SDKTARGETSYSROOT"
+ cmd = cmd + " && "
+ cmd = cmd + "cd " + fPrj.ClientPath
cmd = cmd + " && "
cmd = cmd + "mkdir -p build"
cmd = cmd + " && "
@@ -93,7 +107,11 @@ func TestExec(t *testing.T) {
assert.Nil(t, HTTPCli.Post("/exec", exec, &execRes))
flushChannelExec(chExec, 1000)
- cmd = "cd " + fPrj.ClientPath
+ cmd = "source " + sdkSourceFile
+ cmd = cmd + " && "
+ cmd = cmd + "unset SDKTARGETSYSROOT"
+ cmd = cmd + " && "
+ cmd = cmd + "cd " + fPrj.ClientPath
cmd = cmd + "&&"
cmd = cmd + "cd build"
cmd = cmd + "&&"
@@ -107,4 +125,7 @@ func TestExec(t *testing.T) {
assert.Nil(t, err)
assert.Nil(t, HTTPCli.Delete("/folders/"+cfg.ID, &cfg))
+
+ RemoveSdk(t, sdkRes, chSdks)
+ DisconnectSDKStateChange(t, sCli)
}
diff --git a/test/sdks_test.go b/test/sdks_test.go
index 3232fa4..c00966f 100644
--- a/test/sdks_test.go
+++ b/test/sdks_test.go
@@ -17,9 +17,11 @@
package xdsservertest
import (
+ "log"
"os"
"path"
"regexp"
+ "strings"
"testing"
"time"
@@ -27,6 +29,20 @@ import (
"github.com/stretchr/testify/assert"
)
+var cpt int
+
+/*flush channel with timeout*/
+func flushChannelSdk(channel chan xsapiv1.SDK, ms time.Duration) {
+ timeoutB := false
+ for !timeoutB {
+ select {
+ case <-channel:
+ case <-time.After(ms * time.Millisecond):
+ timeoutB = true
+ }
+ }
+}
+
func ConnectSDKStateChange(t *testing.T, sCli *IOSockClient, channel chan xsapiv1.SDK) {
sCli.Conn.On(xsapiv1.EVTSDKStateChange, func(e xsapiv1.EventMsg) {
@@ -38,12 +54,42 @@ func ConnectSDKStateChange(t *testing.T, sCli *IOSockClient, channel chan xsapiv
assert.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))
+}
+
+func InitSdkDir() {
+ sdkDir := os.Getenv(envXdtSdk)
+ os.MkdirAll(sdkDir, 0755)
+ currentDir, err := os.Getwd()
+ if err != nil {
+ log.Fatal(err)
+ }
+ if err := Copy(path.Join(currentDir, sdkFile), path.Join(sdkDir, sdkFileName)); err != nil {
+ log.Fatal(err)
+ }
+}
+
+func RemoveSdk(t *testing.T, sdk xsapiv1.SDK, chSdks chan xsapiv1.SDK) {
+ assert.Nil(t, HTTPCli.Delete("/sdks/"+sdk.ID, &sdk))
+ sdkFromEvt := <-chSdks //Uninstalling
+ assert.Equal(t, sdk.ID, sdkFromEvt.ID)
+ assert.Equal(t, sdkFromEvt.Status, "Un-installing")
+ sdkFromEvt = <-chSdks //not installed
+ assert.Equal(t, sdkFromEvt.Status, "Not Installed")
+ os.RemoveAll(path.Join(os.Getenv(envXdtSdk), sdk.Profile))
+ os.Remove(strings.Replace(sdk.URL, "file://", "", 1))
+}
+
func TestSdks(t *testing.T) {
+ cpt = 0
+ InitSdkDir()
var sdkArray []xsapiv1.SDK
assert.Nil(t, HTTPCli.Get("/sdks", &sdkArray))
- _, err := os.Stat(path.Join(sdkDir, "sdks_latest.json"))
+ _, err := os.Stat(path.Join(os.Getenv(envXdtSdk), "sdks_latest.json"))
+ time.Sleep(1000 * time.Millisecond)
assert.Nil(t, err)
- t.Logf("Connect websocket with url=%v clientId=%v\n", prefixURL, HTTPCli.GetClientID())
chSdks := make(chan xsapiv1.SDK)
defer close(chSdks)
@@ -61,25 +107,31 @@ func TestSdks(t *testing.T) {
var sdkRes xsapiv1.SDK
assert.Nil(t, HTTPCli.Post("/sdks", sdk, &sdkRes))
assert.Equal(t, sdkRes.Status, "Installing")
- time.Sleep(1 * time.Millisecond)
+ sdkFromEvent := <-chSdks
+ assert.Equal(t, sdkRes.ID, sdkFromEvent.ID)
+ assert.Equal(t, sdkFromEvent.Status, "Installing")
+
assert.Nil(t, HTTPCli.Post("/sdks/abortinstall", sdk, &sdkRes))
assert.Equal(t, sdkRes.Status, "Not Installed")
- time.Sleep(1 * time.Millisecond)
- sdkFromEvent := <-chSdks
+ sdkFromEvent = <-chSdks
assert.Equal(t, sdkRes.ID, sdkFromEvent.ID)
assert.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))
assert.Equal(t, sdkRes.Status, "Installing")
- /*waiting for SDKStateChange event from channel*/
sdkFromEvent := <-chSdks
- t.Log(sdkFromEvent)
+ assert.Equal(t, sdkRes.ID, sdkFromEvent.ID)
+ assert.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, "")
return sdkFromEvent
}
@@ -94,10 +146,12 @@ func TestInstallFakeSdk(t *testing.T) {
defer close(chSdks)
ConnectSDKStateChange(t, sCli, chSdks)
installFakeSdk(t, sdk, chSdks)
- var sdkRes xsapiv1.SDK
- assert.NotNil(t, HTTPCli.Post("/sdks", sdk, &sdkRes))
+
+ /*test force install*/
sdk.Force = true
- //installFakeSdk(t, sdk, chSdks)
+ sdkRes := installFakeSdk(t, sdk, chSdks)
+ RemoveSdk(t, sdkRes, chSdks)
+ DisconnectSDKStateChange(t, sCli)
}
func TestSdksError(t *testing.T) {
@@ -108,7 +162,7 @@ func TestSdksError(t *testing.T) {
}
var sdkRes xsapiv1.SDK
assert.NotNil(t, HTTPCli.Post("/sdks", sdk, &sdkRes))
- sdk.ID = "42885c24-374e-3ef0-9723-0ce8a05191aa"
+ sdk.ID = "42885c24-374e-3ef0-9723-0c8a05191aa"
assert.NotNil(t, HTTPCli.Post("/sdks", sdk, &sdkRes))
sdk.Filename = "fake"
assert.NotNil(t, HTTPCli.Post("/sdks", sdk, &sdkRes))
diff --git a/test/target_test.go b/test/target_test.go
index 401c641..e222505 100644
--- a/test/target_test.go
+++ b/test/target_test.go
@@ -147,6 +147,13 @@ func AddTerms(t *testing.T, nbTerms int, listID []string, chTermEvt chan xsapiv1
}
func PostTerms(t *testing.T, post string, chTermEvt chan xsapiv1.TerminalConfig) {
+ var status string
+ switch post {
+ case "open":
+ status = "Open"
+ case "close":
+ status = "Closing"
+ }
var targets []xsapiv1.TargetConfig
assert.Nil(t, HTTPCli.Get("/targets", &targets))
for i := 0; i < len(targets); i++ {
@@ -155,12 +162,14 @@ func PostTerms(t *testing.T, post string, chTermEvt chan xsapiv1.TerminalConfig)
listTermsID := make([]string, len(terms))
for j := 0; j < len(terms); j++ {
var term xsapiv1.TerminalConfig
- assert.Nil(t, HTTPCli.Post("/targets/"+targets[i].ID+"/terminals/"+terms[j].ID+"/"+post, term, &term))
+ assert.Nil(t, HTTPCli.Post("/targets/"+targets[i].ID+"/terminals/"+terms[j].ID+"/"+post, terms[j], &term))
termEvt := <-chTermEvt //waiting for event terminalStateChange
assert.Equal(t, term.ID, termEvt.ID)
- assert.True(t, strings.EqualFold(termEvt.Status, post))
+ assert.Equal(t, term.Status, status)
+ assert.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))
diff --git a/test/xdsserver_test.go b/test/xdsserver_test.go
index 585ad50..ba56321 100644
--- a/test/xdsserver_test.go
+++ b/test/xdsserver_test.go
@@ -22,7 +22,6 @@ import (
"log"
"os"
"os/exec"
- "path"
"sync"
"testing"
"time"
@@ -46,7 +45,6 @@ type IOSockClient struct {
//global client
var HTTPCli *common.HTTPClient
var logDir string
-var sdkDir string
var sCli *IOSockClient
func Copy(src, dst string) error {
@@ -81,7 +79,7 @@ func initEnv(launchProcess bool) {
if err := os.Setenv(envRootCfgDir, rootTestLog); err != nil {
log.Fatal(err)
}
- sdkDir = rootTestLog + "/sdks/"
+ sdkDir := rootTestLog + "/sdks/"
if err := os.Setenv(envXdtSdk, sdkDir); err != nil {
log.Fatal(err)
}
@@ -98,14 +96,6 @@ func initEnv(launchProcess bool) {
os.MkdirAll(rootTestLog, 0755)
logDir = rootTestLog + "/logs/"
os.MkdirAll(logDir, 0755)
- os.MkdirAll(sdkDir, 0755)
- currentDir, err := os.Getwd()
- if err != nil {
- log.Fatal(err)
- }
- if err := Copy(path.Join(currentDir, sdkFile), path.Join(sdkDir, sdkFileName)); err != nil {
- log.Fatal(err)
- }
}
func launchXdsServer(proc **os.Process) *os.File {
@@ -180,11 +170,12 @@ func NewIoSocketClient(url, clientID string) (*IOSockClient, error) {
sCli.Connected = false
})
+ log.Printf("Connect websocket with url=%v clientId=%v\n", prefixURL, HTTPCli.GetClientID())
return sCli, nil
}
func TestMain(m *testing.M) {
launchProcess := true
- log.Printf("TestMain: launchProcess is %v", launchProcess)
+ log.Printf("TestMain: launchProcess is %v, so launching xds-server", launchProcess)
initEnv(launchProcess)
var proc *os.Process
@@ -211,8 +202,6 @@ func TestMain(m *testing.M) {
log.Fatal(err)
}
- log.Printf("HTTPCli id is %v", HTTPCli.GetClientID())
-
if HTTPCli == nil {
log.Fatal("HTTPCLi is nil")
}