diff --git a/provider/pdns.go b/provider/pdns.go index 8b33a4c967..8bf888daf2 100644 --- a/provider/pdns.go +++ b/provider/pdns.go @@ -30,11 +30,12 @@ import ( log "github.com/sirupsen/logrus" "crypto/tls" + "net" + pgo "github.com/ffledgling/pdns-go" "github.com/kubernetes-incubator/external-dns/endpoint" "github.com/kubernetes-incubator/external-dns/pkg/tlsutils" "github.com/kubernetes-incubator/external-dns/plan" - "net" ) type pdnsChangeType string @@ -175,7 +176,7 @@ func (c *PDNSAPIClient) PartitionZones(zones []pgo.Zone) (filteredZones []pgo.Zo } } } else { - residualZones = zones + filteredZones = zones } return filteredZones, residualZones } diff --git a/provider/pdns_test.go b/provider/pdns_test.go index c7c5b592cd..76fdb70413 100644 --- a/provider/pdns_test.go +++ b/provider/pdns_test.go @@ -17,6 +17,7 @@ limitations under the License. package provider import ( + "context" "errors" //"fmt" "net/http" @@ -475,6 +476,44 @@ var ( }, }, } + + DomainFilterListSingle = DomainFilter{ + filters: []string{ + "example.com", + }, + } + + DomainFilterListMultiple = DomainFilter{ + filters: []string{ + "example.com", + "mock.com", + }, + } + + DomainFilterListEmpty = DomainFilter{ + filters: []string{}, + } + + DomainFilterEmptyClient = &PDNSAPIClient{ + dryRun: false, + authCtx: context.WithValue(context.TODO(), pgo.ContextAPIKey, pgo.APIKey{Key: "TEST-API-KEY"}), + client: pgo.NewAPIClient(pgo.NewConfiguration()), + domainFilter: DomainFilterListEmpty, + } + + DomainFilterSingleClient = &PDNSAPIClient{ + dryRun: false, + authCtx: context.WithValue(context.TODO(), pgo.ContextAPIKey, pgo.APIKey{Key: "TEST-API-KEY"}), + client: pgo.NewAPIClient(pgo.NewConfiguration()), + domainFilter: DomainFilterListSingle, + } + + DomainFilterMultipleClient = &PDNSAPIClient{ + dryRun: false, + authCtx: context.WithValue(context.TODO(), pgo.ContextAPIKey, pgo.APIKey{Key: "TEST-API-KEY"}), + client: pgo.NewAPIClient(pgo.NewConfiguration()), + domainFilter: DomainFilterListMultiple, + } ) /******************************************************************************/ @@ -912,6 +951,51 @@ func (suite *NewPDNSProviderTestSuite) TestPDNSmutateRecords() { } +func (suite *NewPDNSProviderTestSuite) TestPDNSClientPartitionZones() { + zoneList := []pgo.Zone{ + ZoneEmpty, + ZoneEmpty2, + } + + partitionResultFilteredEmptyFilter := []pgo.Zone{ + ZoneEmpty, + ZoneEmpty2, + } + + partitionResultResidualEmptyFilter := ([]pgo.Zone)(nil) + + partitionResultFilteredSingleFilter := []pgo.Zone{ + ZoneEmpty, + } + + partitionResultResidualSingleFilter := []pgo.Zone{ + ZoneEmpty2, + } + + partitionResultFilteredMultipleFilter := []pgo.Zone{ + ZoneEmpty, + } + + partitionResultResidualMultipleFilter := []pgo.Zone{ + ZoneEmpty2, + } + + // Check filtered, residual zones when no domain filter specified + filteredZones, residualZones := DomainFilterEmptyClient.PartitionZones(zoneList) + assert.Equal(suite.T(), partitionResultFilteredEmptyFilter, filteredZones) + assert.Equal(suite.T(), partitionResultResidualEmptyFilter, residualZones) + + // Check filtered, residual zones when a single domain filter specified + filteredZones, residualZones = DomainFilterSingleClient.PartitionZones(zoneList) + assert.Equal(suite.T(), partitionResultFilteredSingleFilter, filteredZones) + assert.Equal(suite.T(), partitionResultResidualSingleFilter, residualZones) + + // Check filtered, residual zones when a multiple domain filter specified + filteredZones, residualZones = DomainFilterMultipleClient.PartitionZones(zoneList) + assert.Equal(suite.T(), partitionResultFilteredMultipleFilter, filteredZones) + assert.Equal(suite.T(), partitionResultResidualMultipleFilter, residualZones) +} + func TestNewPDNSProviderTestSuite(t *testing.T) { suite.Run(t, new(NewPDNSProviderTestSuite)) }