aboutsummaryrefslogtreecommitdiffstats
path: root/test/xdsserver_test.go
diff options
context:
space:
mode:
authorClément Bénier <clement.benier@iot.bzh>2018-08-14 16:29:07 +0200
committerClément Bénier <clement.benier@iot.bzh>2018-08-21 11:08:36 +0200
commite0e1d75c08ff6187acabca74261ebeb0e0893ede (patch)
tree1bc6f3a033b4db55810d4f00da325f39abdb60d3 /test/xdsserver_test.go
parent4c01e5e3fad9455b97519380babdf7e8801d8643 (diff)
tests: better handle websocket client
Change-Id: Iffc7370c52457e6d90e88e30c95b37ae3c60bce3 Signed-off-by: Clément Bénier <clement.benier@iot.bzh>
Diffstat (limited to 'test/xdsserver_test.go')
-rw-r--r--test/xdsserver_test.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/test/xdsserver_test.go b/test/xdsserver_test.go
index 76c54ea..585ad50 100644
--- a/test/xdsserver_test.go
+++ b/test/xdsserver_test.go
@@ -17,22 +17,37 @@
package xdsservertest
import (
+ "fmt"
"io"
"log"
"os"
"os/exec"
"path"
+ "sync"
"testing"
"time"
common "gerrit.automotivelinux.org/gerrit/src/xds/xds-common.git/golib"
"gerrit.automotivelinux.org/gerrit/src/xds/xds-server/lib/xsapiv1"
+ socketio_client "github.com/sebd71/go-socket.io-client"
)
+// IOSockClient
+type IOSockClient struct {
+ URL string
+ Conn *socketio_client.Client
+ Options *socketio_client.Options
+ EmitMutex *sync.Mutex
+ Connected bool
+ //ServerDiscoChan chan Disconnection
+ EscapeKeys []byte
+}
+
//global client
var HTTPCli *common.HTTPClient
var logDir string
var sdkDir string
+var sCli *IOSockClient
func Copy(src, dst string) error {
in, err := os.Open(src)
@@ -136,6 +151,37 @@ func getHTTPClient(lvl int) (*common.HTTPClient, *os.File) {
return cli, file
}
+func NewIoSocketClient(url, clientID string) (*IOSockClient, error) {
+
+ var err error
+
+ sCli := &IOSockClient{
+ URL: url,
+ EmitMutex: &sync.Mutex{},
+ Options: &socketio_client.Options{
+ Transport: "websocket",
+ Header: make(map[string][]string),
+ },
+ //ServerDiscoChan: make(chan Disconnection, 1),
+ }
+ sCli.Options.Header["XDS-SID"] = []string{clientID}
+
+ sCli.Conn, err = socketio_client.NewClient(url, sCli.Options)
+ if err != nil {
+ return nil, fmt.Errorf("IO.socket connection error: " + err.Error())
+ }
+
+ sCli.Conn.On("connection", func() {
+ sCli.Connected = true
+ })
+
+ sCli.Conn.On("disconnection", func(err error) {
+ log.Printf("WS disconnection event with err: %v\n", err)
+ sCli.Connected = false
+ })
+
+ return sCli, nil
+}
func TestMain(m *testing.M) {
launchProcess := true
log.Printf("TestMain: launchProcess is %v", launchProcess)
@@ -159,6 +205,11 @@ func TestMain(m *testing.M) {
var fileHTTPClient *os.File
HTTPCli, fileHTTPClient = getHTTPClient(lvl)
defer fileHTTPClient.Close()
+ var err error
+ sCli, err = NewIoSocketClient(prefixURL, HTTPCli.GetClientID())
+ if err != nil {
+ log.Fatal(err)
+ }
log.Printf("HTTPCli id is %v", HTTPCli.GetClientID())