From 2eeb26083f2cfe1824287d7ba2a82e62ae239f43 Mon Sep 17 00:00:00 2001 From: Marek Siarkowicz Date: Thu, 16 Mar 2023 13:53:17 +0100 Subject: [PATCH] tests: Backport RunUtilCompletion Signed-off-by: Marek Siarkowicz --- pkg/expect/expect.go | 5 +++++ tests/e2e/util.go | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/pkg/expect/expect.go b/pkg/expect/expect.go index 614ac4cb1..3c4018780 100644 --- a/pkg/expect/expect.go +++ b/pkg/expect/expect.go @@ -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. diff --git a/tests/e2e/util.go b/tests/e2e/util.go index 86bf239df..11c2d61fe 100644 --- a/tests/e2e/util.go +++ b/tests/e2e/util.go @@ -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() }