MCPcopy
hub / github.com/go-playground/validator / TestAbilityToValidateNils

Function TestAbilityToValidateNils

validator_test.go:13306–13328  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

13304}
13305
13306func TestAbilityToValidateNils(t *testing.T) {
13307 type TestStruct struct {
13308 Test *string `validate:"nil"`
13309 }
13310
13311 ts := TestStruct{}
13312 val := New()
13313 fn := func(fl FieldLevel) bool {
13314 return fl.Field().Kind() == reflect.Ptr && fl.Field().IsNil()
13315 }
13316
13317 err := val.RegisterValidation("nil", fn, true)
13318 Equal(t, err, nil)
13319
13320 errs := val.Struct(ts)
13321 Equal(t, errs, nil)
13322
13323 str := "string"
13324 ts.Test = &str
13325
13326 errs = val.Struct(ts)
13327 NotEqual(t, errs, nil)
13328}
13329
13330func TestRequiredWithoutPointers(t *testing.T) {
13331 type Lookup struct {

Callers

nothing calls this directly

Calls 5

NewFunction · 0.85
RegisterValidationMethod · 0.80
StructMethod · 0.80
KindMethod · 0.65
FieldMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…