-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathusers_test.go
39 lines (33 loc) · 962 Bytes
/
users_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
package devtogo
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/require"
)
func TestLookupUser(t *testing.T) {
var res UserProfile
b := unmarshalGoldenFileBytes(t, "user.json", &res)
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
require.Equal(t, "/users/167919", r.URL.Path)
w.WriteHeader(http.StatusOK)
w.Write(b)
}))
client := NewClient(withBaseURL(ts.URL))
up, err := client.LookupUser("167919")
require.NoError(t, err)
require.Equal(t, &res, up)
}
func TestLookupMe(t *testing.T) {
var res UserProfile
b := unmarshalGoldenFileBytes(t, "user.json", &res)
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
require.Equal(t, "/users/me", r.URL.Path)
w.WriteHeader(http.StatusOK)
w.Write(b)
}))
client := NewClient(withBaseURL(ts.URL))
up, err := client.Me()
require.NoError(t, err)
require.Equal(t, &res, up)
}