e2e: add "spawnWithExpectLines"

Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
release-3.4
Gyuho Lee 2018-03-01 14:30:34 -08:00
parent 85533a6305
commit b62e8291c2
1 changed files with 9 additions and 4 deletions

View File

@ -42,9 +42,14 @@ func spawnWithExpect(args []string, expected string) error {
} }
func spawnWithExpects(args []string, xs ...string) error { func spawnWithExpects(args []string, xs ...string) error {
_, err := spawnWithExpectLines(args, xs...)
return err
}
func spawnWithExpectLines(args []string, xs ...string) ([]string, error) {
proc, err := spawnCmd(args) proc, err := spawnCmd(args)
if err != nil { if err != nil {
return err return nil, err
} }
// process until either stdout or stderr contains // process until either stdout or stderr contains
// the expected string // the expected string
@ -57,7 +62,7 @@ func spawnWithExpects(args []string, xs ...string) error {
l, lerr := proc.ExpectFunc(lineFunc) l, lerr := proc.ExpectFunc(lineFunc)
if lerr != nil { if lerr != nil {
proc.Close() proc.Close()
return fmt.Errorf("%v (expected %q, got %q)", lerr, txt, lines) return nil, fmt.Errorf("%v (expected %q, got %q)", lerr, txt, lines)
} }
lines = append(lines, l) lines = append(lines, l)
if strings.Contains(l, txt) { if strings.Contains(l, txt) {
@ -67,9 +72,9 @@ func spawnWithExpects(args []string, xs ...string) error {
} }
perr := proc.Close() perr := proc.Close()
if len(xs) == 0 && proc.LineCount() != noOutputLineCount { // expect no output if len(xs) == 0 && proc.LineCount() != noOutputLineCount { // expect no output
return fmt.Errorf("unexpected output (got lines %q, line count %d)", lines, proc.LineCount()) return nil, fmt.Errorf("unexpected output (got lines %q, line count %d)", lines, proc.LineCount())
} }
return perr return lines, perr
} }
func closeWithTimeout(p *expect.ExpectProcess, d time.Duration) error { func closeWithTimeout(p *expect.ExpectProcess, d time.Duration) error {