Go 42 lines
package projecttype
import (
"bytes"
"strings"
"testing"
)
func TestStdinPrompter(t *testing.T) {
cat := mustCatalog(t)
cands := []Category{WebApp, Fullstack}
cases := []struct {
name string
input string
wantChoice Category
wantDescribe bool
wantFree string
}{
{"pick-second", "2\n", Fullstack, false, ""},
{"pick-first", "1\n", WebApp, false, ""},
{"generic", "g\n", Generic, false, ""},
{"describe", "d\na rest api\n", "", true, "a rest api"},
{"eof", "", Generic, false, ""},
{"retry-then-valid", "x\n9\n2\n", Fullstack, false, ""},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
var out bytes.Buffer
p := NewStdinPrompter(strings.NewReader(tc.input), &out)
choice, describe, free, err := p.Pick(cands, cat)
if err != nil {
t.Fatalf("Pick: %v", err)
}
if choice != tc.wantChoice || describe != tc.wantDescribe || free != tc.wantFree {
t.Fatalf("Pick = (%q, %v, %q), want (%q, %v, %q)",
choice, describe, free, tc.wantChoice, tc.wantDescribe, tc.wantFree)
}
})
}
}