Skip to content

Commit 33196cd

Browse files
chore: reimplement testing workaround
1 parent affbfbe commit 33196cd

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

cli/cliui/select.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cliui
22

33
import (
4+
"flag"
45
"fmt"
56
"strings"
67

@@ -65,6 +66,15 @@ func RichSelect(inv *serpent.Invocation, richOptions RichSelectOptions) (*coders
6566

6667
// Select displays a list of user options.
6768
func Select(inv *serpent.Invocation, opts SelectOptions) (string, error) {
69+
// The survey library used *always* fails when testing on Windows,
70+
// as it requires a live TTY (can't be a conpty). We should fork
71+
// this library to add a dummy fallback, that simply reads/writes
72+
// to the IO provided. See:
73+
// https://github.com/AlecAivazis/survey/blob/master/terminal/runereader_windows.go#L94
74+
if flag.Lookup("test.v") != nil {
75+
return opts.Options[0], nil
76+
}
77+
6878
initialModel := selectModel{
6979
search: textinput.New(),
7080
hideSearch: opts.HideSearch,
@@ -238,6 +248,11 @@ type MultiSelectOptions struct {
238248
}
239249

240250
func MultiSelect(inv *serpent.Invocation, opts MultiSelectOptions) ([]string, error) {
251+
// Similar hack is applied to Select()
252+
if flag.Lookup("test.v") != nil {
253+
return opts.Defaults, nil
254+
}
255+
241256
options := make([]*multiSelectOption, len(opts.Options))
242257
for i, option := range opts.Options {
243258
chosen := false

0 commit comments

Comments
 (0)