mirror of
https://github.com/astaxie/beego.git
synced 2025-07-10 02:30:18 +00:00
fix label == `` #4001
This commit is contained in:
@ -15,6 +15,7 @@
|
||||
package validation
|
||||
|
||||
import (
|
||||
"log"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
@ -80,6 +81,28 @@ func TestGetValidFuncs(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
type User struct {
|
||||
Name string `valid:"Required;MaxSize(5)" `
|
||||
Sex string `valid:"Required;" label:"sex_label"`
|
||||
Age int `valid:"Required;Range(1, 140);" label:"age_label"`
|
||||
}
|
||||
|
||||
func TestValidation(t *testing.T) {
|
||||
u := User{"man1238888456", "", 1140}
|
||||
valid := Validation{}
|
||||
b, err := valid.Valid(&u)
|
||||
if err != nil {
|
||||
// handle error
|
||||
}
|
||||
if !b {
|
||||
// validation does not pass
|
||||
// blabla...
|
||||
for _, err := range valid.Errors {
|
||||
log.Println(err.Key, err.Message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCall(t *testing.T) {
|
||||
u := user{Name: "test", Age: 180}
|
||||
tf := reflect.TypeOf(u)
|
||||
|
Reference in New Issue
Block a user