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.
pull/13032/head
Lucas Bajolet 2 years ago committed by Lucas Bajolet
parent 8e282d4100
commit afb4340539

@ -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:

@ -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
})

Loading…
Cancel
Save