From d175625869bf1560099b795c294c1907be3f07dd Mon Sep 17 00:00:00 2001 From: Lucas Bajolet Date: Fri, 10 May 2024 11:54:49 -0400 Subject: [PATCH] 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. --- packer_test/pipe_checker_test.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packer_test/pipe_checker_test.go b/packer_test/pipe_checker_test.go index f5f5501f3..b34aa896b 100644 --- a/packer_test/pipe_checker_test.go +++ b/packer_test/pipe_checker_test.go @@ -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