summaryrefslogtreecommitdiff
path: root/integrationtests/commandutils.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2021-11-02 09:15:43 +0200
committerPaul Buetow <paul@buetow.org>2021-11-02 09:15:43 +0200
commit479a1c1bff839f40d980fdbedcab80e2e73aeb58 (patch)
treeb3f92443b1e2641b807a5976504e9d49f8d2850e /integrationtests/commandutils.go
parentefeba5233c99a88dc1a49e44673ae56709814624 (diff)
Refactor integration tests. Also fix the dmap1 PIPE test
Diffstat (limited to 'integrationtests/commandutils.go')
-rw-r--r--integrationtests/commandutils.go23
1 files changed, 16 insertions, 7 deletions
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() {