added test for GetHomeTweets
This commit is contained in:
parent
2eb31665a5
commit
cf1575a1a3
1 changed files with 60 additions and 1 deletions
|
|
@ -306,7 +306,7 @@ func TestTweetThread(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHomeTweets(t *testing.T) {
|
func TestFetchHomeTweets(t *testing.T) {
|
||||||
if skipAuthTest {
|
if skipAuthTest {
|
||||||
t.Skip("Skipping test due to environment variable")
|
t.Skip("Skipping test due to environment variable")
|
||||||
}
|
}
|
||||||
|
|
@ -319,3 +319,62 @@ func TestHomeTweets(t *testing.T) {
|
||||||
t.Fatal("returned 0 tweets")
|
t.Fatal("returned 0 tweets")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetHomeTweets(t *testing.T) {
|
||||||
|
if skipAuthTest {
|
||||||
|
t.Skip("Skipping test due to environment variable")
|
||||||
|
}
|
||||||
|
count := 0
|
||||||
|
maxTweetsNbr := 150
|
||||||
|
dupcheck := make(map[string]bool)
|
||||||
|
|
||||||
|
for tweet := range testScraper.GetHomeTweets(context.Background(), 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