Merge pull request #413 from suekto-andreas/v9

Fix #352 Returns error when passing pointer to RegisterStructValidation
pull/418/head
Dean Karn 6 years ago committed by GitHub
commit 1730262625
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      validator_instance.go
  2. 13
      validator_test.go

@ -207,6 +207,11 @@ func (v *Validate) RegisterStructValidationCtx(fn StructLevelFuncCtx, types ...i
}
for _, t := range types {
tv := reflect.ValueOf(t)
if tv.Kind() == reflect.Ptr {
t = reflect.Indirect(tv).Interface()
}
v.structLevelFuncs[reflect.TypeOf(t)] = fn
}
}

@ -8149,3 +8149,16 @@ func TestKeyOrs(t *testing.T) {
AssertDeepError(t, errs, "Test2.Test1[badtestkey]", "Test2.Test1[badtestkey]", "Test1[badtestkey]", "Test1[badtestkey]", "okkey", "eq=testkey|eq=testkeyok")
AssertDeepError(t, errs, "Test2.Test1[badtestkey]", "Test2.Test1[badtestkey]", "Test1[badtestkey]", "Test1[badtestkey]", "eq", "eq")
}
func TestStructLevelValidationsPointerPassing(t *testing.T) {
v1 := New()
v1.RegisterStructValidation(StructValidationTestStruct, &TestStruct{})
tst := &TestStruct{
String: "good value",
}
errs := v1.Struct(tst)
NotEqual(t, errs, nil)
AssertError(t, errs, "TestStruct.StringVal", "TestStruct.String", "StringVal", "String", "badvalueteststruct")
}

Loading…
Cancel
Save