2020-05-14 14:59:33 +02:00
|
|
|
package twitterscraper
|
|
|
|
|
|
2020-06-12 21:31:08 +08:00
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"testing"
|
|
|
|
|
)
|
2020-05-14 14:59:33 +02:00
|
|
|
|
|
|
|
|
func TestGetSearchTweets(t *testing.T) {
|
|
|
|
|
count := 0
|
2020-05-15 17:52:06 +02:00
|
|
|
maxTweetsNbr := 50
|
2020-06-12 21:31:08 +08:00
|
|
|
for tweet := range SearchTweets(context.Background(), "twitter scraper data -filter:retweets", maxTweetsNbr) {
|
2020-05-14 14:59:33 +02:00
|
|
|
if tweet.Error != nil {
|
|
|
|
|
t.Error(tweet.Error)
|
|
|
|
|
} else {
|
|
|
|
|
count++
|
|
|
|
|
if tweet.HTML == "" {
|
|
|
|
|
t.Error("Expected tweet HTML is not empty")
|
|
|
|
|
}
|
|
|
|
|
if tweet.ID == "" {
|
|
|
|
|
t.Error("Expected tweet ID is not empty")
|
|
|
|
|
}
|
|
|
|
|
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-05-15 17:52:06 +02:00
|
|
|
if count != maxTweetsNbr {
|
|
|
|
|
t.Errorf("Expected tweets count=%v, got: %v", maxTweetsNbr, count)
|
2020-05-14 14:59:33 +02:00
|
|
|
}
|
|
|
|
|
}
|