forked from mikespook/gorbac
-
Notifications
You must be signed in to change notification settings - Fork 0
/
role_test.go
31 lines (28 loc) · 704 Bytes
/
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
package gorbac
import (
"testing"
)
func TestStdrA(t *testing.T) {
rA := NewRole("role-a")
if rA.ID != "role-a" {
t.Fatalf("[a] expected, but %s got", rA.ID)
}
if err := rA.Assign(NewPermission("permission-a")); err != nil {
t.Fatal(err)
}
if !rA.Permit(NewPermission("permission-a")) {
t.Fatal("[permission-a] should permit to rA")
}
if len(rA.Permissions()) != 1 {
t.Fatal("[a] should have one permission")
}
if err := rA.Revoke(NewPermission("permission-a")); err != nil {
t.Fatal(err)
}
if rA.Permit(NewPermission("permission-a")) {
t.Fatal("[permission-a] should not permit to rA")
}
if len(rA.Permissions()) != 0 {
t.Fatal("[a] should not have any permission")
}
}