twitter-scrapper/profile_test.go
Alexander Sheiko a35f307a7e Update profile
2020-02-11 13:13:58 +02:00

52 lines
1.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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{
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.",
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 {
t.Error("Expected FollowersCount is greater than zero")
}
if profile.FollowingCount == 0 {
t.Error("Expected FollowingCount is greater than zero")
}
if profile.LikesCount == 0 {
t.Error("Expected LikesCount is greater than zero")
}
if profile.TweetsCount == 0 {
t.Error("Expected TweetsCount is greater than zero")
}
}