@@ -1516,14 +1516,12 @@ func TestNewTXTScheme(t *testing.T) {
15161516
15171517func TestGenerateTXT (t * testing.T ) {
15181518 record := newEndpointWithOwner ("foo.test-zone.example.org" , "new-foo.loadbalancer.com" , endpoint .RecordTypeCNAME , "owner" )
1519- expectedTXT := []* endpoint.Endpoint {
1520- {
1521- DNSName : "cname-foo.test-zone.example.org" ,
1522- Targets : endpoint.Targets {"\" heritage=external-dns,external-dns/owner=owner\" " },
1523- RecordType : endpoint .RecordTypeTXT ,
1524- Labels : map [string ]string {
1525- endpoint .OwnedRecordLabelKey : "foo.test-zone.example.org" ,
1526- },
1519+ expectedTXT := & endpoint.Endpoint {
1520+ DNSName : "cname-foo.test-zone.example.org" ,
1521+ Targets : endpoint.Targets {"\" heritage=external-dns,external-dns/owner=owner\" " },
1522+ RecordType : endpoint .RecordTypeTXT ,
1523+ Labels : map [string ]string {
1524+ endpoint .OwnedRecordLabelKey : "foo.test-zone.example.org" ,
15271525 },
15281526 }
15291527 p := inmemory .NewInMemoryProvider ()
@@ -1535,14 +1533,12 @@ func TestGenerateTXT(t *testing.T) {
15351533
15361534func TestGenerateTXTWithMigration (t * testing.T ) {
15371535 record := newEndpointWithOwner ("foo.test-zone.example.org" , "1.2.3.4" , endpoint .RecordTypeA , "owner" )
1538- expectedTXTBeforeMigration := []* endpoint.Endpoint {
1539- {
1540- DNSName : "a-foo.test-zone.example.org" ,
1541- Targets : endpoint.Targets {"\" heritage=external-dns,external-dns/owner=owner\" " },
1542- RecordType : endpoint .RecordTypeTXT ,
1543- Labels : map [string ]string {
1544- endpoint .OwnedRecordLabelKey : "foo.test-zone.example.org" ,
1545- },
1536+ expectedTXTBeforeMigration := & endpoint.Endpoint {
1537+ DNSName : "a-foo.test-zone.example.org" ,
1538+ Targets : endpoint.Targets {"\" heritage=external-dns,external-dns/owner=owner\" " },
1539+ RecordType : endpoint .RecordTypeTXT ,
1540+ Labels : map [string ]string {
1541+ endpoint .OwnedRecordLabelKey : "foo.test-zone.example.org" ,
15461542 },
15471543 }
15481544 p := inmemory .NewInMemoryProvider ()
@@ -1551,14 +1547,12 @@ func TestGenerateTXTWithMigration(t *testing.T) {
15511547 gotTXTBeforeMigration := r .generateTXTRecord (record )
15521548 assert .Equal (t , expectedTXTBeforeMigration , gotTXTBeforeMigration )
15531549
1554- expectedTXTAfterMigration := []* endpoint.Endpoint {
1555- {
1556- DNSName : "a-foo.test-zone.example.org" ,
1557- Targets : endpoint.Targets {"\" heritage=external-dns,external-dns/owner=foobar\" " },
1558- RecordType : endpoint .RecordTypeTXT ,
1559- Labels : map [string ]string {
1560- endpoint .OwnedRecordLabelKey : "foo.test-zone.example.org" ,
1561- },
1550+ expectedTXTAfterMigration := & endpoint.Endpoint {
1551+ DNSName : "a-foo.test-zone.example.org" ,
1552+ Targets : endpoint.Targets {"\" heritage=external-dns,external-dns/owner=foobar\" " },
1553+ RecordType : endpoint .RecordTypeTXT ,
1554+ Labels : map [string ]string {
1555+ endpoint .OwnedRecordLabelKey : "foo.test-zone.example.org" ,
15621556 },
15631557 }
15641558
@@ -1570,14 +1564,12 @@ func TestGenerateTXTWithMigration(t *testing.T) {
15701564
15711565func TestGenerateTXTForAAAA (t * testing.T ) {
15721566 record := newEndpointWithOwner ("foo.test-zone.example.org" , "2001:DB8::1" , endpoint .RecordTypeAAAA , "owner" )
1573- expectedTXT := []* endpoint.Endpoint {
1574- {
1575- DNSName : "aaaa-foo.test-zone.example.org" ,
1576- Targets : endpoint.Targets {"\" heritage=external-dns,external-dns/owner=owner\" " },
1577- RecordType : endpoint .RecordTypeTXT ,
1578- Labels : map [string ]string {
1579- endpoint .OwnedRecordLabelKey : "foo.test-zone.example.org" ,
1580- },
1567+ expectedTXT := & endpoint.Endpoint {
1568+ DNSName : "aaaa-foo.test-zone.example.org" ,
1569+ Targets : endpoint.Targets {"\" heritage=external-dns,external-dns/owner=owner\" " },
1570+ RecordType : endpoint .RecordTypeTXT ,
1571+ Labels : map [string ]string {
1572+ endpoint .OwnedRecordLabelKey : "foo.test-zone.example.org" ,
15811573 },
15821574 }
15831575 p := inmemory .NewInMemoryProvider ()
@@ -1595,8 +1587,8 @@ func TestFailGenerateTXT(t *testing.T) {
15951587 RecordType : endpoint .RecordTypeCNAME ,
15961588 Labels : map [string ]string {},
15971589 }
1598- // A bad DNS name returns empty expected TXT
1599- expectedTXT := [] * endpoint.Endpoint {}
1590+ // A bad DNS name returns nil
1591+ var expectedTXT * endpoint.Endpoint
16001592 p := inmemory .NewInMemoryProvider ()
16011593 p .CreateZone (testZone )
16021594 r , _ := NewTXTRegistry (p , "" , "" , "owner" , time .Hour , "" , []string {}, []string {}, false , nil , "" )
@@ -1749,23 +1741,14 @@ func TestGenerateTXTRecordWithNewFormatOnly(t *testing.T) {
17491741 for _ , tc := range testCases {
17501742 t .Run (tc .name , func (t * testing.T ) {
17511743 r , _ := NewTXTRegistry (p , "" , "" , "owner" , time .Hour , "" , []string {}, []string {}, false , nil , "" )
1752- records := r .generateTXTRecord (tc .endpoint )
1744+ txt := r .generateTXTRecord (tc .endpoint )
17531745
1754- assert .Len (t , records , tc . expectedRecords , tc .description )
1746+ assert .NotNil (t , txt , tc .description )
17551747
1756- for _ , record := range records {
1757- assert .Equal (t , endpoint .RecordTypeTXT , record .RecordType )
1758- }
1748+ assert .Equal (t , endpoint .RecordTypeTXT , txt .RecordType )
17591749
17601750 if tc .endpoint .RecordType == endpoint .RecordTypeAAAA {
1761- hasNewFormat := false
1762- for _ , record := range records {
1763- if strings .HasPrefix (record .DNSName , tc .expectedPrefix ) {
1764- hasNewFormat = true
1765- break
1766- }
1767- }
1768- assert .True (t , hasNewFormat ,
1751+ assert .True (t , strings .HasPrefix (txt .DNSName , tc .expectedPrefix ),
17691752 "Should have at least one record with prefix %s when using new format" , tc .expectedPrefix )
17701753 }
17711754 })
@@ -2082,30 +2065,26 @@ func TestTXTRecordMigration(t *testing.T) {
20822065
20832066 newTXTRecord := r .generateTXTRecord (createdRecords [0 ])
20842067
2085- expectedTXTRecords := []* endpoint.Endpoint {
2086- {
2087- DNSName : "a-bar.test-zone.example.org" ,
2088- Targets : endpoint.Targets {"\" heritage=external-dns,external-dns/owner=foo\" " },
2089- RecordType : endpoint .RecordTypeTXT ,
2090- },
2068+ expectedTXTRecord := endpoint.Endpoint {
2069+ DNSName : "a-bar.test-zone.example.org" ,
2070+ Targets : endpoint.Targets {"\" heritage=external-dns,external-dns/owner=foo\" " },
2071+ RecordType : endpoint .RecordTypeTXT ,
20912072 }
20922073
2093- assert .Equal (t , expectedTXTRecords [ 0 ] .Targets , newTXTRecord [ 0 ] .Targets )
2074+ assert .Equal (t , expectedTXTRecord .Targets , newTXTRecord .Targets )
20942075
20952076 r , _ = NewTXTRegistry (p , "%{record_type}-" , "" , "foobar" , time .Hour , "" , []string {}, []string {}, false , nil , "foo" )
20962077
20972078 updatedRecords , _ := r .Records (ctx )
20982079
20992080 updatedTXTRecord := r .generateTXTRecord (updatedRecords [0 ])
21002081
2101- expectedFinalTXT := []* endpoint.Endpoint {
2102- {
2103- DNSName : "a-bar.test-zone.example.org" ,
2104- Targets : endpoint.Targets {"\" heritage=external-dns,external-dns/owner=foobar\" " },
2105- RecordType : endpoint .RecordTypeTXT ,
2106- },
2082+ expectedFinalTXT := endpoint.Endpoint {
2083+ DNSName : "a-bar.test-zone.example.org" ,
2084+ Targets : endpoint.Targets {"\" heritage=external-dns,external-dns/owner=foobar\" " },
2085+ RecordType : endpoint .RecordTypeTXT ,
21072086 }
21082087
2109- assert .Equal (t , updatedTXTRecord [ 0 ] .Targets , expectedFinalTXT [ 0 ] .Targets )
2088+ assert .Equal (t , updatedTXTRecord .Targets , expectedFinalTXT .Targets )
21102089
21112090}
0 commit comments