-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathurl_parser_test.go
58 lines (49 loc) · 1.46 KB
/
url_parser_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
49
50
51
52
53
54
55
56
57
58
package socketio
import (
"testing"
)
func testHandshakeUrls(t *testing.T, rawUrls []string, expected string) {
for _, raw := range rawUrls {
u, err := newURLParser(raw)
if err != nil {
t.Errorf("NewUrl error: %s", err)
}
if u.handshake() != expected {
t.Errorf("Wrong handshake formatted url, expected: %s, actual: %s", expected, u.handshake())
}
}
}
func testWebsocketUrls(t *testing.T, rawUrls []string, expected string) {
for _, raw := range rawUrls {
u, err := newURLParser(raw)
if err != nil {
t.Errorf("NewUrl error: %s", err)
}
ws := u.websocket("session_id")
if ws != expected {
t.Errorf("Wrong websocket formatted url, expected: %s, actual: %s", expected, ws)
}
}
}
func TestHandshakeUrl(t *testing.T) {
testHandshakeUrls(t,
[]string{"server.com", "http://server.com"},
"http://server.com/socket.io/1")
testHandshakeUrls(t,
[]string{"server.com/path", "http://server.com/path"},
"http://server.com/path/socket.io/1")
testHandshakeUrls(t,
[]string{"https://server.com"},
"https://server.com/socket.io/1")
}
func TestWebsocketUrl(t *testing.T) {
testWebsocketUrls(t,
[]string{"server.com", "http://server.com"},
"ws://server.com/socket.io/1/websocket/session_id")
testWebsocketUrls(t,
[]string{"server.com/path", "http://server.com/path"},
"ws://server.com/path/socket.io/1/websocket/session_id")
testWebsocketUrls(t,
[]string{"https://server.com"},
"wss://server.com/socket.io/1/websocket/session_id")
}