github.com/GeniusesGroup/libgo@v0.0.0-20220929090155-5ff932cb408e/user/user-type_test.go (about) 1 /* For license and copyright information please see LEGAL file in repository */ 2 3 package user 4 5 import ( 6 "testing" 7 8 "../protocol" 9 ) 10 11 func Test_CheckUserType(t *testing.T) { 12 type args struct { 13 baseUsers protocol.UserType 14 user protocol.UserType 15 } 16 tests := []struct { 17 name string 18 args args 19 WantBool bool 20 }{ 21 { 22 name: "test1", 23 args: args{ 24 baseUsers: protocol.UserType_All, 25 user: protocol.UserType_App, 26 }, 27 WantBool: true, 28 }, { 29 name: "test2", 30 args: args{ 31 baseUsers: protocol.UserType_Person, 32 user: protocol.UserType_Person, 33 }, 34 WantBool: true, 35 }, { 36 name: "test3", 37 args: args{ 38 baseUsers: protocol.UserType_Person, 39 user: protocol.UserType_App, 40 }, 41 WantBool: false, 42 }, { 43 name: "test4", 44 args: args{ 45 baseUsers: protocol.UserType_Unset, 46 user: protocol.UserType_Person, 47 }, 48 WantBool: false, 49 }, { 50 name: "test5", 51 args: args{ 52 baseUsers: protocol.UserType_All ^ protocol.UserType_Guest, 53 user: protocol.UserType_Guest, 54 }, 55 WantBool: false, 56 }, { 57 name: "test6", 58 args: args{ 59 baseUsers: ^protocol.UserType_Guest, 60 user: protocol.UserType_Guest, 61 }, 62 WantBool: false, 63 }, { 64 name: "test7", 65 args: args{ 66 baseUsers: protocol.UserType_Person | protocol.UserType_Thing, 67 user: protocol.UserType_Person, 68 }, 69 WantBool: true, 70 }, 71 // TODO::: 72 // { 73 // name: "test8", 74 // args: args{ 75 // baseUsers: ^protocol.UserType_Guest, 76 // user: protocol.UserType_Unset, 77 // }, 78 // WantBool: false, 79 // }, 80 } 81 for _, tt := range tests { 82 t.Run(tt.name, func(t *testing.T) { 83 var exist = CheckUserType(tt.args.baseUsers, tt.args.user) 84 if exist != tt.WantBool { 85 t.Errorf("CheckUserType() Base = %b, Checked by = %b", tt.args.baseUsers, tt.args.user) 86 t.Errorf("CheckUserType() on %v return %v, want %v", tt.name, exist, tt.WantBool) 87 } 88 }) 89 } 90 }