twitter-scrapper/profile_test.go

53 lines
1.5 KiB
Go
Raw Normal View History

2019-09-21 11:56:06 +03:00
package twitterscraper
import (
"testing"
"time"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
)
func TestGetProfile(t *testing.T) {
joined := time.Unix(1245860880, 0)
sample := Profile{
2020-02-11 13:13:58 +02:00
Avatar: "https://pbs.twimg.com/profile_images/1176439369596624896/Fkqe6qVj_400x400.jpg",
Biography: "Kenneth Reitz, n: a gardenvariety selfreferential loop. Not available for purchase. Made in USA.",
2019-09-21 11:56:06 +03:00
Birthday: "1988",
Joined: &joined,
Location: "Eden, Earth, Milky Way",
Name: "☿ Kenneth Reitz",
URL: "https://twitter.com/kennethreitz",
Username: "kennethreitz",
Website: "https://kennethreitz.org/values",
}
profile, err := GetProfile("kennethreitz")
if err != nil {
t.Error(err)
}
var cmpOptions = cmp.Options{
cmpopts.IgnoreFields(Profile{}, "FollowersCount"),
cmpopts.IgnoreFields(Profile{}, "FollowingCount"),
cmpopts.IgnoreFields(Profile{}, "LikesCount"),
cmpopts.IgnoreFields(Profile{}, "TweetsCount"),
}
if diff := cmp.Diff(sample, profile, cmpOptions...); diff != "" {
t.Error("Resulting profile does not match the sample", diff)
}
if profile.FollowersCount == 0 {
2019-09-21 12:06:42 +03:00
t.Error("Expected FollowersCount is greater than zero")
2019-09-21 11:56:06 +03:00
}
if profile.FollowingCount == 0 {
2019-09-21 12:06:42 +03:00
t.Error("Expected FollowingCount is greater than zero")
2019-09-21 11:56:06 +03:00
}
if profile.LikesCount == 0 {
2019-09-21 12:06:42 +03:00
t.Error("Expected LikesCount is greater than zero")
2019-09-21 11:56:06 +03:00
}
if profile.TweetsCount == 0 {
2019-09-21 12:06:42 +03:00
t.Error("Expected TweetsCount is greater than zero")
2019-09-21 11:56:06 +03:00
}
}