| 232 | } |
| 233 | |
| 234 | func 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 | } |