diff options
| author | Paul Buetow <paul@buetow.org> | 2021-10-31 17:23:34 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2021-10-31 17:23:34 +0200 |
| commit | feff2c21715ab75fdc27ab2a5dcc4d795c45bc17 (patch) | |
| tree | 8151f9d6666f558719a096368e1ab686d0fbfad1 /integrationtests/commandutils.go | |
| parent | b5ba67519a597758fa7b2ff3b40f75202717b581 (diff) | |
add dmap integration test with stdin input pipe
Diffstat (limited to 'integrationtests/commandutils.go')
| -rw-r--r-- | integrationtests/commandutils.go | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/integrationtests/commandutils.go b/integrationtests/commandutils.go index d5b5987..af898ab 100644 --- a/integrationtests/commandutils.go +++ b/integrationtests/commandutils.go @@ -4,6 +4,7 @@ import ( "bufio" "context" "fmt" + "io" "os" "os/exec" "strings" @@ -47,8 +48,8 @@ func runCommandRetry(ctx context.Context, t *testing.T, retries int, stdoutFile, return } -func startCommand(ctx context.Context, t *testing.T, cmdStr string, - args ...string) (<-chan string, <-chan string, <-chan error, error) { +func startCommand(ctx context.Context, t *testing.T, inPipeFile, + cmdStr string, args ...string) (<-chan string, <-chan string, <-chan error, error) { stdoutCh := make(chan string) stderrCh := make(chan string) @@ -65,12 +66,28 @@ func startCommand(ctx context.Context, t *testing.T, cmdStr string, if err != nil { return stdoutCh, stderrCh, nil, err } + cmdStderr, err := cmd.StderrPipe() err = cmd.Start() if err != nil { return stdoutCh, stderrCh, nil, err } + // 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() { scanner := bufio.NewScanner(cmdStdout) scanner.Split(bufio.ScanLines) |
