From feff2c21715ab75fdc27ab2a5dcc4d795c45bc17 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 31 Oct 2021 17:23:34 +0200 Subject: add dmap integration test with stdin input pipe --- integrationtests/commandutils.go | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'integrationtests/commandutils.go') 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) -- cgit v1.2.3