forked from Fuyu/validate
36 lines
711 B
Go
36 lines
711 B
Go
package validate
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
type testCase struct {
|
|
A string `validate:"required"`
|
|
B int `validate:"gt=9"`
|
|
C float64 `validate:"eq=10"`
|
|
D uint64 `validate:"required,lt=9"`
|
|
}
|
|
|
|
var case1 = testCase{`abc`, 10, 10.0, 5}
|
|
var case2 = testCase{`abc`, 8, 10.0, 0}
|
|
|
|
func BenchmarkValidateCorrect(b *testing.B) {
|
|
var errs []ValidationError
|
|
for i := 0; i < b.N; i++ {
|
|
errs = Validate(case1)
|
|
if len(errs) != 0 {
|
|
b.Fatal(`This case should pass but got`, errs)
|
|
}
|
|
}
|
|
}
|
|
|
|
func BenchmarkValidateIncorrect(b *testing.B) {
|
|
var errs []ValidationError
|
|
for i := 0; i < b.N; i++ {
|
|
errs = Validate(case2)
|
|
if len(errs) != 2 {
|
|
b.Fatal(`This case should get 2 errors but got`, len(errs))
|
|
}
|
|
}
|
|
}
|