AnswerWith runs any validators associated with the question. If they all pass, it sends the answer down the channel. If any fail, the validation error is returned from here, and the answer is NOT sent. This mimics the behaviour of real survey, which will keep asking you in a loop until the validator
(answer any)
| 326 | // assert.EqualError(t, err, nil) |
| 327 | // test sequence should proceed now |
| 328 | func (q *QuestionWrapper) AnswerWith(answer any) error { |
| 329 | // run validators, otherwise we won't be able to test them |
| 330 | if q.Options != nil && len(q.Options.Validators) > 0 { |
| 331 | for _, validator := range q.Options.Validators { |
| 332 | validationErr := validator(answer) |
| 333 | if validationErr != nil { |
| 334 | return validationErr |
| 335 | } |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | q.Asker.sendAnswer(answer, nil) |
| 340 | return nil |
| 341 | } |
| 342 | |
| 343 | func (q *QuestionWrapper) AnswerWithError(err error) { |
| 344 | q.Asker.sendAnswer(nil, err) |