forked from gravitational/teleport
-
Notifications
You must be signed in to change notification settings - Fork 0
/
roles_test.go
47 lines (42 loc) · 1.47 KB
/
roles_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
package teleport
import "testing"
func TestRolesCheck(t *testing.T) {
tests := []struct {
roles Roles
wantErr bool
}{
{roles: []Role{}, wantErr: false},
{roles: []Role{RoleAuth}, wantErr: false},
{roles: []Role{RoleAuth, RoleWeb, RoleNode, RoleProxy, RoleAdmin, RoleProvisionToken, RoleTrustedCluster, LegacyClusterTokenType, RoleSignup, RoleNop}, wantErr: false},
{roles: []Role{RoleAuth, RoleNode, RoleAuth}, wantErr: true},
{roles: []Role{Role("unknown")}, wantErr: true},
}
for _, tt := range tests {
err := tt.roles.Check()
if (err != nil) != tt.wantErr {
t.Errorf("%v.Check(): got error %q, want error %v", tt.roles, err, tt.wantErr)
}
}
}
func TestRolesEqual(t *testing.T) {
tests := []struct {
a, b Roles
want bool
}{
{a: nil, b: nil, want: true},
{a: []Role{}, b: []Role{}, want: true},
{a: nil, b: []Role{}, want: true},
{a: []Role{RoleAuth}, b: []Role{RoleAuth}, want: true},
{a: []Role{RoleAuth}, b: []Role{RoleAuth, RoleAuth}, want: true},
{a: []Role{RoleAuth, RoleNode}, b: []Role{RoleNode, RoleAuth}, want: true},
{a: []Role{RoleAuth}, b: nil, want: false},
{a: []Role{RoleAuth}, b: []Role{RoleNode}, want: false},
{a: []Role{RoleAuth, RoleAuth}, b: []Role{RoleAuth, RoleNode}, want: false},
{a: []Role{RoleAuth, RoleNode}, b: []Role{RoleAuth, RoleAuth}, want: false},
}
for _, tt := range tests {
if got := tt.a.Equals(tt.b); got != tt.want {
t.Errorf("%v.Equals(%v): got %v, want %v", tt.a, tt.b, got, tt.want)
}
}
}