gcs/gcs_test: adds generic tests for all matching strats
This commit is contained in:
parent
36301f211d
commit
bf1e1be935
1 changed files with 65 additions and 30 deletions
|
@ -217,36 +217,71 @@ func TestGCSFilterMatch(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestGCSFilterMatchAny checks that both the built and copied filters match a
|
// AnyMatcher is the function signature of our matching algorithms.
|
||||||
// list correctly, logging any false positives without failing on them.
|
type AnyMatcher func(key [gcs.KeySize]byte, data [][]byte) (bool, error)
|
||||||
func TestGCSFilterMatchAny(t *testing.T) {
|
|
||||||
match, err := filter.MatchAny(key, contents2)
|
// TestGCSFilterMatchAnySuite checks that all of our matching algorithms
|
||||||
|
// properly match a list correctly when using built or copied filters, logging
|
||||||
|
// any false positives without failing on them.
|
||||||
|
func TestGCSFilterMatchAnySuite(t *testing.T) {
|
||||||
|
funcs := []struct {
|
||||||
|
name string
|
||||||
|
matchAny func(*gcs.Filter) AnyMatcher
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
"default",
|
||||||
|
func(f *gcs.Filter) AnyMatcher {
|
||||||
|
return f.MatchAny
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hash",
|
||||||
|
func(f *gcs.Filter) AnyMatcher {
|
||||||
|
return f.HashMatchAny
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"zip",
|
||||||
|
func(f *gcs.Filter) AnyMatcher {
|
||||||
|
return f.ZipMatchAny
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range funcs {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
contentsCopy := make([][]byte, len(contents2))
|
||||||
|
copy(contentsCopy, contents2)
|
||||||
|
|
||||||
|
match, err := test.matchAny(filter)(key, contentsCopy)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Filter match any failed: %s", err.Error())
|
t.Fatalf("Filter match any failed: %s", err.Error())
|
||||||
}
|
}
|
||||||
if match {
|
if match {
|
||||||
t.Logf("False positive match, should be 1 in 2**%d!", P)
|
t.Logf("False positive match, should be 1 in 2**%d!", P)
|
||||||
}
|
}
|
||||||
match, err = filter2.MatchAny(key, contents2)
|
match, err = test.matchAny(filter2)(key, contentsCopy)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Filter match any failed: %s", err.Error())
|
t.Fatalf("Filter match any failed: %s", err.Error())
|
||||||
}
|
}
|
||||||
if match {
|
if match {
|
||||||
t.Logf("False positive match, should be 1 in 2**%d!", P)
|
t.Logf("False positive match, should be 1 in 2**%d!", P)
|
||||||
}
|
}
|
||||||
contents2 = append(contents2, []byte("Nate"))
|
contentsCopy = append(contentsCopy, []byte("Nate"))
|
||||||
match, err = filter.MatchAny(key, contents2)
|
match, err = test.matchAny(filter)(key, contentsCopy)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Filter match any failed: %s", err.Error())
|
t.Fatalf("Filter match any failed: %s", err.Error())
|
||||||
}
|
}
|
||||||
if !match {
|
if !match {
|
||||||
t.Fatal("Filter didn't match any when it should have!")
|
t.Fatal("Filter didn't match any when it should have!")
|
||||||
}
|
}
|
||||||
match, err = filter2.MatchAny(key, contents2)
|
match, err = test.matchAny(filter2)(key, contentsCopy)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Filter match any failed: %s", err.Error())
|
t.Fatalf("Filter match any failed: %s", err.Error())
|
||||||
}
|
}
|
||||||
if !match {
|
if !match {
|
||||||
t.Fatal("Filter didn't match any when it should have!")
|
t.Fatal("Filter didn't match any when it should have!")
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue