2019-09-21 12:18:34 +03:00
|
|
|
package twitterscraper
|
|
|
|
|
|
|
|
|
|
import (
|
2020-06-12 21:31:08 +08:00
|
|
|
"context"
|
2019-09-21 12:18:34 +03:00
|
|
|
"testing"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestGetTweets(t *testing.T) {
|
|
|
|
|
count := 0
|
2020-12-11 20:58:49 +02:00
|
|
|
maxTweetsNbr := 300
|
|
|
|
|
dupcheck := make(map[string]bool)
|
2020-06-15 16:16:08 +03:00
|
|
|
for tweet := range GetTweets(context.Background(), "Twitter", maxTweetsNbr) {
|
2019-09-21 12:18:34 +03:00
|
|
|
if tweet.Error != nil {
|
|
|
|
|
t.Error(tweet.Error)
|
|
|
|
|
} else {
|
|
|
|
|
count++
|
|
|
|
|
if tweet.ID == "" {
|
|
|
|
|
t.Error("Expected tweet ID is not empty")
|
2020-12-11 20:58:49 +02:00
|
|
|
} else {
|
|
|
|
|
if dupcheck[tweet.ID] {
|
|
|
|
|
t.Errorf("Detect duplicated tweet ID: %s", tweet.ID)
|
|
|
|
|
} else {
|
|
|
|
|
dupcheck[tweet.ID] = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if tweet.UserID == "" {
|
|
|
|
|
t.Error("Expected tweet UserID is not empty")
|
2019-09-21 12:18:34 +03:00
|
|
|
}
|
2020-06-15 16:38:51 +03:00
|
|
|
if tweet.Username == "" {
|
|
|
|
|
t.Error("Expected tweet Username is not empty")
|
|
|
|
|
}
|
2019-09-21 12:18:34 +03:00
|
|
|
if tweet.PermanentURL == "" {
|
|
|
|
|
t.Error("Expected tweet PermanentURL is not empty")
|
|
|
|
|
}
|
|
|
|
|
if tweet.Text == "" {
|
|
|
|
|
t.Error("Expected tweet Text is not empty")
|
|
|
|
|
}
|
|
|
|
|
if tweet.TimeParsed.IsZero() {
|
|
|
|
|
t.Error("Expected tweet TimeParsed is not zero")
|
|
|
|
|
}
|
|
|
|
|
if tweet.Timestamp == 0 {
|
|
|
|
|
t.Error("Expected tweet Timestamp is greater than zero")
|
|
|
|
|
}
|
2020-12-11 20:58:49 +02:00
|
|
|
for _, video := range tweet.Videos {
|
|
|
|
|
if video.ID == "" {
|
|
|
|
|
t.Error("Expected tweet video ID is not empty")
|
|
|
|
|
}
|
|
|
|
|
if video.Preview == "" {
|
|
|
|
|
t.Error("Expected tweet video Preview is not empty")
|
|
|
|
|
}
|
|
|
|
|
if video.URL == "" {
|
|
|
|
|
t.Error("Expected tweet video URL is not empty")
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-09-21 12:18:34 +03:00
|
|
|
}
|
|
|
|
|
}
|
2020-06-15 16:16:08 +03:00
|
|
|
if count != maxTweetsNbr {
|
|
|
|
|
t.Errorf("Expected tweets count=%v, got: %v", maxTweetsNbr, count)
|
2019-09-21 12:18:34 +03:00
|
|
|
}
|
|
|
|
|
}
|