Skip to content

Commit

Permalink
e2e: add "spawnWithExpectLines"
Browse files Browse the repository at this point in the history
Signed-off-by: Gyuho Lee <[email protected]>
  • Loading branch information
gyuho committed Mar 2, 2018
1 parent 85533a6 commit b62e829
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions e2e/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,14 @@ func spawnWithExpect(args []string, expected 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)
if err != nil {
return err
return nil, err
}
// process until either stdout or stderr contains
// the expected string
Expand All @@ -57,7 +62,7 @@ func spawnWithExpects(args []string, xs ...string) error {
l, lerr := proc.ExpectFunc(lineFunc)
if lerr != nil {
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)
if strings.Contains(l, txt) {
Expand All @@ -67,9 +72,9 @@ func spawnWithExpects(args []string, xs ...string) error {
}
perr := proc.Close()
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 {
Expand Down

0 comments on commit b62e829

Please sign in to comment.