forked from Davincible/gotiktoklive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
feed_test.go
40 lines (33 loc) · 936 Bytes
/
feed_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
package gotiktoklive
import (
"sort"
"testing"
"github.com/ryusuke410/gotiktoklive/tests"
)
func TestFeedItem(t *testing.T) {
tiktok := NewTikTok()
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
})
tests.USERNAME = items[0].Room.Owner.Username
t.Logf("Setting username to %s", items[0].Room.Owner.Username)
}