packer_test: add Tee pipe gadget

When troubleshooting a pipeline for a test, it can be useful to print
the input out without necessarily preventing the pipeline to work.

The Tee gadget is exactly made for this purpose, the input of the Tee is
printed out through `t.Log`, and the input is forwarded to the next step
in the pipeline.
This commit is contained in:
Lucas Bajolet
2024-06-07 14:38:20 -04:00
parent 28bf784869
commit 032114b3fc
+11
View File
@@ -5,6 +5,7 @@ import (
"regexp"
"strconv"
"strings"
"testing"
)
// Pipe is any command that allows piping two gadgets together
@@ -44,6 +45,16 @@ func LineCount() Pipe {
})
}
// Tee pipes the output to stdout (as t.Logf) and forwards it, unaltered
//
// This is useful typically for troubleshooting a pipe that misbehaves
func Tee(t *testing.T) Pipe {
return CustomPipe(func(s string) (string, error) {
t.Logf(s)
return s, nil
})
}
// Tester is the end of a pipe for testing purposes.
//
// Once multiple commands have been piped together in a pipeline, we can