Skip to content

Commit

Permalink
Allowing AND in a filter (#742)
Browse files Browse the repository at this point in the history
i3149 authored Aug 28, 2024
1 parent b5579b6 commit 9a9ef63
Showing 2 changed files with 9 additions and 5 deletions.
7 changes: 5 additions & 2 deletions pkg/filter/filter.go
Original file line number Diff line number Diff line change
@@ -122,8 +122,10 @@ func (i *FilterDefs) Set(value string) error {
func GetFilters(log logger.Underlying, filters []string) ([]FilterWrapper, error) {
ff := FilterDefs{}
for _, f := range filters {
if err := ff.Set(f); err != nil {
return nil, err
for _, andSet := range strings.Split(f, AndToken) {
if err := ff.Set(andSet); err != nil {
return nil, err
}
}
}
filterSet := make([]FilterWrapper, 0)
@@ -153,6 +155,7 @@ func GetFilters(log logger.Underlying, filters []string) ([]FilterWrapper, error
return nil, fmt.Errorf("Invalid type: %s. Valid Types: %s|%s|%s", fd.FType, String, Int, Addr)
}
}
log.Infof("Filter: ", "Added %s", fSet.String())
filterSet = append(filterSet, orSet)
}

7 changes: 4 additions & 3 deletions pkg/filter/filter_test.go
Original file line number Diff line number Diff line change
@@ -28,13 +28,14 @@ func TestFilter(t *testing.T) {
"fooII,==,12",
"src_addr,==,10.2.2.0/24",
"foo,==,no or fooII,==,12",
"foo,==,bar and fooII,==,12",
}
fs, err := GetFilters(l, filters)
assert.NoError(err)
assert.Equal(len(filters), len(fs))
assert.Equal(len(filters)+1, len(fs)) // There's an extra and in here.

results := []bool{true, true, true, false, true, true, true, true, false, true, true, true, true}
results := []bool{true, true, true, false, true, true, true, true, false, true, true, true, true, true, true}
for i, fs := range fs {
assert.Equal(results[i], fs.Filter(kt.InputTesting[0]), "%d -> %v", i, filters[i])
assert.Equal(results[i], fs.Filter(kt.InputTesting[0]), "%d", i)
}
}

0 comments on commit 9a9ef63

Please sign in to comment.