MCPcopy
hub / github.com/gin-gonic/gin / TestValidatorEngine

Function TestValidatorEngine

binding/validate_test.go:234–253  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

232}
233
234func TestValidatorEngine(t *testing.T) {
235 // This validates that the function `notOne` matches
236 // the expected function signature by `defaultValidator`
237 // and by extension the validator library.
238 engine, ok := Validator.Engine().(*validator.Validate)
239 assert.True(t, ok)
240
241 err := engine.RegisterValidation("notone", notOne)
242 // Check that we can register custom validation without error
243 require.NoError(t, err)
244
245 // Create an instance which will fail validation
246 withOne := structCustomValidation{Integer: 1}
247 errs := validate(withOne)
248
249 // Check that we got back non-nil errs
250 require.Error(t, errs)
251 // Check that the error matches expectation
252 require.Error(t, errs, "notone")
253}

Callers

nothing calls this directly

Calls 3

validateFunction · 0.70
EngineMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected