forked from silphid/survey
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsurvey_test.go
44 lines (34 loc) · 929 Bytes
/
survey_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package survey
import (
"fmt"
"testing"
"github.com/AlecAivazis/survey/core"
)
func init() {
// disable color output for all prompts to simplify testing
core.DisableColor = true
}
func TestValidationError(t *testing.T) {
err := fmt.Errorf("Football is not a valid month")
actual, err := core.RunTemplate(
core.ErrorTemplate,
err,
)
if err != nil {
t.Errorf("Failed to run template to format error: %s", err)
}
expected := `✘ Sorry, your reply was invalid: Football is not a valid month
`
if actual != expected {
t.Errorf("Formatted error was not formatted correctly. Found:\n%s\nExpected:\n%s", actual, expected)
}
}
func TestAsk_returnsErrorIfTargetIsNil(t *testing.T) {
// pass an empty place to leave the answers
err := Ask([]*Question{}, nil)
// if we didn't get an error
if err == nil {
// the test failed
t.Error("Did not encounter error when asking with no where to record.")
}
}