mirror of
https://github.com/kubernetes-sigs/external-dns.git
synced 2025-08-06 17:46:57 +02:00
test(domain-filter): simple filters on domain exclusion (#5064)
* issue(filter-tags): issue-3718 domain exclusion filters Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com> * issue(filter-tags): issue-3718 domain exclusion filters Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com> * issue(filter-tags): issue-3718 domain exclusion filters Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com> * Apply suggestions from code review Co-authored-by: Michel Loiseleur <97035654+mloiseleur@users.noreply.github.com> --------- Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com> Co-authored-by: Michel Loiseleur <97035654+mloiseleur@users.noreply.github.com>
This commit is contained in:
parent
b98723d78c
commit
70cbcd1314
@ -20,6 +20,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@ -769,3 +770,51 @@ func TestDomainFilterMatchParent(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSimpleDomainFilterWithExclusion(t *testing.T) {
|
||||
test := []struct {
|
||||
domainFilter []string
|
||||
exclusionFilter []string
|
||||
domains []string
|
||||
want []string
|
||||
}{
|
||||
{
|
||||
domainFilter: []string{"ex.com"},
|
||||
exclusionFilter: []string{"subdomain.ex.com"},
|
||||
domains: []string{"subdomain.ex.com", "ex.com", "subdomain.ex.com.", ".subdomain.ex.com", "one.subdomain.ex.com", "ex.com."},
|
||||
want: []string{"ex.com", "ex.com."},
|
||||
},
|
||||
{
|
||||
domainFilter: []string{"ex.com"},
|
||||
exclusionFilter: []string{},
|
||||
domains: []string{"subdomain.ex.com", "ex.com", "subdomain.ex.com.", ".subdomain.ex.com", "one.subdomain.ex.com", "ex.com."},
|
||||
want: []string{"subdomain.ex.com", "ex.com", "subdomain.ex.com.", ".subdomain.ex.com", "one.subdomain.ex.com", "ex.com."},
|
||||
},
|
||||
{
|
||||
domainFilter: []string{"ex.com"},
|
||||
exclusionFilter: []string{"one.subdomain.ex.com"},
|
||||
domains: []string{"subdomain.ex.com", "ex.com", "subdomain.ex.com.", ".subdomain.ex.com", "one.subdomain.ex.com", "ex.com."},
|
||||
want: []string{"subdomain.ex.com", "ex.com", "subdomain.ex.com.", ".subdomain.ex.com", "ex.com."},
|
||||
},
|
||||
{
|
||||
domainFilter: []string{"ex.com"},
|
||||
exclusionFilter: []string{".ex.com"},
|
||||
domains: []string{"subdomain.ex.com", "ex.com", "subdomain.ex.com.", ".subdomain.ex.com", "one.subdomain.ex.com", "ex.com."},
|
||||
want: []string{"ex.com", "ex.com."},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range test {
|
||||
t.Run(fmt.Sprintf("include:%s-exclude:%s", strings.Join(tt.domainFilter, "_"), strings.Join(tt.exclusionFilter, "_")), func(t *testing.T) {
|
||||
domainFilter := NewDomainFilterWithExclusions(tt.domainFilter, tt.exclusionFilter)
|
||||
var got []string
|
||||
for _, domain := range tt.domains {
|
||||
if domainFilter.Match(domain) {
|
||||
got = append(got, domain)
|
||||
}
|
||||
}
|
||||
assert.Equal(t, len(got), len(tt.want))
|
||||
assert.Equal(t, got, tt.want)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user