add check for maxTweetsNbr and rename GetSearchTweets fun to Search Tweets

This commit is contained in:
xisco 2020-05-15 17:52:06 +02:00
parent 9c16b10725
commit 9497edf199
2 changed files with 7 additions and 6 deletions

View file

@ -9,8 +9,8 @@ import (
const ajaxSearchURL = "https://twitter.com/i/search/timeline?q=%s"
// GetTweets returns channel with tweets for a given search query
func GetSearchTweets(query string, maxTweetsNbr int) <-chan *Result {
// SearchTweets returns channel with tweets for a given search query
func SearchTweets(query string, maxTweetsNbr int) <-chan *Result {
channel := make(chan *Result)
go func(query string) {
defer close(channel)
@ -40,7 +40,7 @@ func GetSearchTweets(query string, maxTweetsNbr int) <-chan *Result {
return channel
}
// FetchTweets gets tweets for a given search query, via the Twitter frontend API
// FetchSearchTweets gets tweets for a given search query, via the Twitter frontend API
func FetchSearchTweets(query, maxId string) ([]*Tweet, error) {
if maxId != "" {
query = query + " max_id:" + maxId

View file

@ -4,7 +4,8 @@ import "testing"
func TestGetSearchTweets(t *testing.T) {
count := 0
for tweet := range GetSearchTweets("twitter scraper data -filter:retweets", 50) {
maxTweetsNbr := 50
for tweet := range SearchTweets("twitter scraper data -filter:retweets", maxTweetsNbr) {
if tweet.Error != nil {
t.Error(tweet.Error)
} else {
@ -30,7 +31,7 @@ func TestGetSearchTweets(t *testing.T) {
}
}
if count == 0 {
t.Error("Expected tweets count is greater than zero")
if count != maxTweetsNbr {
t.Errorf("Expected tweets count=%v, got: %v", maxTweetsNbr, count)
}
}