-
Notifications
You must be signed in to change notification settings - Fork 3
/
group_test.go
97 lines (82 loc) · 2.12 KB
/
group_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
package p4
import (
"fmt"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestGroup_Groups(t *testing.T) {
var (
message string
group = "group-xxx"
subGroups = []string{"eyotang2"}
users = []string{"eyotang", "tangyongqiang"}
other = []string{"abc"}
owners = []string{"owner"}
)
conn, err := setup(t)
Convey("test Group functions", t, func() {
So(err, ShouldBeNil)
Convey("List groups", func() {
var (
groups []string
)
groups, err = conn.Groups()
So(err, ShouldBeNil)
So(len(groups), ShouldBeGreaterThanOrEqualTo, 0)
})
Convey("Create group", func() {
message, err = conn.CreateGroup(group, owners, subGroups, users)
So(err, ShouldBeNil)
So(message, ShouldEqual, fmt.Sprintf("Group %s created.", group))
})
Convey("Add user to group", func() {
message, err = conn.AddGroupUsers(group, owners, other)
So(err, ShouldBeNil)
So(message, ShouldEqual, fmt.Sprintf("Group %s updated.", group))
})
Convey("Remove user from group", func() {
message, err = conn.RemoveGroupUsers(group, owners, other)
So(err, ShouldBeNil)
So(message, ShouldEqual, fmt.Sprintf("Group %s updated.", group))
})
Convey("Delete group", func() {
message, err = conn.DeleteGroup(group)
So(err, ShouldBeNil)
So(message, ShouldEqual, fmt.Sprintf("Group %s deleted.", group))
})
})
}
func TestGroup_GroupsRead(t *testing.T) {
var (
user = "lejiajun"
owner = "feihonghui"
)
conn, err := setup(t)
Convey("test Group functions", t, func() {
So(err, ShouldBeNil)
Convey("Display group", func() {
var (
group *GroupInfo
)
group, err = conn.GroupInfo("swarm-group")
So(err, ShouldBeNil)
So(len(group.Users), ShouldBeGreaterThanOrEqualTo, 0)
})
Convey("List my groups", func() {
var (
groups []string
)
groups, err = conn.GroupsBelong(user)
So(err, ShouldBeNil)
So(len(groups), ShouldBeGreaterThanOrEqualTo, 0)
})
Convey("List owned groups", func() {
var (
groups []string
)
groups, err = conn.GroupsOwned(owner)
So(err, ShouldBeNil)
So(len(groups), ShouldBeGreaterThanOrEqualTo, 0)
})
})
}