-
Notifications
You must be signed in to change notification settings - Fork 26
/
role_test.go
71 lines (64 loc) · 1.77 KB
/
role_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
package civogo
import (
"testing"
)
func TestListRoles(t *testing.T) {
client, server, _ := NewClientForTesting(map[string]string{
"/v2/roles": `[{"id":"12345","name":"admin","permissions":"*.*","built_in":true}]`,
})
defer server.Close()
got, err := client.ListRoles()
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)
}
if got[0].Permissions != "*.*" {
t.Errorf("Expected %s, got %s", "*.*", got[0].Permissions)
}
if got[0].BuiltIn != true {
t.Errorf("Expected %t, got %t", true, got[0].BuiltIn)
}
}
func TestCreateRole(t *testing.T) {
client, server, _ := NewClientForTesting(map[string]string{
"/v2/roles": `{"id":"12345","name":"Org Admin","permissions":"organisation.*","built_in":false}`,
})
defer server.Close()
got, err := client.CreateRole("Org Admin", "organisation.*")
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 != "Org Admin" {
t.Errorf("Expected %s, got %s", "admin", got.Name)
}
if got.Permissions != "organisation.*" {
t.Errorf("Expected %s, got %s", "*.*", got.Permissions)
}
if got.BuiltIn != false {
t.Errorf("Expected %t, got %t", false, got.BuiltIn)
}
}
func TestDeleteRole(t *testing.T) {
client, server, _ := NewClientForTesting(map[string]string{
"/v2/roles/12345": `{"result":"success"}`,
})
defer server.Close()
got, err := client.DeleteRole("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)
}
}