-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmethods_test.go
51 lines (48 loc) · 1.27 KB
/
methods_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"fmt"
"log"
"net/http"
"net/http/httptest"
"testing"
)
func TestGetProfileName(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request){
w.Header().Set("Content-Type","application/json")
fmt.Fprintln(w,`{"id":"1","name":"Test User"}`)
}))
defer ts.Close()
data, err := getProfileName(&http.Client{}, ts.URL)
if err != nil {
t.Error(err)
}
if data != "Test User" {
t.Error("Wrong user name")
}
}
func TestGetProfileFriendlist(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request){
w.Header().Set("Content-Type","application/json")
fmt.Fprintln(w,`{"data":[{"name":"A","id":"1"},{"name":"B","id":"2"}],"summary":{"total_count":2}}`)
}))
defer ts.Close()
friends := getProfileFriendlist(&http.Client{}, ts.URL)
var profilesAll []FacebookProfile
profiles, err := friends()
log.Println(profiles)
log.Println(err)
appendProfiles := func(profiles []FacebookProfile) {
for _, profile := range profiles {
profilesAll = append(profilesAll, profile)
}
}
appendProfiles(profiles)
for err == nil {
profiles, err = friends()
appendProfiles(profiles)
}
log.Println(len(profilesAll))
if len(profilesAll) != 2 {
t.Error("Wrong profiles count")
}
}