aboutsummaryrefslogtreecommitdiffstats
path: root/test/sdks_test.go
diff options
context:
space:
mode:
authorClément Bénier <clement.benier@iot.bzh>2018-08-20 15:43:22 +0200
committerClément Bénier <clement.benier@iot.bzh>2018-08-21 11:08:36 +0200
commit83fad88204387d196f755c718de40828c08dc7ac (patch)
treec943126bf4baac0a365652505a283df664f2ea85 /test/sdks_test.go
parentcf3266b208d3ba0fb8f172c29725768bbd41d509 (diff)
test exec/sdk: use sdk for building exec project
source sdk before building helloworld project fix sdks misconfiguration and multiple sdk installs Change-Id: I019e6b6e2704737774e93f08fb79d2f4a84a12b9 Signed-off-by: Clément Bénier <clement.benier@iot.bzh>
Diffstat (limited to 'test/sdks_test.go')
-rw-r--r--test/sdks_test.go76
1 files changed, 65 insertions, 11 deletions
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))