-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlive_online_test.go
125 lines (112 loc) · 2.25 KB
/
live_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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
//go:build requiresOnline
package gotiktoklive
import (
"log/slog"
"testing"
"time"
"github.com/steampoweredtaco/gotiktoklive/test_types"
)
func TestLiveTrackUser(t *testing.T) {
tiktok, err := NewTikTok()
if err != nil {
t.Fatal(err)
}
live, err := tiktok.TrackUser(test_types.USERNAME)
if err != nil {
t.Fatal(err)
}
timeout := time.After(5 * time.Second)
eventCounter := 0
for {
select {
case event := <-live.Events:
t.Logf("%T", event)
eventCounter++
case <-timeout:
if eventCounter < 10 {
t.Fatal("Less than 10 events received.. Something seems off")
}
return
}
}
}
func TestLivePriceList(t *testing.T) {
tiktok, err := NewTikTok()
if err != nil {
t.Fatal(err)
}
priceList, err := tiktok.GetPriceList()
if err != nil {
t.Fatal(err)
}
t.Logf("Fetched %d prices", len(priceList.PriceList))
}
func TestLiveDownload(t *testing.T) {
slog.SetLogLoggerLevel(slog.LevelDebug)
tiktok, err := NewTikTok(SigningApiKey(test_types.APIKEY))
if err != nil {
t.Fatal(err)
}
live, err := tiktok.TrackUser(test_types.USERNAME)
if err != nil {
t.Fatal(err)
}
done := make(chan struct{})
go func() {
defer func() {
done <- struct{}{}
}()
err = live.DownloadStream()
if err != nil {
t.Fatal(err)
}
}()
select {
case _ = <-done:
t.Log("command exited")
case <-time.After(12 * time.Second):
t.Log("test complete")
}
live.Close()
live, err = tiktok.TrackUser(test_types.USERNAME)
if err != nil {
t.Fatal(err)
}
done = make(chan struct{})
go func() {
defer func() {
done <- struct{}{}
}()
err = live.DownloadStream("my-test-download.mkv")
if err != nil {
t.Fatal(err)
}
}()
select {
case _ = <-done:
t.Log("command exited")
case <-time.After(4 * time.Hour):
t.Log("test complete")
}
live.Close()
}
// func TestRankList(t *testing.T) {
// tiktok := gotiktoklive.NewTikTok()
// live, err := tiktok.TrackUser(USERNAME)
// if err != nil {
// t.Fatal(err)
// }
//
// tiktok.LogRequests = true
// rankList, err := live.GetRankList()
// if err != nil {
// t.Fatal(err)
// }
//
// if len(rankList.Ranks) == 0 {
// t.Fatal("No ranked users found")
// }
//
// topUser := rankList.Ranks[0]
// t.Logf("Top user (%s) has donated %d coins", topUser.User.Nickname, topUser.Score)
// }