44 "database/sql"
55 "database/sql/driver"
66 "encoding/json"
7- "errors"
87 "fmt"
98 "reflect"
109 "testing"
@@ -130,7 +129,8 @@ type valuer struct {
130129func (v valuer ) Value () (driver.Value , error ) {
131130
132131 if v .Name == "errorme" {
133- return nil , errors .New ("some kind of error" )
132+ panic ("SQL Driver Valuer error: some kind of error" )
133+ // return nil, errors.New("some kind of error")
134134 }
135135
136136 if len (v .Name ) == 0 {
@@ -248,7 +248,7 @@ func TestSQLValue2Validation(t *testing.T) {
248248
249249 val .Name = "errorme"
250250
251- PanicMatches (t , func () { errs = validate .Field (val , "required" ) }, "SQL Driver Valuer error: some kind of error" )
251+ PanicMatches (t , func () { validate .Field (val , "required" ) }, "SQL Driver Valuer error: some kind of error" )
252252
253253 type myValuer valuer
254254
@@ -3187,7 +3187,9 @@ func TestHsla(t *testing.T) {
31873187 AssertError (t , errs , "" , "" , "hsla" )
31883188
31893189 i := 1
3190- PanicMatches (t , func () { validate .Field (i , "hsla" ) }, "interface conversion: interface is int, not string" )
3190+ validate .Field (i , "hsla" )
3191+ NotEqual (t , errs , nil )
3192+ AssertError (t , errs , "" , "" , "hsla" )
31913193}
31923194
31933195func TestHsl (t * testing.T ) {
@@ -3221,7 +3223,9 @@ func TestHsl(t *testing.T) {
32213223 AssertError (t , errs , "" , "" , "hsl" )
32223224
32233225 i := 1
3224- PanicMatches (t , func () { validate .Field (i , "hsl" ) }, "interface conversion: interface is int, not string" )
3226+ errs = validate .Field (i , "hsl" )
3227+ NotEqual (t , errs , nil )
3228+ AssertError (t , errs , "" , "" , "hsl" )
32253229}
32263230
32273231func TestRgba (t * testing.T ) {
@@ -3263,7 +3267,9 @@ func TestRgba(t *testing.T) {
32633267 AssertError (t , errs , "" , "" , "rgba" )
32643268
32653269 i := 1
3266- PanicMatches (t , func () { validate .Field (i , "rgba" ) }, "interface conversion: interface is int, not string" )
3270+ errs = validate .Field (i , "rgba" )
3271+ NotEqual (t , errs , nil )
3272+ AssertError (t , errs , "" , "" , "rgba" )
32673273}
32683274
32693275func TestRgb (t * testing.T ) {
@@ -3301,7 +3307,9 @@ func TestRgb(t *testing.T) {
33013307 AssertError (t , errs , "" , "" , "rgb" )
33023308
33033309 i := 1
3304- PanicMatches (t , func () { validate .Field (i , "rgb" ) }, "interface conversion: interface is int, not string" )
3310+ errs = validate .Field (i , "rgb" )
3311+ NotEqual (t , errs , nil )
3312+ AssertError (t , errs , "" , "" , "rgb" )
33053313}
33063314
33073315func TestEmail (t * testing.T ) {
@@ -3331,7 +3339,9 @@ func TestEmail(t *testing.T) {
33313339 AssertError (t , errs , "" , "" , "email" )
33323340
33333341 i := true
3334- PanicMatches (t , func () { validate .Field (i , "email" ) }, "interface conversion: interface is bool, not string" )
3342+ errs = validate .Field (i , "email" )
3343+ NotEqual (t , errs , nil )
3344+ AssertError (t , errs , "" , "" , "email" )
33353345}
33363346
33373347func TestHexColor (t * testing.T ) {
@@ -3355,7 +3365,9 @@ func TestHexColor(t *testing.T) {
33553365 AssertError (t , errs , "" , "" , "hexcolor" )
33563366
33573367 i := true
3358- PanicMatches (t , func () { validate .Field (i , "hexcolor" ) }, "interface conversion: interface is bool, not string" )
3368+ errs = validate .Field (i , "hexcolor" )
3369+ NotEqual (t , errs , nil )
3370+ AssertError (t , errs , "" , "" , "hexcolor" )
33593371}
33603372
33613373func TestHexadecimal (t * testing.T ) {
@@ -3370,7 +3382,9 @@ func TestHexadecimal(t *testing.T) {
33703382 AssertError (t , errs , "" , "" , "hexadecimal" )
33713383
33723384 i := true
3373- PanicMatches (t , func () { validate .Field (i , "hexadecimal" ) }, "interface conversion: interface is bool, not string" )
3385+ errs = validate .Field (i , "hexadecimal" )
3386+ NotEqual (t , errs , nil )
3387+ AssertError (t , errs , "" , "" , "hexadecimal" )
33743388}
33753389
33763390func TestNumber (t * testing.T ) {
@@ -3415,7 +3429,9 @@ func TestNumber(t *testing.T) {
34153429 AssertError (t , errs , "" , "" , "number" )
34163430
34173431 i := 1
3418- PanicMatches (t , func () { validate .Field (i , "number" ) }, "interface conversion: interface is int, not string" )
3432+ errs = validate .Field (i , "number" )
3433+ NotEqual (t , errs , nil )
3434+ AssertError (t , errs , "" , "" , "number" )
34193435}
34203436
34213437func TestNumeric (t * testing.T ) {
@@ -3455,7 +3471,9 @@ func TestNumeric(t *testing.T) {
34553471 AssertError (t , errs , "" , "" , "numeric" )
34563472
34573473 i := 1
3458- PanicMatches (t , func () { validate .Field (i , "numeric" ) }, "interface conversion: interface is int, not string" )
3474+ errs = validate .Field (i , "numeric" )
3475+ NotEqual (t , errs , nil )
3476+ AssertError (t , errs , "" , "" , "numeric" )
34593477}
34603478
34613479func TestAlphaNumeric (t * testing.T ) {
@@ -3469,7 +3487,9 @@ func TestAlphaNumeric(t *testing.T) {
34693487 NotEqual (t , errs , nil )
34703488 AssertError (t , errs , "" , "" , "alphanum" )
34713489
3472- PanicMatches (t , func () { validate .Field (1 , "alphanum" ) }, "interface conversion: interface is int, not string" )
3490+ errs = validate .Field (1 , "alphanum" )
3491+ NotEqual (t , errs , nil )
3492+ AssertError (t , errs , "" , "" , "alphanum" )
34733493}
34743494
34753495func TestAlpha (t * testing.T ) {
@@ -3481,10 +3501,11 @@ func TestAlpha(t *testing.T) {
34813501 s = "abc1"
34823502 errs = validate .Field (s , "alpha" )
34833503 NotEqual (t , errs , nil )
3484-
34853504 AssertError (t , errs , "" , "" , "alpha" )
34863505
3487- PanicMatches (t , func () { validate .Field (1 , "alpha" ) }, "interface conversion: interface is int, not string" )
3506+ errs = validate .Field (1 , "alpha" )
3507+ NotEqual (t , errs , nil )
3508+ AssertError (t , errs , "" , "" , "alpha" )
34883509}
34893510
34903511func TestStructStringValidation (t * testing.T ) {
@@ -3737,22 +3758,6 @@ func TestInvalidStruct(t *testing.T) {
37373758 PanicMatches (t , func () { validate .Struct (s .Test ) }, "value passed for validation is not a struct" )
37383759}
37393760
3740- func TestInvalidField (t * testing.T ) {
3741- s := & SubTest {
3742- Test : "1" ,
3743- }
3744-
3745- PanicMatches (t , func () { validate .Field (s , "required" ) }, "Invalid field passed to traverseField" )
3746- }
3747-
3748- func TestInvalidTagField (t * testing.T ) {
3749- s := & SubTest {
3750- Test : "1" ,
3751- }
3752-
3753- PanicMatches (t , func () { validate .Field (s .Test , "" ) }, fmt .Sprintf ("Invalid validation tag on field %s" , "" ))
3754- }
3755-
37563761func TestInvalidValidatorFunction (t * testing.T ) {
37573762 s := & SubTest {
37583763 Test : "1" ,
0 commit comments