From 1278d50cd267a9c58b401565ef1380294f1d1f3a Mon Sep 17 00:00:00 2001 From: Lucas Bajolet Date: Mon, 6 May 2024 16:42:44 -0400 Subject: [PATCH] test: add empty/non-empty input checkers When running a pipeline on a command's output, a simple check is making sure the pipeline returned something empty or not. This is the goal of those two implementations, basically either the input is empty as expected, or it errors, and the reverse. --- test/pipe_checker_test.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/pipe_checker_test.go b/test/pipe_checker_test.go index 2a9608047..8b2f6331e 100644 --- a/test/pipe_checker_test.go +++ b/test/pipe_checker_test.go @@ -47,6 +47,28 @@ func (ct CustomTester) Check(input string) error { return ct(input) } +// NonEmptyInput errors if the result from the pipeline was empty +func NonEmptyInput() Tester { + return CustomTester(func(in string) error { + in = strings.TrimSpace(in) + if in != "" { + return fmt.Errorf("input is not empty, expected it to be: %s", in) + } + return nil + }) +} + +// EmptyInput errors if the result from the pipeline was not empty +func EmptyInput() Tester { + return CustomTester(func(in string) error { + in = strings.TrimSpace(in) + if in == "" { + return fmt.Errorf("input is empty, expected it not to") + } + return nil + }) +} + // PipeChecker is a kind of checker that essentially lets users write mini // gadgets that pipe inputs together, and compose those to end as a true/false // statement, which translates to an error.