forked from imperatrona/twitter-scraper
-
Notifications
You must be signed in to change notification settings - Fork 1
/
tweet_test.go
126 lines (105 loc) · 2.46 KB
/
tweet_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
126
package twitterscraper_test
import (
"testing"
twitterscraper "github.com/imperatrona/twitter-scraper"
)
var testDeleteTweetId string
func TestCreateTweet(t *testing.T) {
if skipAuthTest {
t.Skip("Skipping test due to environment variable")
}
var err error
var tweet *twitterscraper.Tweet
tweet, err = testScraper.CreateTweet(twitterscraper.NewTweet{
Text: "i love hollywood 🖤",
Medias: nil,
})
if tweet != nil {
testDeleteTweetId = tweet.ID
}
if err != nil {
t.Error(err)
}
}
func TestCreateTweetWithMedia(t *testing.T) {
if skipAuthTest {
t.Skip("Skipping test due to environment variable")
}
var err error
var video *twitterscraper.Media
video, err = testScraper.UploadMedia("./photo.jpg")
if err != nil {
t.Error(err)
}
var photo *twitterscraper.Media
photo, err = testScraper.UploadMedia("./video.mp4")
if err != nil {
t.Error(err)
}
var tweet *twitterscraper.Tweet
tweet, err = testScraper.CreateTweet(twitterscraper.NewTweet{
Text: "3 more seconds till i get 🖤",
Medias: []*twitterscraper.Media{
photo,
video,
},
})
if tweet != nil {
testDeleteTweetId = tweet.ID
}
if err != nil {
t.Error(err)
}
}
func TestDeleteTweet(t *testing.T) {
if skipAuthTest {
t.Skip("Skipping test due to environment variable")
}
if testDeleteTweetId == "" {
t.Skip("run TestCreateTweet before")
}
if err := testScraper.DeleteTweet(testDeleteTweetId); err != nil {
t.Error(err)
}
}
func TestCreateRetweet(t *testing.T) {
if skipAuthTest {
t.Skip("Skipping test due to environment variable")
}
if _, err := testScraper.CreateRetweet("1792634158977568997"); err != nil {
t.Error(err)
}
}
func TestDeleteRetweet(t *testing.T) {
if skipAuthTest {
t.Skip("Skipping test due to environment variable")
}
if err := testScraper.DeleteRetweet("1792634158977568997"); err != nil {
t.Error(err)
}
}
func TestLikeAndUnlikeTweet(t *testing.T) {
if skipAuthTest {
t.Skip("Skipping test due to environment variable")
}
tweetId := "1792634158977568997"
if err := testScraper.LikeTweet(tweetId); err != nil {
t.Error(err)
}
if err := testScraper.UnlikeTweet(tweetId); err != nil {
t.Error(err)
}
}
func TestGetTweetRetweeters(t *testing.T) {
if skipAuthTest {
t.Skip("Skipping test due to environment variable")
}
tweetId := "1792634158977568997"
retweeters, _, err := testScraper.GetTweetRetweeters(tweetId, 20, "")
if err != nil {
t.Error(err)
}
if len(retweeters) == 0 {
t.Error("0 tweet retweeters")
}
}