-
Notifications
You must be signed in to change notification settings - Fork 2
/
feed_online_test.go
43 lines (36 loc) · 956 Bytes
/
feed_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
//go:build requiresOnline
package gotiktoklive
import (
"github.com/stretchr/testify/assert"
"sort"
"testing"
)
func TestFeedItem(t *testing.T) {
tiktok, err := NewTikTok()
if !assert.NoError(t, err) {
return
}
feed := tiktok.NewFeed()
items := []*LiveStream{}
i := 0
for {
feedItem, err := feed.Next()
if err != nil {
t.Fatal(err)
}
items = append(items, feedItem.LiveStreams...)
i++
t.Logf("%d : %d, %v", feedItem.Extra.MaxTime, len(feedItem.LiveStreams), feedItem.Extra.HasMore)
for _, stream := range feedItem.LiveStreams {
t.Logf("%s : %d viewers, %s", stream.Room.Owner.Nickname, stream.Room.UserCount, stream.LiveReason)
}
if !feedItem.Extra.HasMore || i > 5 {
break
}
}
t.Logf("Found %d items, over %d requests", len(items), i)
sort.Slice(items, func(i, j int) bool {
return items[i].Room.UserCount > items[j].Room.UserCount
})
t.Logf("Setting username to %s", items[0].Room.Owner.Username)
}