forked from Noooste/azuretls-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebsocket_test.go
67 lines (55 loc) · 1.5 KB
/
websocket_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
59
60
61
62
63
64
65
66
67
package azuretls_test
import (
"github.com/Noooste/azuretls-client"
"testing"
)
func TestSession_Websocket(t *testing.T) {
s := azuretls.NewSession()
_, err := s.NewWebsocket("", 0, 0)
if err == nil {
t.Fatal("TestSession_Websocket failed, expected: error, got: nil")
}
ws, err := s.NewWebsocket(
"wss://demo.piesocket.com/v3/channel_123?api_key=VCXCEuvhGcBDP7XhiJJUDvR1e1D3eiVjgZ9VRiaV¬ify_self",
1024, 1024,
azuretls.OrderedHeaders{
{"User-Agent", "fhttp"},
})
if err != nil {
t.Fatal(err)
}
if ws == nil {
t.Fatal("TestSession_Websocket failed, expected: *Websocket, got: nil")
}
if err = ws.WriteJSON(map[string]string{
"event": "new_message",
}); err != nil {
t.Fatal(err)
}
}
func TestSession_WebsocketDiscord(t *testing.T) {
session := azuretls.NewSession()
defer session.Close()
ws, err := session.NewWebsocket("wss://gateway.discord.gg/?encoding=etf&v=9&compress=zlib-stream", 1024, 1024, azuretls.OrderedHeaders{
{"Host"},
{"Connection"},
{"Pragma", "no-cache"},
{"Cache-Control", "no-cache"},
{"User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36"},
{"Upgrade"},
{"Origin", "https://discord.com"},
{"Sec-WebSocket-Version"},
{"Accept-Encoding", "gzip, deflate, br"},
{"Accept-Language", "en-US,en;q=0.9"},
{"Sec-WebSocket-Key"},
{"Sec-WebSocket-Extensions"},
})
if err != nil {
t.Fatal(err)
return
}
_, _, err = ws.ReadMessage()
if err != nil {
t.Fatal(err)
}
}