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" "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) { func TestZoneTypeFilterMatch(t *testing.T) {
publicZone := "public" publicZoneStr := "public"
privateZone := "private" 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 { for _, tc := range []struct {
zoneTypeFilter string zoneTypeFilter string
zone string
matches bool 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", false, []interface{}{ publicZoneStr },
},
{
"unknown", publicZone, false,
}, },
} { } {
zoneTypeFilter := NewZoneTypeFilter(tc.zoneTypeFilter) 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))
}
} }
} }