From afb43405395f62db0139a9dae12932b000ccba66 Mon Sep 17 00:00:00 2001 From: Lucas Bajolet Date: Mon, 6 May 2024 16:56:33 -0400 Subject: [PATCH] test: rename empty/non-empty pipe testers The name and semantics were a bit unclear with how they were previously named, so this commit changes the name of those functions so it's clearer they are expecting something, and what they're expecting. --- test/gadgets_test.go | 4 ++-- test/pipe_checker_test.go | 24 ++++++++++++++++-------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/test/gadgets_test.go b/test/gadgets_test.go index 16ea28019..eac3bc836 100644 --- a/test/gadgets_test.go +++ b/test/gadgets_test.go @@ -90,12 +90,12 @@ func Grep(expression string, opts ...grepOpts) Checker { pipers: []Pipe{ PipeGrep(expression), }, - check: EmptyInput(), + check: ExpectNonEmptyInput(), } for _, opt := range opts { switch opt { case grepInvert: - pc.check = NonEmptyInput() + pc.check = ExpectEmptyInput() case grepStderr: pc.stream = OnlyStderr case grepStdout: diff --git a/test/pipe_checker_test.go b/test/pipe_checker_test.go index 72193a9e9..06d1d69ba 100644 --- a/test/pipe_checker_test.go +++ b/test/pipe_checker_test.go @@ -60,23 +60,31 @@ func (ct CustomTester) Check(input string) error { return ct(input) } -// NonEmptyInput errors if the result from the pipeline was empty -func NonEmptyInput() Tester { +// ExpectNonEmptyInput errors if the result from the pipeline was empty +// +// Non-empty in this context means that the output contains characters that are +// non-whitespace, i.e. anything that `TrimSpace` (aka unicode.IsSpace) recognizes +// as whitespace. +func ExpectNonEmptyInput() 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) + if in == "" { + return fmt.Errorf("input is empty, expected it not to") } return nil }) } -// EmptyInput errors if the result from the pipeline was not empty -func EmptyInput() Tester { +// ExpectEmptyInput errors if the result from the pipeline was not empty +// +// Non-empty in this context means that the output contains characters that are +// non-whitespace, i.e. anything that `TrimSpace` (aka unicode.IsSpace) recognizes +// as whitespace. +func ExpectEmptyInput() Tester { return CustomTester(func(in string) error { in = strings.TrimSpace(in) - if in == "" { - return fmt.Errorf("input is empty, expected it not to") + if in != "" { + return fmt.Errorf("input is not empty, expected it to be: %s", in) } return nil })