-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1087 from sundowndev/feat/filtering
Add disable CLI flag
- Loading branch information
Showing
9 changed files
with
100 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package filter | ||
|
||
type Filter interface { | ||
Match(string) bool | ||
} | ||
|
||
type Engine struct { | ||
rules []string | ||
} | ||
|
||
func NewEngine() *Engine { | ||
return &Engine{} | ||
} | ||
|
||
func (e *Engine) AddRule(r ...string) { | ||
e.rules = append(e.rules, r...) | ||
} | ||
|
||
func (e *Engine) Match(r string) bool { | ||
for _, rule := range e.rules { | ||
if rule == r { | ||
return true | ||
} | ||
} | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package filter | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestFilterEngine(t *testing.T) { | ||
testcases := []struct { | ||
name string | ||
rules []string | ||
expected map[string]bool | ||
}{ | ||
{ | ||
name: "test googlesearch is ignored", | ||
rules: []string{"googlesearch"}, | ||
expected: map[string]bool{ | ||
"googlesearch": true, | ||
"numverify": false, | ||
}, | ||
}, | ||
{ | ||
name: "test none is ignored", | ||
rules: []string{}, | ||
expected: map[string]bool{ | ||
"googlesearch": false, | ||
"numverify": false, | ||
}, | ||
}, | ||
} | ||
|
||
for _, tt := range testcases { | ||
t.Run(tt.name, func(t *testing.T) { | ||
e := NewEngine() | ||
e.AddRule(tt.rules...) | ||
for r, isIgnored := range tt.expected { | ||
assert.Equal(t, isIgnored, e.Match(r)) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters