-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathusers_test.go
More file actions
95 lines (78 loc) · 1.98 KB
/
users_test.go
File metadata and controls
95 lines (78 loc) · 1.98 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
package users
import (
"fmt"
"net/http"
"net/http/httptest"
"net/url"
"reflect"
"testing"
"github.com/deis/deis/client-go/controller/api"
"github.com/deis/deis/client-go/controller/client"
"github.com/deis/deis/version"
)
const usersFixture string = `
{
"count": 1,
"next": null,
"previous": null,
"results": [
{
"id": 1,
"last_login": "2014-10-19T22:01:00.601Z",
"is_superuser": true,
"username": "test",
"first_name": "test",
"last_name": "testerson",
"email": "test@example.com",
"is_staff": true,
"is_active": true,
"date_joined": "2014-10-19T22:01:00.601Z",
"groups": [],
"user_permissions": []
}
]
}`
type fakeHTTPServer struct{}
func (fakeHTTPServer) ServeHTTP(res http.ResponseWriter, req *http.Request) {
res.Header().Add("DEIS_API_VERSION", version.APIVersion)
if req.URL.Path == "/v1/users/" && req.Method == "GET" {
res.Write([]byte(usersFixture))
return
}
fmt.Printf("Unrecongized URL %s\n", req.URL)
res.WriteHeader(http.StatusNotFound)
res.Write(nil)
}
func TestUsersList(t *testing.T) {
t.Parallel()
expected := []api.User{
api.User{
ID: 1,
LastLogin: "2014-10-19T22:01:00.601Z",
IsSuperuser: true,
Username: "test",
FirstName: "test",
LastName: "testerson",
Email: "test@example.com",
IsStaff: true,
IsActive: true,
DateJoined: "2014-10-19T22:01:00.601Z",
},
}
handler := fakeHTTPServer{}
server := httptest.NewServer(handler)
defer server.Close()
u, err := url.Parse(server.URL)
if err != nil {
t.Fatal(err)
}
httpClient := client.CreateHTTPClient(false)
client := client.Client{HTTPClient: httpClient, ControllerURL: *u, Token: "abc"}
actual, _, err := List(&client, 100)
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(expected, actual) {
t.Errorf("Expected %v, Got %v", expected, actual)
}
}