-
Notifications
You must be signed in to change notification settings - Fork 24
/
team_test.go
148 lines (131 loc) · 3.59 KB
/
team_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
package civogo
import (
"testing"
)
func TestListTeams(t *testing.T) {
client, server, _ := NewClientForTesting(map[string]string{
"/v2/teams": `[{"id":"12345","name":"admin"}]`,
})
defer server.Close()
got, err := client.ListTeams()
if err != nil {
t.Errorf("Request returned an error: %s", err)
return
}
if got[0].ID != "12345" {
t.Errorf("Expected %s, got %s", "12345", got[0].ID)
}
if got[0].Name != "admin" {
t.Errorf("Expected %s, got %s", "admin", got[0].Name)
}
}
func TestCreateTeam(t *testing.T) {
client, server, _ := NewClientForTesting(map[string]string{
"/v2/teams": `{"name":"Org Admin"}`,
})
defer server.Close()
got, err := client.CreateTeam("Org Admin")
if err != nil {
t.Errorf("Request returned an error: %s", err)
return
}
if got.Name != "Org Admin" {
t.Errorf("Expected %s, got %s", "admin", got.Name)
}
}
func TestRenameTeam(t *testing.T) {
client, server, _ := NewClientForTesting(map[string]string{
"/v2/teams/12345": `{"id":"12345","name":"New Admin"}`,
})
defer server.Close()
got, err := client.RenameTeam("12345", "New Admin")
if err != nil {
t.Errorf("Request returned an error: %s", err)
return
}
if got.ID != "12345" {
t.Errorf("Expected %s, got %s", "12345", got.ID)
}
if got.Name != "New Admin" {
t.Errorf("Expected %s, got %s", "admin", got.Name)
}
}
func TestDeleteTeam(t *testing.T) {
client, server, _ := NewClientForTesting(map[string]string{
"/v2/teams/12345": `{"result":"success"}`,
})
defer server.Close()
got, err := client.DeleteTeam("12345")
if err != nil {
t.Errorf("Request returned an error: %s", err)
return
}
if got.Result != "success" {
t.Errorf("Expected %s, got %s", "success", got.Result)
}
}
func TestListTeamMembers(t *testing.T) {
client, server, _ := NewClientForTesting(map[string]string{
"/v2/teams/12345/members": `[{"id":"abcde","user_id":"bcdef"}]`,
})
defer server.Close()
got, err := client.ListTeamMembers("12345")
if err != nil {
t.Errorf("Request returned an error: %s", err)
return
}
if got[0].ID != "abcde" {
t.Errorf("Expected %s, got %s", "12345", got[0].ID)
}
if got[0].UserID != "bcdef" {
t.Errorf("Expected %s, got %s", "bcdef", got[0].UserID)
}
}
func TestAddTeamMember(t *testing.T) {
client, server, _ := NewClientForTesting(map[string]string{
"/v2/teams/12345/members": `[{"id":"abcde","user_id":"bcdef"}]`,
})
defer server.Close()
got, err := client.AddTeamMember("12345", "abcde", "*.*", "")
if err != nil {
t.Errorf("Request returned an error: %s", err)
return
}
if got[0].ID != "abcde" {
t.Errorf("Expected %s, got %s", "12345", got[0].ID)
}
if got[0].UserID != "bcdef" {
t.Errorf("Expected %s, got %s", "bcdef", got[0].UserID)
}
}
func TestUpdateTeamMember(t *testing.T) {
client, server, _ := NewClientForTesting(map[string]string{
"/v2/teams/12345/members/abcde": `{"id":"12345","permissions":"*.*"}`,
})
defer server.Close()
got, err := client.UpdateTeamMember("12345", "abcde", "*.*", "")
if err != nil {
t.Errorf("Request returned an error: %s", err)
return
}
if got.ID != "12345" {
t.Errorf("Expected %s, got %s", "12345", got.ID)
}
if got.Permissions != "*.*" {
t.Errorf("Expected %s, got %s", "*.*", got.Permissions)
}
}
func TestRemoveTeamMember(t *testing.T) {
client, server, _ := NewClientForTesting(map[string]string{
"/v2/teams/12345/members/abcde": `{"result":"success"}`,
})
defer server.Close()
got, err := client.RemoveTeamMember("12345", "abcde")
if err != nil {
t.Errorf("Request returned an error: %s", err)
return
}
if got.Result != "success" {
t.Errorf("Expected %s, got %s", "success", got.Result)
}
}