1 | package domain_test |
||
2 | |||
3 | import ( |
||
4 | "testing" |
||
5 | |||
6 | "github.com/memnix/memnix-rest/domain" |
||
7 | ) |
||
8 | |||
9 | func TestPermission_IsValid(t *testing.T) { |
||
10 | tests := []struct { |
||
11 | permission domain.Permission |
||
12 | expected bool |
||
13 | }{ |
||
14 | {permission: domain.PermissionNone, expected: true}, |
||
15 | {permission: domain.PermissionUser, expected: true}, |
||
16 | {permission: domain.PermissionVip, expected: true}, |
||
17 | {permission: domain.PermissionAdmin, expected: true}, |
||
18 | {permission: -1, expected: false}, |
||
19 | {permission: 4, expected: false}, |
||
20 | } |
||
21 | |||
22 | for _, test := range tests { |
||
23 | result := test.permission.IsValid() |
||
24 | if result != test.expected { |
||
25 | t.Errorf("Expected IsValid() to return %v for permission %d, but got %v", test.expected, test.permission, result) |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
26 | } |
||
27 | } |
||
28 | } |
||
29 | |||
30 | func TestPermission_String(t *testing.T) { |
||
31 | tests := []struct { |
||
32 | expected string |
||
33 | permission domain.Permission |
||
34 | }{ |
||
35 | {permission: domain.PermissionNone, expected: "none"}, |
||
36 | {permission: domain.PermissionUser, expected: "user"}, |
||
37 | {permission: domain.PermissionVip, expected: "vip"}, |
||
38 | {permission: domain.PermissionAdmin, expected: "admin"}, |
||
39 | } |
||
40 | |||
41 | for _, test := range tests { |
||
42 | result := test.permission.String() |
||
43 | if result != test.expected { |
||
44 | t.Errorf("Expected String() to return %s for permission %d, but got %s", test.expected, test.permission, result) |
||
0 ignored issues
–
show
|
|||
45 | } |
||
46 | } |
||
47 | } |
||
48 |