forked from grafana/amixr-api-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_test.go
83 lines (68 loc) · 1.6 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package aapi
import (
"fmt"
"net/http"
"reflect"
"testing"
)
var testUser = &User{
ID: "U4DNY931HHJS5",
Email: "[email protected]",
Role: "admin",
Username: "Alex",
}
var testUserBody = `{
"id": "U4DNY931HHJS5",
"email": "[email protected]",
"slack": [
{
"user_id": "UALEXSLACKDJPK",
"team_id": "TALEXSLACKDJPK"
}
],
"username": "Alex",
"role": "admin"
}`
func TestListUsers(t *testing.T) {
mux, server, client := setup(t)
defer teardown(server)
mux.HandleFunc("/api/v1/users/", func(w http.ResponseWriter, r *http.Request) {
testRequestMethod(t, r, "GET")
fmt.Fprint(w, fmt.Sprintf(`{"count": 1, "next": null, "previous": null, "results": [%s]}`, testUserBody))
})
options := &ListUserOptions{}
users, _, err := client.Users.ListUsers(options)
if err != nil {
t.Fatal(err)
}
want := &PaginatedUsersResponse{
PaginatedResponse: PaginatedResponse{
Count: 1,
Next: nil,
Previous: nil,
},
Users: []*User{
testUser,
},
}
if !reflect.DeepEqual(want, users) {
t.Errorf("returned\n %+v, \nwant\n %+v", users, want)
}
}
func TestGetUser(t *testing.T) {
mux, server, client := setup(t)
defer teardown(server)
mux.HandleFunc("/api/v1/users/U4DNY931HHJS5/", func(w http.ResponseWriter, r *http.Request) {
testRequestMethod(t, r, "GET")
fmt.Fprint(w, testUserBody)
})
options := &GetUserOptions{}
user, _, err := client.Users.GetUser("U4DNY931HHJS5", options)
if err != nil {
t.Fatal(err)
}
want := testUser
if !reflect.DeepEqual(want, user) {
t.Errorf("returned\n %+v\n want\n %+v\n", user, want)
}
}