File tree 3 files changed +28
-2
lines changed
3 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ type User struct {
22
22
}
23
23
24
24
func (u * User ) RoleNames () []string {
25
- roles := []string {}
25
+ var roles []string
26
26
for _ , r := range u .Roles {
27
27
roles = append (roles , r .Name )
28
28
}
Original file line number Diff line number Diff line change
1
+ package entities
2
+
3
+ import (
4
+ "testing"
5
+
6
+ "github.com/stretchr/testify/assert"
7
+ )
8
+
9
+ func TestUserRoleNames (t * testing.T ) {
10
+ u := & User {}
11
+
12
+ roles := u .RoleNames ()
13
+ assert .Empty (t , roles )
14
+
15
+ u .Roles = []Role {
16
+ {Name : "admin" },
17
+ {Name : "engineering" },
18
+ }
19
+
20
+ roles = u .RoleNames ()
21
+ assert .NotEmpty (t , roles )
22
+ assert .Len (t , roles , 2 )
23
+ assert .Equal (t , roles [0 ], "admin" )
24
+ assert .Equal (t , roles [1 ], "engineering" )
25
+
26
+ }
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ role_permissions := {
6
6
" engineering" : [{" method" : " GET" , " path" : " /api/campaigns" },
7
7
{" method" : " GET" , " path" : " /api/campaigns/:id" }],
8
8
" webdev" : [{" method" : " GET" , " path" : " /api/campaigns" },
9
- {" method" : " PUT" , " path" : " /api/campaigns/:id" }],
9
+ {" method" : " PUT" , " path" : " /api/campaigns/:id" }]
10
10
}
11
11
12
12
default allow = false
You can’t perform that action at this time.
0 commit comments