tests: Backport RunUtilCompletion

Signed-off-by: Marek Siarkowicz <siarkowicz@google.com>
This commit is contained in:
Marek Siarkowicz 2023-03-16 13:53:17 +01:00
parent 00e1e5db21
commit 2eeb26083f
2 changed files with 20 additions and 0 deletions

View File

@ -149,6 +149,11 @@ func (ep *ExpectProcess) Signal(sig os.Signal) error {
return ep.cmd.Process.Signal(sig)
}
// Wait waits for the process to finish.
func (ep *ExpectProcess) Wait() {
ep.wg.Wait()
}
// Close waits for the expect process to exit.
// Close currently does not return error if process exited with !=0 status.
// TODO: Close should expose underlying proces failure by default.

View File

@ -78,6 +78,21 @@ func spawnWithExpectLines(args []string, envVars map[string]string, xs ...string
return lines, perr
}
func runUtilCompletion(args []string, envVars map[string]string) ([]string, error) {
proc, err := spawnCmd(args, envVars)
if err != nil {
return nil, fmt.Errorf("failed to spawn command %v with error: %w", args, err)
}
proc.Wait()
err = proc.Close()
if err != nil {
return nil, fmt.Errorf("failed to close command %v with error: %w", args, err)
}
return proc.Lines(), nil
}
func randomLeaseID() int64 {
return rand.New(rand.NewSource(time.Now().UnixNano())).Int63()
}