internal/prompt: TestConfirm: don't use un-keyed structs
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
ecde8c38a5
commit
b74b7b3c40
@ -109,29 +109,53 @@ func TestConfirm(t *testing.T) {
|
|||||||
f func() error
|
f func() error
|
||||||
expected promptResult
|
expected promptResult
|
||||||
}{
|
}{
|
||||||
{"SIGINT", func() error {
|
{
|
||||||
_ = syscall.Kill(syscall.Getpid(), syscall.SIGINT)
|
desc: "SIGINT",
|
||||||
return nil
|
f: func() error {
|
||||||
}, promptResult{false, prompt.ErrTerminated}},
|
_ = syscall.Kill(syscall.Getpid(), syscall.SIGINT)
|
||||||
{"no", func() error {
|
return nil
|
||||||
_, err := fmt.Fprintln(promptWriter, "n")
|
},
|
||||||
return err
|
expected: promptResult{false, prompt.ErrTerminated},
|
||||||
}, promptResult{false, nil}},
|
},
|
||||||
{"yes", func() error {
|
{
|
||||||
_, err := fmt.Fprintln(promptWriter, "y")
|
desc: "no",
|
||||||
return err
|
f: func() error {
|
||||||
}, promptResult{true, nil}},
|
_, err := fmt.Fprintln(promptWriter, "n")
|
||||||
{"any", func() error {
|
return err
|
||||||
_, err := fmt.Fprintln(promptWriter, "a")
|
},
|
||||||
return err
|
expected: promptResult{false, nil},
|
||||||
}, promptResult{false, nil}},
|
},
|
||||||
{"with space", func() error {
|
{
|
||||||
_, err := fmt.Fprintln(promptWriter, " y")
|
desc: "yes",
|
||||||
return err
|
f: func() error {
|
||||||
}, promptResult{true, nil}},
|
_, err := fmt.Fprintln(promptWriter, "y")
|
||||||
{"reader closed", func() error {
|
return err
|
||||||
return promptReader.Close()
|
},
|
||||||
}, promptResult{false, nil}},
|
expected: promptResult{true, nil},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "any",
|
||||||
|
f: func() error {
|
||||||
|
_, err := fmt.Fprintln(promptWriter, "a")
|
||||||
|
return err
|
||||||
|
},
|
||||||
|
expected: promptResult{false, nil},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "with space",
|
||||||
|
f: func() error {
|
||||||
|
_, err := fmt.Fprintln(promptWriter, " y")
|
||||||
|
return err
|
||||||
|
},
|
||||||
|
expected: promptResult{true, nil},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "reader closed",
|
||||||
|
f: func() error {
|
||||||
|
return promptReader.Close()
|
||||||
|
},
|
||||||
|
expected: promptResult{false, nil},
|
||||||
|
},
|
||||||
} {
|
} {
|
||||||
t.Run(tc.desc, func(t *testing.T) {
|
t.Run(tc.desc, func(t *testing.T) {
|
||||||
notifyCtx, notifyCancel := signal.NotifyContext(ctx, syscall.SIGINT, syscall.SIGTERM)
|
notifyCtx, notifyCancel := signal.NotifyContext(ctx, syscall.SIGINT, syscall.SIGTERM)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user