Skip to content

Commit aa74eb4

Browse files
committed
internal/prompt: TestConfirm: don't use un-keyed structs
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 862db30 commit aa74eb4

File tree

1 file changed

+47
-23
lines changed

1 file changed

+47
-23
lines changed

internal/prompt/prompt_test.go

Lines changed: 47 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -109,29 +109,53 @@ func TestConfirm(t *testing.T) {
109109
f func() error
110110
expected promptResult
111111
}{
112-
{"SIGINT", func() error {
113-
_ = syscall.Kill(syscall.Getpid(), syscall.SIGINT)
114-
return nil
115-
}, promptResult{false, prompt.ErrTerminated}},
116-
{"no", func() error {
117-
_, err := fmt.Fprintln(promptWriter, "n")
118-
return err
119-
}, promptResult{false, nil}},
120-
{"yes", func() error {
121-
_, err := fmt.Fprintln(promptWriter, "y")
122-
return err
123-
}, promptResult{true, nil}},
124-
{"any", func() error {
125-
_, err := fmt.Fprintln(promptWriter, "a")
126-
return err
127-
}, promptResult{false, nil}},
128-
{"with space", func() error {
129-
_, err := fmt.Fprintln(promptWriter, " y")
130-
return err
131-
}, promptResult{true, nil}},
132-
{"reader closed", func() error {
133-
return promptReader.Close()
134-
}, promptResult{false, nil}},
112+
{
113+
desc: "SIGINT",
114+
f: func() error {
115+
_ = syscall.Kill(syscall.Getpid(), syscall.SIGINT)
116+
return nil
117+
},
118+
expected: promptResult{false, prompt.ErrTerminated},
119+
},
120+
{
121+
desc: "no",
122+
f: func() error {
123+
_, err := fmt.Fprintln(promptWriter, "n")
124+
return err
125+
},
126+
expected: promptResult{false, nil},
127+
},
128+
{
129+
desc: "yes",
130+
f: func() error {
131+
_, err := fmt.Fprintln(promptWriter, "y")
132+
return err
133+
},
134+
expected: promptResult{true, nil},
135+
},
136+
{
137+
desc: "any",
138+
f: func() error {
139+
_, err := fmt.Fprintln(promptWriter, "a")
140+
return err
141+
},
142+
expected: promptResult{false, nil},
143+
},
144+
{
145+
desc: "with space",
146+
f: func() error {
147+
_, err := fmt.Fprintln(promptWriter, " y")
148+
return err
149+
},
150+
expected: promptResult{true, nil},
151+
},
152+
{
153+
desc: "reader closed",
154+
f: func() error {
155+
return promptReader.Close()
156+
},
157+
expected: promptResult{false, nil},
158+
},
135159
} {
136160
t.Run(tc.desc, func(t *testing.T) {
137161
notifyCtx, notifyCancel := signal.NotifyContext(ctx, syscall.SIGINT, syscall.SIGTERM)

0 commit comments

Comments
 (0)