mirror of
https://github.com/kubernetes-sigs/external-dns.git
synced 2025-08-06 01:26:59 +02:00
Run tests via a Mock targetNetFilter instead of the actual one
This commit is contained in:
parent
d7d5a2d404
commit
05bb165ffa
@ -26,6 +26,26 @@ import (
|
||||
"sigs.k8s.io/external-dns/endpoint"
|
||||
)
|
||||
|
||||
type mockTargetNetFilter struct {
|
||||
targets map[string]bool
|
||||
}
|
||||
|
||||
func NewMockTargetNetFilter(targets []string) endpoint.TargetFilterInterface {
|
||||
targetMap := make(map[string]bool)
|
||||
for _, target := range targets {
|
||||
targetMap[target] = true
|
||||
}
|
||||
return &mockTargetNetFilter{targets: targetMap}
|
||||
}
|
||||
|
||||
func (m *mockTargetNetFilter) Match(target string) bool {
|
||||
return m.targets[target]
|
||||
}
|
||||
|
||||
func (m *mockTargetNetFilter) IsConfigured() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// echoSource is a Source that returns the endpoints passed in on creation.
|
||||
type echoSource struct {
|
||||
endpoints []*endpoint.Endpoint
|
||||
@ -66,7 +86,6 @@ func TestEchoSourceReturnGivenSources(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func TestTargetFilterSource(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
@ -89,54 +108,8 @@ func TestTargetFilterSourceEndpoints(t *testing.T) {
|
||||
expected []*endpoint.Endpoint
|
||||
}{
|
||||
{
|
||||
title: "no filters",
|
||||
filters: endpoint.NewTargetNetFilter(nil),
|
||||
endpoints: []*endpoint.Endpoint{endpoint.NewEndpoint("foo", "A", "1.2.3.4")},
|
||||
expected: []*endpoint.Endpoint{endpoint.NewEndpoint("foo", "A", "1.2.3.4")},
|
||||
},
|
||||
{
|
||||
title: "filter matched specific",
|
||||
filters: endpoint.NewTargetNetFilter([]string{"1.2.3.4"}),
|
||||
endpoints: []*endpoint.Endpoint{endpoint.NewEndpoint("foo", "A", "1.2.3.4")},
|
||||
expected: []*endpoint.Endpoint{endpoint.NewEndpoint("foo", "A", "1.2.3.4")},
|
||||
},
|
||||
{
|
||||
title: "filter matched net",
|
||||
filters: endpoint.NewTargetNetFilter([]string{"1.2.3.0/24"}),
|
||||
endpoints: []*endpoint.Endpoint{endpoint.NewEndpoint("foo", "A", "1.2.3.4")},
|
||||
expected: []*endpoint.Endpoint{endpoint.NewEndpoint("foo", "A", "1.2.3.4")},
|
||||
},
|
||||
{
|
||||
title: "filter not matched specific",
|
||||
filters: endpoint.NewTargetNetFilter([]string{"1.2.3.5/32"}),
|
||||
endpoints: []*endpoint.Endpoint{endpoint.NewEndpoint("foo", "A", "1.2.3.4")},
|
||||
expected: []*endpoint.Endpoint{},
|
||||
},
|
||||
{
|
||||
title: "filter not matched net",
|
||||
filters: endpoint.NewTargetNetFilter([]string{"1.2.4.0/24"}),
|
||||
endpoints: []*endpoint.Endpoint{endpoint.NewEndpoint("foo", "A", "1.2.3.4")},
|
||||
expected: []*endpoint.Endpoint{},
|
||||
},
|
||||
{
|
||||
title: "filter not matched CNAME endpoint",
|
||||
filters: endpoint.NewTargetNetFilter([]string{"1.2.4.0/24"}),
|
||||
endpoints: []*endpoint.Endpoint{endpoint.NewEndpoint("foo", "CNAME", "foo.bar")},
|
||||
expected: []*endpoint.Endpoint{},
|
||||
},
|
||||
{
|
||||
title: "filter matched one of two",
|
||||
filters: endpoint.NewTargetNetFilter([]string{"1.2.4.0/24"}),
|
||||
endpoints: []*endpoint.Endpoint{
|
||||
endpoint.NewEndpoint("foo", "CNAME", "foo.bar"),
|
||||
endpoint.NewEndpoint("foo", "A", "1.2.4.1")},
|
||||
expected: []*endpoint.Endpoint{endpoint.NewEndpoint("foo", "A", "1.2.4.1")},
|
||||
},
|
||||
{
|
||||
title: "filter exclusion all",
|
||||
filters: endpoint.NewTargetNetFilterWithExclusions(
|
||||
[]string{""},
|
||||
[]string{"1.0.0.0/8"}),
|
||||
title: "filter exclusion all",
|
||||
filters: NewMockTargetNetFilter([]string{}),
|
||||
endpoints: []*endpoint.Endpoint{
|
||||
endpoint.NewEndpoint("foo", "A", "1.2.3.4"),
|
||||
endpoint.NewEndpoint("foo", "A", "1.2.3.5"),
|
||||
@ -146,19 +119,16 @@ func TestTargetFilterSourceEndpoints(t *testing.T) {
|
||||
expected: []*endpoint.Endpoint{},
|
||||
},
|
||||
{
|
||||
title: "filter exclude internal net",
|
||||
filters: endpoint.NewTargetNetFilterWithExclusions(
|
||||
[]string{""},
|
||||
[]string{"10.0.0.0/8"}),
|
||||
title: "filter exclude internal net",
|
||||
filters: NewMockTargetNetFilter([]string{"8.8.8.8"}),
|
||||
endpoints: []*endpoint.Endpoint{
|
||||
endpoint.NewEndpoint("foo", "A", "10.0.0.1"),
|
||||
endpoint.NewEndpoint("foo", "A", "8.8.8.8")},
|
||||
expected: []*endpoint.Endpoint{endpoint.NewEndpoint("foo", "A", "8.8.8.8")},
|
||||
},
|
||||
{
|
||||
title: "filter only internal",
|
||||
filters: endpoint.NewTargetNetFilterWithExclusions(
|
||||
[]string{"10.0.0.0/8"}, []string{}),
|
||||
title: "filter only internal",
|
||||
filters: NewMockTargetNetFilter([]string{"10.0.0.1"}),
|
||||
endpoints: []*endpoint.Endpoint{
|
||||
endpoint.NewEndpoint("foo", "A", "10.0.0.1"),
|
||||
endpoint.NewEndpoint("foo", "A", "8.8.8.8")},
|
||||
|
Loading…
Reference in New Issue
Block a user