-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjoiner_test.go
48 lines (38 loc) · 1.16 KB
/
joiner_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package xconn_test
import (
"context"
"fmt"
"net"
"testing"
"github.com/gammazero/nexus/v3/router"
"github.com/gammazero/nexus/v3/wamp"
"github.com/stretchr/testify/require"
"github.com/xconnio/xconn-go"
)
func startRouter(t *testing.T, realm string) net.Listener {
r, err := router.NewRouter(&router.Config{RealmConfigs: []*router.RealmConfig{
{URI: wamp.URI(realm), AnonymousAuth: true},
}}, nil)
require.NoError(t, err)
require.NotNil(t, r)
server := router.NewWebsocketServer(r)
closer, err := server.ListenAndServe("localhost:0")
require.NoError(t, err)
require.NotNil(t, closer)
listener := closer.(net.Listener)
require.NotNil(t, listener)
return listener
}
func TestJoin(t *testing.T) {
listener := startRouter(t, "realm1")
defer func() { _ = listener.Close() }()
address := fmt.Sprintf("ws://%s/ws", listener.Addr().String())
var joiner xconn.WebSocketJoiner
base, err := joiner.Join(context.Background(), address, "realm1", &xconn.WSDialerConfig{
SubProtocol: xconn.JsonWebsocketProtocol,
})
require.NoError(t, err)
require.NotNil(t, base)
require.Equal(t, "realm1", base.Realm())
require.Equal(t, "anonymous", base.AuthRole())
}