Skip to content

Commit

Permalink
spew.Sdump() filter & add some assertions in FuzzParser()
Browse files Browse the repository at this point in the history
  • Loading branch information
julianbrost authored and yhabteab committed May 2, 2023
1 parent 172182c commit 080e335
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion internal/filter/parser_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package filter

import (
"github.com/davecgh/go-spew/spew"
"github.com/stretchr/testify/assert"
"strings"
"testing"
Expand Down Expand Up @@ -322,10 +323,35 @@ func FuzzParser(f *testing.F) {
f.Add("col%29umn>val%29ue")

f.Fuzz(func(t *testing.T, expr string) {
_, err := ParseFilter(expr)
f, err := ParseFilter(expr)

if strings.Count(expr, "(") != strings.Count(expr, ")") {
assert.Error(t, err)
}

if err == nil {
dump := spew.Sdump(f)

assertDumpContainsAny := func(substrs ...string) {
for _, substr := range substrs {
if strings.Contains(dump, substr) {
return
}
}

assert.Failf(t, "Parsed expression dump did not contain any expected string",
"Expression: %q\nExpected: %#v\n\n%s", expr, substrs, dump)
}

if strings.Contains(expr, "&") {
assertDumpContainsAny("All")
}
if strings.Contains(expr, "|") {
assertDumpContainsAny("Any", "None")
}
if strings.Contains(expr, "!") {
assertDumpContainsAny("None", "UnEqual", "Unlike")
}
}
})
}

0 comments on commit 080e335

Please sign in to comment.