-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser_test.go
56 lines (46 loc) · 1.07 KB
/
user_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
52
53
54
55
56
package suzuri
import (
"context"
"net/http"
"strconv"
"testing"
)
func TestGetUser(t *testing.T) {
setup()
defer teardown()
userID := 7
endpoint := "/users/" + strconv.Itoa(userID)
stub.HandleFunc(endpoint, func(w http.ResponseWriter, r *http.Request) {
expected := "GET"
actual := r.Method
if actual != expected {
t.Errorf("expected %v, got %v", expected, actual)
}
http.ServeFile(w, r, "testdata/users-7.json")
})
user, err := client.GetUser(ctx, userID)
if err != nil {
t.Fatalf("failed to get user: %v", err)
}
expected := userID
actual := user.ID
if actual != expected {
t.Errorf("expected %v, got %v", expected, actual)
}
expected = 2
actual = len(user.Identities)
if actual != expected {
t.Errorf("expected %v, got %v", expected, actual)
}
expected = 10
actual = user.Profile.ID
if actual != expected {
t.Errorf("expected %v, got %v", expected, actual)
}
cancelCtx, cancel := context.WithCancel(ctx)
cancel()
user, err = client.GetUser(cancelCtx, userID)
if err == nil {
t.Errorf("should return error, got %v", err)
}
}