fix(registry): improve logging for TXT records with empty targets and add unit test

This commit is contained in:
Saikat Chakrabortty 2025-03-06 11:48:45 +01:00
parent d097f9c2ff
commit 4ef055b1be
2 changed files with 36 additions and 1 deletions

View File

@ -148,7 +148,7 @@ func (im *TXTRegistry) Records(ctx context.Context) ([]*endpoint.Endpoint, error
// We simply assume that TXT records for the registry will always have only one target.
// If there are no targets (e.g for routing policy based records in google), direct targets will be empty
if len(record.Targets) == 0 {
log.Errorf("TXT record has no targets", record.DNSName)
log.Errorf("TXT record has no targets %s", record.DNSName)
continue
}
labels, err := endpoint.NewLabelsFromString(record.Targets[0], im.txtEncryptAESKey)

View File

@ -1798,3 +1798,38 @@ func TestApplyChangesWithNewFormatOnly(t *testing.T) {
"TXT record should have 'a-' prefix when using new format only")
}
}
func TestTXTRegistryRecordsWithEmptyTargets(t *testing.T) {
ctx := context.Background()
p := inmemory.NewInMemoryProvider()
p.CreateZone(testZone)
p.ApplyChanges(ctx, &plan.Changes{
Create: []*endpoint.Endpoint{
{
DNSName: "empty-targets.test-zone.example.org",
RecordType: endpoint.RecordTypeTXT,
Targets: endpoint.Targets{},
},
{
DNSName: "valid-targets.test-zone.example.org",
RecordType: endpoint.RecordTypeTXT,
Targets: endpoint.Targets{"target1"},
},
},
})
r, _ := NewTXTRegistry(p, "", "", "owner", time.Hour, "", []string{}, []string{}, false, nil, false)
records, err := r.Records(ctx)
require.NoError(t, err)
expectedRecords := []*endpoint.Endpoint{
{
DNSName: "valid-targets.test-zone.example.org",
Targets: endpoint.Targets{"target1"},
RecordType: endpoint.RecordTypeTXT,
Labels: map[string]string{},
},
}
assert.True(t, testutils.SameEndpoints(records, expectedRecords))
}