diff options
author | Clément Bénier <clement.benier@iot.bzh> | 2018-07-27 11:37:51 +0200 |
---|---|---|
committer | Clément Bénier <clement.benier@iot.bzh> | 2018-08-21 11:08:36 +0200 |
commit | a70639fb60bfbe5899f580a48222b47f435ca1f8 (patch) | |
tree | e4af15b94f1c1255ab8cae03a236b9cfd0f7ebc8 /test/sdks_test.go | |
parent | db0df685e9dc40fdd53113caaac976d12fd73435 (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/sdks_test.go')
-rw-r--r-- | test/sdks_test.go | 66 |
1 files changed, 53 insertions, 13 deletions
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)) } |