-
Notifications
You must be signed in to change notification settings - Fork 2
/
wss_online_test.go
75 lines (64 loc) · 1.34 KB
/
wss_online_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
68
69
70
71
72
73
74
75
//go:build requiresOnline
package gotiktoklive
import (
"github.com/stretchr/testify/assert"
"sync"
"testing"
"time"
"github.com/steampoweredtaco/gotiktoklive/test_types"
"golang.org/x/net/context"
)
func TestWebsocket(t *testing.T) {
tiktok, err := NewTikTok()
if !assert.NoError(t, err) {
return
}
tiktok.Debug = true
tiktok.debugHandler = func(i ...interface{}) {
t.Log(i...)
}
id, err := tiktok.getRoomID(test_types.USERNAME)
if !assert.NoError(t, err) {
return
}
live := Live{
t: tiktok,
ID: id,
wg: &sync.WaitGroup{},
Events: make(chan Event, 100),
}
ctx, cancel := context.WithCancel(context.Background())
live.done = ctx.Done
live.close = func() {
cancel()
close(live.Events)
}
err = live.getRoomData()
if !assert.NoError(t, err) {
return
}
if live.wsURL == "" {
t.Fatal("No websocket url provided")
}
t.Logf("Ws url: %s, %+v", live.wsURL, live.wsParams)
if err := live.connect(live.wsURL, live.wsParams); err != nil {
t.Fatal(err)
}
tiktok.wg.Add(2)
go live.readSocket()
go live.sendPing()
timeout := time.After(5 * time.Second)
for {
select {
case <-timeout:
return
case event := <-live.Events:
switch e := event.(type) {
case UserEvent:
t.Logf("%T: %s (%s) %s", e, e.User.Nickname, e.User.Nickname, e.Event)
default:
t.Logf("%T: %+v", e, e)
}
}
}
}