Refactor zone type test

This commit is contained in:
Falcon Taylor-Carter 2021-07-14 09:40:06 -04:00
parent b8cee43d73
commit afe9381b48

View File

@ -25,83 +25,39 @@ import (
"github.com/stretchr/testify/assert"
)
func TestZoneTypeFilterMatchAWS(t *testing.T) {
publicZone := &route53.HostedZone{Config: &route53.HostedZoneConfig{PrivateZone: aws.Bool(false)}}
privateZone := &route53.HostedZone{Config: &route53.HostedZoneConfig{PrivateZone: aws.Bool(true)}}
for _, tc := range []struct {
zoneTypeFilter string
zone *route53.HostedZone
matches bool
}{
{
"", publicZone, true,
},
{
"", privateZone, true,
},
{
"public", publicZone, true,
},
{
"public", privateZone, false,
},
{
"private", publicZone, false,
},
{
"private", privateZone, true,
},
{
"unknown", publicZone, false,
},
{
"", &route53.HostedZone{}, true,
},
{
"public", &route53.HostedZone{}, true,
},
{
"private", &route53.HostedZone{}, false,
},
} {
zoneTypeFilter := NewZoneTypeFilter(tc.zoneTypeFilter)
assert.Equal(t, tc.matches, zoneTypeFilter.Match(tc.zone))
}
}
func TestZoneTypeFilterMatch(t *testing.T) {
publicZone := "public"
privateZone := "private"
publicZoneStr := "public"
privateZoneStr := "private"
publicZoneAWS := &route53.HostedZone{Config: &route53.HostedZoneConfig{PrivateZone: aws.Bool(false)}}
privateZoneAWS := &route53.HostedZone{Config: &route53.HostedZoneConfig{PrivateZone: aws.Bool(true)}}
for _, tc := range []struct {
zoneTypeFilter string
zone string
matches bool
zones []interface{}
}{
{
"", publicZone, true,
"", true, []interface{}{ publicZoneStr, privateZoneStr, &route53.HostedZone{} },
},
{
"", privateZone, true,
"public", true, []interface{}{ publicZoneStr, publicZoneAWS, &route53.HostedZone{} },
},
{
"public", publicZone, true,
"public", false, []interface{}{ privateZoneStr, privateZoneAWS },
},
{
"public", privateZone, false,
"private", true, []interface{}{ privateZoneStr, privateZoneAWS },
},
{
"private", publicZone, false,
"private", false, []interface{}{ publicZoneStr, publicZoneAWS, &route53.HostedZone{} },
},
{
"private", privateZone, true,
},
{
"unknown", publicZone, false,
"unknown", false, []interface{}{ publicZoneStr },
},
} {
zoneTypeFilter := NewZoneTypeFilter(tc.zoneTypeFilter)
assert.Equal(t, tc.matches, zoneTypeFilter.Match(tc.zone))
for _, zone := range tc.zones {
assert.Equal(t, tc.matches, zoneTypeFilter.Match(zone))
}
}
}