forked from AlecAivazis/survey
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinfo_test.go
72 lines (63 loc) · 1.35 KB
/
info_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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package survey
import (
"fmt"
"strings"
"testing"
"github.com/Iilun/survey/v2/core"
"github.com/stretchr/testify/assert"
)
func init() {
// disable color output for all prompts to simplify testing
core.DisableColor = true
}
func TestInfoRender(t *testing.T) {
tests := []struct {
title string
prompt Info
data InfoTemplateData
expected string
}{
{
"Test Info Formatting",
Info{Message: "The weather is nice today"},
InfoTemplateData{},
fmt.Sprintf("%s The weather is nice today\n", defaultIcons().Info.Text),
},
}
for _, test := range tests {
test.data.Info = test.prompt
// set the icon set
test.data.Config = defaultPromptConfig()
actual, _, err := core.RunTemplate(
InfoTemplate,
&test.data,
)
assert.Nil(t, err, test.title)
assert.Equal(t, test.expected, actual, test.title)
}
}
func TestInfoPrompt(t *testing.T) {
tests := []PromptTest{
{
"SKIP: Test Info prompt interaction",
&Info{
Message: "A valuable information",
},
nil,
func(c expectConsole) {
c.ExpectString("A valuable information")
c.ExpectEOF()
},
nil,
},
}
for _, test := range tests {
testName := strings.TrimPrefix(test.name, "SKIP: ")
t.Run(test.name, func(t *testing.T) {
if testName != test.name {
t.Skipf("warning: flakey test %q", testName)
}
RunPromptTest(t, test)
})
}
}