@@ -26,6 +26,8 @@ import (
2626 "github.com/stretchr/testify/assert"
2727 "github.com/stretchr/testify/require"
2828
29+ log "github.com/sirupsen/logrus"
30+
2931 "sigs.k8s.io/external-dns/endpoint"
3032 "sigs.k8s.io/external-dns/internal/testutils"
3133 "sigs.k8s.io/external-dns/plan"
@@ -1798,3 +1800,40 @@ func TestApplyChangesWithNewFormatOnly(t *testing.T) {
17981800 "TXT record should have 'a-' prefix when using new format only" )
17991801 }
18001802}
1803+
1804+ func TestTXTRegistryRecordsWithEmptyTargets (t * testing.T ) {
1805+ ctx := context .Background ()
1806+ p := inmemory .NewInMemoryProvider ()
1807+ p .CreateZone (testZone )
1808+ p .ApplyChanges (ctx , & plan.Changes {
1809+ Create : []* endpoint.Endpoint {
1810+ {
1811+ DNSName : "empty-targets.test-zone.example.org" ,
1812+ RecordType : endpoint .RecordTypeTXT ,
1813+ Targets : endpoint.Targets {},
1814+ },
1815+ {
1816+ DNSName : "valid-targets.test-zone.example.org" ,
1817+ RecordType : endpoint .RecordTypeTXT ,
1818+ Targets : endpoint.Targets {"target1" },
1819+ },
1820+ },
1821+ })
1822+
1823+ r , _ := NewTXTRegistry (p , "" , "" , "owner" , time .Hour , "" , []string {}, []string {}, false , nil , false )
1824+ b := testutils .LogsToBuffer (log .ErrorLevel , t )
1825+ records , err := r .Records (ctx )
1826+ require .NoError (t , err )
1827+
1828+ expectedRecords := []* endpoint.Endpoint {
1829+ {
1830+ DNSName : "valid-targets.test-zone.example.org" ,
1831+ Targets : endpoint.Targets {"target1" },
1832+ RecordType : endpoint .RecordTypeTXT ,
1833+ Labels : map [string ]string {},
1834+ },
1835+ }
1836+
1837+ assert .True (t , testutils .SameEndpoints (records , expectedRecords ))
1838+ assert .Contains (t , b .String (), "TXT record has no targets empty-targets.test-zone.example.org" )
1839+ }
0 commit comments