Add missing DomainFilter tests

This commit is contained in:
John Gardiner Myers 2023-07-01 10:49:13 -07:00
parent 04a5079469
commit 84aa9c1792

View File

@ -411,7 +411,7 @@ func TestMatchFilterReturnsProperEmptyVal(t *testing.T) {
} }
func TestDomainFilterIsConfigured(t *testing.T) { func TestDomainFilterIsConfigured(t *testing.T) {
for _, tt := range []struct { for i, tt := range []struct {
filters []string filters []string
exclude []string exclude []string
expected bool expected bool
@ -452,9 +452,43 @@ func TestDomainFilterIsConfigured(t *testing.T) {
true, true,
}, },
} { } {
t.Run("test IsConfigured", func(t *testing.T) { t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
df := NewDomainFilterWithExclusions(tt.filters, tt.exclude) df := NewDomainFilterWithExclusions(tt.filters, tt.exclude)
assert.Equal(t, tt.expected, df.IsConfigured()) assert.Equal(t, tt.expected, df.IsConfigured())
}) })
} }
} }
func TestRegexDomainFilterIsConfigured(t *testing.T) {
for i, tt := range []struct {
regex string
regexExclude string
expected bool
}{
{
"",
"",
false,
},
{
"(?:foo|bar)\\.org$",
"",
true,
},
{
"",
"\\.org$",
true,
},
{
"(?:foo|bar)\\.org$",
"\\.org$",
true,
},
} {
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
df := NewRegexDomainFilter(regexp.MustCompile(tt.regex), regexp.MustCompile(tt.regexExclude))
assert.Equal(t, tt.expected, df.IsConfigured())
})
}
}