| 203 | } |
| 204 | |
| 205 | func TestValidateAndModifyStruct(t *testing.T) { |
| 206 | // This validates that pointers to structs are passed to the validator |
| 207 | // giving us the ability to modify the struct being validated. |
| 208 | engine, ok := Validator.Engine().(*validator.Validate) |
| 209 | assert.True(t, ok) |
| 210 | |
| 211 | engine.RegisterStructValidation(toZero, structModifyValidation{}) |
| 212 | |
| 213 | s := structModifyValidation{Integer: 1} |
| 214 | errs := validate(&s) |
| 215 | |
| 216 | require.NoError(t, errs) |
| 217 | assert.Equal(t, structModifyValidation{Integer: 0}, s) |
| 218 | } |
| 219 | |
| 220 | // structCustomValidation is a helper struct we use to check that |
| 221 | // custom validation can be registered on it. |