-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathgroups_test.go
152 lines (114 loc) · 2.79 KB
/
groups_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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package redmine
import (
"testing"
)
var (
testGroupName = "test-group"
testGroupName2 = "test-group2"
)
func TestGroupsCRUD(t *testing.T) {
var r Context
// Init Redmine context
initTest(&r, t)
// Preparing auxiliary data
uCreated := testUserCreate(t, r)
defer testUserDetele(t, r, uCreated.ID)
// Create and delete
gCreated := testGroupCreate(t, r)
defer testGroupDetele(t, r, gCreated.ID)
// Get all
testGroupAllGet(t, r)
// Update
testGroupUpdate(t, r, gCreated.ID, uCreated.ID)
// Get single (check user is member of specified group)
testGroupSingleGet(t, r, gCreated.ID, uCreated.ID)
// Delete user
testGroupDeteleUser(t, r, gCreated.ID, uCreated.ID)
// Add user
testGroupAddUser(t, r, gCreated.ID, uCreated.ID)
}
func testGroupCreate(t *testing.T, r Context) GroupObject {
g, _, err := r.GroupCreate(
GroupCreate{
Group: GroupCreateObject{
Name: testGroupName,
},
},
)
if err != nil {
t.Fatal("Group create error:", err)
}
t.Logf("Group create: success")
return g
}
func testGroupUpdate(t *testing.T, r Context, id, userID int64) {
_, err := r.GroupUpdate(
id,
GroupUpdate{
Group: GroupUpdateObject{
Name: &testGroupName2,
UserIDs: &[]int64{userID},
},
},
)
if err != nil {
t.Fatal("Group update error:", err)
}
t.Logf("Group update: success")
}
func testGroupAddUser(t *testing.T, r Context, id, userID int64) {
_, err := r.GroupAddUser(id, GroupAddUserObject{UserID: userID})
if err != nil {
t.Fatal("Group add user error:", err)
}
t.Logf("Group add user: success")
}
func testGroupDeteleUser(t *testing.T, r Context, id, userID int64) {
_, err := r.GroupDeleteUser(id, userID)
if err != nil {
t.Fatal("Group delete user error:", err)
}
t.Logf("Group delete user: success")
}
func testGroupDetele(t *testing.T, r Context, id int64) {
_, err := r.GroupDelete(id)
if err != nil {
t.Fatal("Group delete error:", err)
}
t.Logf("Group delete: success")
}
func testGroupAllGet(t *testing.T, r Context) {
g, _, err := r.GroupAllGet()
if err != nil {
t.Fatal("Groups get error:", err)
}
for _, e := range g.Groups {
if e.Name == testGroupName {
t.Logf("Groups get: success")
return
}
}
t.Fatal("Groups get error: can't find created group")
}
func testGroupSingleGet(t *testing.T, r Context, id, userID int64) {
g, _, err := r.GroupSingleGet(id, GroupSingleGetRequest{
Includes: []GroupInclude{
GroupIncludeMemberships,
GroupIncludeUsers,
},
})
if err != nil {
t.Fatal("Group get error:", err)
}
if g.Users == nil {
t.Fatal("Group get error: users not found")
}
// Check user is a member of specified group (error if not)
for _, e := range *g.Users {
if e.ID == userID {
t.Logf("Group get: success")
return
}
}
t.Fatal("Group get error: can't find user in specified group")
}