github.com/johnnyeven/libtools@v0.0.0-20191126065708-61829c1adf46/validate/validatetpl/unity_social_credit_code_test.go (about) 1 package validatetpl 2 3 import ( 4 "testing" 5 ) 6 7 func TestValidateUnitySocialCreditCode(t *testing.T) { 8 type args struct { 9 v interface{} 10 } 11 tests := []struct { 12 name string 13 args args 14 want bool 15 want1 string 16 }{ 17 { 18 name: "normal", 19 args: args{ 20 v: "12345678901234567a", 21 }, 22 want: true, 23 want1: "", 24 }, 25 { 26 name: "ExceedLength", 27 args: args{ 28 v: "1234567890123456789", 29 }, 30 want: false, 31 want1: InvalidUnitySocialCreditCodeValue, 32 }, 33 { 34 name: "shortLength", 35 args: args{ 36 v: "12345678901234567", 37 }, 38 want: false, 39 want1: InvalidUnitySocialCreditCodeValue, 40 }, 41 { 42 name: "invalidCharacter", 43 args: args{ 44 v: "12345678901234567@", 45 }, 46 want: false, 47 want1: InvalidUnitySocialCreditCodeValue, 48 }, 49 { 50 name: "invalidType", 51 args: args{ 52 v: 123456789012345678, 53 }, 54 want: false, 55 want1: InvalidUnitySocialCreditCodeType, 56 }, 57 { 58 name: "empty", 59 args: args{ 60 v: "", 61 }, 62 want: false, 63 want1: InvalidUnitySocialCreditCodeValue, 64 }, 65 } 66 for _, tt := range tests { 67 got, got1 := ValidateUnitySocialCreditCode(tt.args.v) 68 if got != tt.want { 69 t.Errorf("%q. ValidateUnitySocialCreditCode() got = %v, want %v", tt.name, got, tt.want) 70 } 71 if got1 != tt.want1 { 72 t.Errorf("%q. ValidateUnitySocialCreditCode() got1 = %v, want %v", tt.name, got1, tt.want1) 73 } 74 } 75 }