upgrade validator version to v9 (#1015)
* upgrade validator version to v9 * Update vendor.json * Update go.mod * Update go.sum * fix * fix * fix bug * Update binding_test.go * Update validate_test.go * Update go.sum * Update go.mod * Update go.sum * Update go.mod * Update go.sum
This commit is contained in:
@ -658,9 +658,9 @@ func TestValidationDisabled(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestExistsSucceeds(t *testing.T) {
|
||||
func TestRequiredSucceeds(t *testing.T) {
|
||||
type HogeStruct struct {
|
||||
Hoge *int `json:"hoge" binding:"exists"`
|
||||
Hoge *int `json:"hoge" binding:"required"`
|
||||
}
|
||||
|
||||
var obj HogeStruct
|
||||
@ -669,9 +669,9 @@ func TestExistsSucceeds(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestExistsFails(t *testing.T) {
|
||||
func TestRequiredFails(t *testing.T) {
|
||||
type HogeStruct struct {
|
||||
Hoge *int `json:"foo" binding:"exists"`
|
||||
Hoge *int `json:"foo" binding:"required"`
|
||||
}
|
||||
|
||||
var obj HogeStruct
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
"reflect"
|
||||
"sync"
|
||||
|
||||
"gopkg.in/go-playground/validator.v8"
|
||||
"gopkg.in/go-playground/validator.v9"
|
||||
)
|
||||
|
||||
type defaultValidator struct {
|
||||
@ -45,7 +45,7 @@ func (v *defaultValidator) Engine() interface{} {
|
||||
|
||||
func (v *defaultValidator) lazyinit() {
|
||||
v.once.Do(func() {
|
||||
config := &validator.Config{TagName: "binding"}
|
||||
v.validate = validator.New(config)
|
||||
v.validate = validator.New()
|
||||
v.validate.SetTagName("binding")
|
||||
})
|
||||
}
|
||||
|
@ -6,12 +6,11 @@ package binding
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"gopkg.in/go-playground/validator.v8"
|
||||
"gopkg.in/go-playground/validator.v9"
|
||||
)
|
||||
|
||||
type testInterface interface {
|
||||
@ -200,15 +199,8 @@ type structCustomValidation struct {
|
||||
Integer int `binding:"notone"`
|
||||
}
|
||||
|
||||
// notOne is a custom validator meant to be used with `validator.v8` library.
|
||||
// The method signature for `v9` is significantly different and this function
|
||||
// would need to be changed for tests to pass after upgrade.
|
||||
// See https://github.com/gin-gonic/gin/pull/1015.
|
||||
func notOne(
|
||||
v *validator.Validate, topStruct reflect.Value, currentStructOrField reflect.Value,
|
||||
field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string,
|
||||
) bool {
|
||||
if val, ok := field.Interface().(int); ok {
|
||||
func notOne(f1 validator.FieldLevel) bool {
|
||||
if val, ok := f1.Field().Interface().(int); ok {
|
||||
return val != 1
|
||||
}
|
||||
return false
|
||||
|
Reference in New Issue
Block a user