From 479a1c1bff839f40d980fdbedcab80e2e73aeb58 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Tue, 2 Nov 2021 09:15:43 +0200 Subject: Refactor integration tests. Also fix the dmap1 PIPE test --- integrationtests/commandutils.go | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'integrationtests/commandutils.go') diff --git a/integrationtests/commandutils.go b/integrationtests/commandutils.go index af898ab..959288a 100644 --- a/integrationtests/commandutils.go +++ b/integrationtests/commandutils.go @@ -62,12 +62,22 @@ func startCommand(ctx context.Context, t *testing.T, inPipeFile, t.Log(cmdStr, strings.Join(args, " ")) cmd := exec.CommandContext(ctx, cmdStr, args...) + var stdinPipe io.WriteCloser + if inPipeFile != "" { + var err error + stdinPipe, err = cmd.StdinPipe() + if err != nil { + return stdoutCh, stderrCh, nil, err + } + } cmdStdout, err := cmd.StdoutPipe() if err != nil { return stdoutCh, stderrCh, nil, err } - cmdStderr, err := cmd.StderrPipe() + if err != nil { + return stdoutCh, stderrCh, nil, err + } err = cmd.Start() if err != nil { return stdoutCh, stderrCh, nil, err @@ -76,16 +86,15 @@ func startCommand(ctx context.Context, t *testing.T, inPipeFile, // Read input file and send to stdin pipe? if inPipeFile != "" { t.Log(fmt.Sprintf("Piping %s to stdin pipe", inPipeFile)) - stdinPipe, err := cmd.StdinPipe() - if err != nil { - return stdoutCh, stderrCh, nil, err - } fd, err := os.Open(inPipeFile) if err != nil { return stdoutCh, stderrCh, nil, err } - defer fd.Close() - go io.Copy(stdinPipe, bufio.NewReader(fd)) + go func() { + io.Copy(stdinPipe, bufio.NewReader(fd)) + stdinPipe.Close() + fd.Close() + }() } go func() { -- cgit v1.2.3