add medias test
This commit is contained in:
parent
4907a49780
commit
b8d84b5534
1 changed files with 60 additions and 0 deletions
60
medias_test.go
Normal file
60
medias_test.go
Normal file
|
|
@ -0,0 +1,60 @@
|
||||||
|
package twitterscraper_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestGetMedias(t *testing.T) {
|
||||||
|
count := 0
|
||||||
|
maxTweetsNbr := 20
|
||||||
|
dupcheck := make(map[string]bool)
|
||||||
|
for tweet := range testScraper.GetMediaTweets(context.Background(), "XSpaces", maxTweetsNbr) {
|
||||||
|
if tweet.Error != nil {
|
||||||
|
t.Error(tweet.Error)
|
||||||
|
} else {
|
||||||
|
count++
|
||||||
|
if tweet.ID == "" {
|
||||||
|
t.Error("Expected tweet ID is empty")
|
||||||
|
} 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 empty")
|
||||||
|
}
|
||||||
|
if tweet.Username == "" {
|
||||||
|
t.Error("Expected tweet Username is empty")
|
||||||
|
}
|
||||||
|
if tweet.PermanentURL == "" {
|
||||||
|
t.Error("Expected tweet PermanentURL is empty")
|
||||||
|
}
|
||||||
|
if tweet.Text == "" {
|
||||||
|
t.Error("Expected tweet Text is empty")
|
||||||
|
}
|
||||||
|
if tweet.TimeParsed.IsZero() {
|
||||||
|
t.Error("Expected tweet TimeParsed is zero")
|
||||||
|
}
|
||||||
|
if tweet.Timestamp == 0 {
|
||||||
|
t.Error("Expected tweet Timestamp is greater than zero")
|
||||||
|
}
|
||||||
|
for _, video := range tweet.Videos {
|
||||||
|
if video.ID == "" {
|
||||||
|
t.Error("Expected tweet video ID is empty")
|
||||||
|
}
|
||||||
|
if video.Preview == "" {
|
||||||
|
t.Error("Expected tweet video Preview is empty")
|
||||||
|
}
|
||||||
|
if video.URL == "" {
|
||||||
|
t.Error("Expected tweet video URL is empty")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if count != maxTweetsNbr {
|
||||||
|
t.Errorf("Expected tweets count=%v, got: %v", maxTweetsNbr, count)
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue