summaryrefslogtreecommitdiffstats
path: root/test/xdsserver_test.go
diff options
context:
space:
mode:
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())