-
Notifications
You must be signed in to change notification settings - Fork 3
/
user_test.go
95 lines (81 loc) · 2.21 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
84
85
86
87
88
89
90
91
92
93
94
95
package p4
import (
"fmt"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestUser_Users(t *testing.T) {
conn, err := setup(t)
Convey("test Users functions", t, func() {
So(err, ShouldBeNil)
Convey("List users", func() {
users, err := conn.Users()
So(err, ShouldBeNil)
So(len(users), ShouldBeGreaterThanOrEqualTo, 0)
})
Convey("Get user info", func() {
user, err := conn.User("readonly")
So(err, ShouldBeNil)
So(user.User, ShouldEqual, "readonly")
So(user.AuthMethod, ShouldEqual, "perforce")
})
})
}
func TestUser_ListUsers(t *testing.T) {
conn, err := setup(t)
Convey("test Users functions", t, func() {
So(err, ShouldBeNil)
Convey("List users without any group", func() {
users, err := conn.Users()
So(err, ShouldBeNil)
So(len(users), ShouldBeGreaterThanOrEqualTo, 0)
var unrefUsers []string
for _, u := range users {
groups, err := conn.GroupsBelong(u.User)
So(err, ShouldBeNil)
if len(groups) <= 0 {
user, err := conn.User(u.User)
So(err, ShouldBeNil)
if user.AuthMethod == "ldap" {
unrefUsers = append(unrefUsers, u.User)
}
}
}
So(len(unrefUsers), ShouldBeGreaterThanOrEqualTo, 0)
})
})
}
func TestUser_DeleteUser(t *testing.T) {
conn, err := setup(t)
Convey("test User delete functions", t, func() {
So(err, ShouldBeNil)
Convey("Delete users without any group", func() {
user := "localauth"
message, err := conn.DeleteUser(user)
So(err, ShouldBeNil)
So(message, ShouldEqual, fmt.Sprintf("Deletion of user %s and all the user's clients initiated.\nUser %s deleted.", user, user))
})
})
}
func TestUser_CreateUser(t *testing.T) {
conn, err := setup(t)
Convey("test User create functions", t, func() {
So(err, ShouldBeNil)
user := "test99"
Convey("Delete user without any group", func() {
_, err := conn.DeleteUser(user)
So(err, ShouldBeNil)
})
Convey("Create user without any group", func() {
userInfo := &UserInfo{
User: user,
Email: "[email protected]",
FullName: "测试用户99",
AuthMethod: "ldap",
}
message, err := conn.CreateUser(userInfo)
So(err, ShouldBeNil)
So(message, ShouldEqual, fmt.Sprintf("User %s saved.", user))
})
})
}