Add profile test
This commit is contained in:
parent
409af81a81
commit
f97e728210
1 changed files with 52 additions and 0 deletions
52
profile_test.go
Normal file
52
profile_test.go
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
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/1174251196758003713/IjXgRpzL_400x400.jpg",
|
||||
Biography: "Designer of interfaces & abstractions.",
|
||||
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 length is greater than zero")
|
||||
}
|
||||
if profile.FollowingCount == 0 {
|
||||
t.Error("Expected FollowingCount length is greater than zero")
|
||||
}
|
||||
if profile.LikesCount == 0 {
|
||||
t.Error("Expected LikesCount length is greater than zero")
|
||||
}
|
||||
if profile.TweetsCount == 0 {
|
||||
t.Error("Expected TweetsCount length is greater than zero")
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue