mycommon/myvalidator/validator_test.go

53 lines
560 B
Go
Raw Permalink Normal View History

2023-01-15 00:21:08 +08:00
package myvalidator
import (
"fmt"
"testing"
)
func TestValidate(t *testing.T) {
type St struct {
Id int `validate:"gte=0,lte=500"`
Name string `validate:"required"`
}
values := []*St{
{
Id: 5,
Name: "name5",
},
{
Id: 100,
Name: "",
},
{
Id: 600,
Name: "name600",
},
{
Id: -1,
Name: "",
},
}
Init()
for _, v := range values {
err := Verify(v)
if err != nil {
fmt.Println(err)
}
err = VerifyTrans(v)
if err != nil {
fmt.Println(err)
}
fmt.Printf("%+v\n\n", v)
}
}