-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathusers_test.go
More file actions
54 lines (47 loc) · 1.19 KB
/
users_test.go
File metadata and controls
54 lines (47 loc) · 1.19 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
package api
import (
"sort"
"testing"
)
func TestUserString(t *testing.T) {
user := User{
ID: 1,
Username: "bacongobbler",
Email: "matthewf@deis.com",
FirstName: "Matthew",
LastName: "Fisher",
LastLogin: "Yesterday",
IsSuperuser: true,
IsStaff: true,
IsActive: true,
DateJoined: "Yesterday",
}
expected := `ID: 1
Username: bacongobbler
Email: matthewf@deis.com
First Name: Matthew
Last Name: Fisher
Last Login: Yesterday
Is Superuser: true
Is Staff: true
Is Active: true
Date Joined: Yesterday`
if user.String() != expected {
t.Errorf("Got:\n\n%s\n\nExpected:\n\n%s", user.String(), expected)
}
}
func TestUsersSorted(t *testing.T) {
users := Users{
{1, "", false, "Zulu", "", "", "", false, false, ""},
{2, "", false, "Beta", "", "", "", false, false, ""},
{3, "", false, "Gamma", "", "", "", false, false, ""},
{4, "", false, "Alpha", "", "", "", false, false, ""},
}
sort.Sort(users)
expectedUsernames := []string{"Alpha", "Beta", "Gamma", "Zulu"}
for i, user := range users {
if expectedUsernames[i] != user.Username {
t.Errorf("Expected users to be sorted %v, Got %v at index %v", expectedUsernames[i], user.Username, i)
}
}
}