aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorClément Bénier <clement.benier@iot.bzh>2018-07-27 11:37:51 +0200
committerClément Bénier <clement.benier@iot.bzh>2018-08-21 11:08:36 +0200
commita70639fb60bfbe5899f580a48222b47f435ca1f8 (patch)
treee4af15b94f1c1255ab8cae03a236b9cfd0f7ebc8 /test
parentdb0df685e9dc40fdd53113caaac976d12fd73435 (diff)
functionnal test: install test install fake sdk
install a fake sdk and waiting for event to end the test Change-Id: I5c2125f32a1fb4a80f9b251174d15117eef26f9a Signed-off-by: Clément Bénier <clement.benier@iot.bzh>
Diffstat (limited to 'test')
-rw-r--r--test/config.go2
-rwxr-xr-xtest/fixtures/poky-agl-glibc-x86_64-gcc_crosssdk-native_x86_64-toolchain-1.0.2.shbin0 -> 2002 bytes
-rw-r--r--test/sdks_test.go66
-rw-r--r--test/xdsserver_test.go29
4 files changed, 84 insertions, 13 deletions
diff --git a/test/config.go b/test/config.go
index 8fea851..a551d4f 100644
--- a/test/config.go
+++ b/test/config.go
@@ -27,4 +27,6 @@ const (
envXdtSdk = "XDT_SDK"
envXdsServerWorkspaceDir = "XDS_SERVER_WORKSPACE_DIR"
envXdsServerRootCfgDir = "XDS_SERVER_ROOT_CFG_DIR"
+ sdkFileName = "poky-agl-glibc-x86_64-gcc_crosssdk-native_x86_64-toolchain-1.0.2.sh"
+ sdkFile = "fixtures/" + sdkFileName
)
diff --git a/test/fixtures/poky-agl-glibc-x86_64-gcc_crosssdk-native_x86_64-toolchain-1.0.2.sh b/test/fixtures/poky-agl-glibc-x86_64-gcc_crosssdk-native_x86_64-toolchain-1.0.2.sh
new file mode 100755
index 0000000..7781335
--- /dev/null
+++ b/test/fixtures/poky-agl-glibc-x86_64-gcc_crosssdk-native_x86_64-toolchain-1.0.2.sh
Binary files differ
diff --git a/test/sdks_test.go b/test/sdks_test.go
index 5efd8fc..6319542 100644
--- a/test/sdks_test.go
+++ b/test/sdks_test.go
@@ -19,16 +19,21 @@ package xdsservertest
import (
"fmt"
"log"
+ "os"
+ "path"
"regexp"
"sync"
"testing"
"time"
+ "gerrit.automotivelinux.org/gerrit/src/xds/xds-agent/lib/xaapiv1"
"gerrit.automotivelinux.org/gerrit/src/xds/xds-server/lib/xsapiv1"
socketio_client "github.com/sebd71/go-socket.io-client"
"github.com/stretchr/testify/assert"
)
+var ch chan xsapiv1.SDK
+
// Disconnection Channel used to notify XDS Server disconnection
//type Disconnection struct {
// error string
@@ -68,20 +73,20 @@ func NewIoSocketClient(url, clientID string) (*IOSockClient, error) {
}
sCli.Conn.On("connection", func() {
- log.Printf("BBBBBBBBBBBBBBBB:::WS connection event")
sCli.Connected = true
})
sCli.Conn.On("disconnection", func(err error) {
- log.Printf("AAAAAAAAAAAA:::WS disconnection event with err: %v\n", err)
+ log.Printf("WS disconnection event with err: %v\n", err)
sCli.Connected = false
})
- sCli.Conn.On(xsapiv1.EVTSDKManagement, func(data interface{}) {
- log.Printf("WS disconnection event with err: %v\n", data)
+ sCli.Conn.On(xsapiv1.EVTSDKStateChange, func(e xsapiv1.EventMsg) {
+ sdk, _ := e.DecodeSDKEvent()
+ ch <- sdk
})
- args := xsapiv1.EventRegisterArgs{Name: xsapiv1.EVTSDKManagement}
+ args := xsapiv1.EventRegisterArgs{Name: xsapiv1.EVTSDKStateChange}
if err := HTTPCli.Post("/events/register", args, nil); err != nil {
return sCli, err
}
@@ -92,17 +97,17 @@ func NewIoSocketClient(url, clientID string) (*IOSockClient, error) {
func TestSdks(t *testing.T) {
var sdkArray []xsapiv1.SDK
assert.Nil(t, HTTPCli.Get("/sdks", &sdkArray))
- t.Log(sdkArray[0])
-
+ _, err := os.Stat(path.Join(sdkDir, "sdks_latest.json"))
+ assert.Nil(t, err)
t.Logf("Connect websocket with url=%v clientId=%v\n", prefixURL, HTTPCli.GetClientID())
- IOSkClient, err := NewIoSocketClient(prefixURL, HTTPCli.GetClientID())
+ _, err = NewIoSocketClient(prefixURL, HTTPCli.GetClientID())
if err != nil {
t.Fatal(err)
}
- t.Log(IOSkClient)
- //for i := 0; i < len(sdkArray); i++ {
- for i := 0; i < 1; i++ {
+ ch = make(chan xsapiv1.SDK)
+
+ 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")
@@ -114,7 +119,42 @@ func TestSdks(t *testing.T) {
var sdkRes xsapiv1.SDK
assert.Nil(t, HTTPCli.Post("/sdks", sdk, &sdkRes))
assert.Equal(t, sdkRes.Status, "Installing")
- //t.Log(sdkRes)
- time.Sleep(1 * time.Second)
+ time.Sleep(1 * time.Millisecond)
+ assert.Nil(t, HTTPCli.Post("/sdks/abortinstall", sdk, &sdkRes))
+ assert.Equal(t, sdkRes.Status, "Not Installed")
+ time.Sleep(1 * time.Millisecond)
+ sdkFromEvent := <-ch
+ assert.Equal(t, sdkRes.ID, sdkFromEvent.ID)
+ assert.Equal(t, sdkRes.Status, sdkFromEvent.Status)
+ }
+}
+
+func TestInstallFakeSdk(t *testing.T) {
+ sdk := xaapiv1.SDKInstallArgs{
+ ID: "",
+ Filename: sdkFileName,
+ Force: false,
+ }
+ var sdkRes xsapiv1.SDK
+ assert.Nil(t, HTTPCli.Post("/sdks", sdk, &sdkRes))
+ assert.Equal(t, sdkRes.Status, "Installing")
+ /*waiting for SDKStateChange event from channel*/
+ sdkFromEvent := <-ch
+ t.Log(sdkFromEvent)
+ assert.Equal(t, sdkRes.ID, sdkFromEvent.ID)
+ assert.Equal(t, "Installed", sdkFromEvent.Status)
+}
+
+func TestSdksError(t *testing.T) {
+ sdk := xaapiv1.SDKInstallArgs{
+ ID: "",
+ Filename: "",
+ Force: false,
}
+ var sdkRes xsapiv1.SDK
+ assert.NotNil(t, HTTPCli.Post("/sdks", sdk, &sdkRes))
+ sdk.ID = "42885c24-374e-3ef0-9723-0ce8a05191aa"
+ assert.NotNil(t, HTTPCli.Post("/sdks", sdk, &sdkRes))
+ sdk.Filename = "fake"
+ assert.NotNil(t, HTTPCli.Post("/sdks", sdk, &sdkRes))
}
diff --git a/test/xdsserver_test.go b/test/xdsserver_test.go
index 5722d31..76c54ea 100644
--- a/test/xdsserver_test.go
+++ b/test/xdsserver_test.go
@@ -17,9 +17,11 @@
package xdsservertest
import (
+ "io"
"log"
"os"
"os/exec"
+ "path"
"testing"
"time"
@@ -32,6 +34,26 @@ var HTTPCli *common.HTTPClient
var logDir string
var sdkDir string
+func Copy(src, dst string) error {
+ in, err := os.Open(src)
+ if err != nil {
+ return err
+ }
+ defer in.Close()
+
+ out, err := os.Create(dst)
+ if err != nil {
+ return err
+ }
+ defer out.Close()
+
+ _, err = io.Copy(out, in)
+ if err != nil {
+ return err
+ }
+ return out.Close()
+}
+
func initEnv(launchProcess bool) {
if launchProcess {
cmd := exec.Command("killall", "-9", "xds-server")
@@ -62,6 +84,13 @@ func initEnv(launchProcess bool) {
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 {