mirror of
https://github.com/kubernetes-sigs/external-dns.git
synced 2025-10-28 17:20:59 +01:00
chore: add tests for case-insensitive TXT prefix
This commit is contained in:
parent
d7516a2580
commit
1cdb941d88
@ -196,17 +196,12 @@ type prefixNameMapper struct {
|
||||
var _ nameMapper = prefixNameMapper{}
|
||||
|
||||
func newPrefixNameMapper(prefix string) prefixNameMapper {
|
||||
return prefixNameMapper{prefix: prefix}
|
||||
return prefixNameMapper{prefix: strings.ToLower(prefix)}
|
||||
}
|
||||
|
||||
func (pr prefixNameMapper) toEndpointName(txtDNSName string) string {
|
||||
log.Debugf("TXT record is %s", txtDNSName)
|
||||
log.Debugf("Prefix is %s", pr.prefix)
|
||||
prefixLower := strings.ToLower(pr.prefix)
|
||||
if strings.HasPrefix(txtDNSName, prefixLower) {
|
||||
log.Debug("Will trim prefix")
|
||||
log.Debug(strings.TrimPrefix(txtDNSName, prefixLower))
|
||||
return strings.TrimPrefix(txtDNSName, prefixLower)
|
||||
if strings.HasPrefix(txtDNSName, pr.prefix) {
|
||||
return strings.TrimPrefix(txtDNSName, pr.prefix)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
@ -136,6 +136,12 @@ func testTXTRegistryRecordsPrefixed(t *testing.T) {
|
||||
records, _ := r.Records()
|
||||
|
||||
assert.True(t, testutils.SameEndpoints(records, expectedRecords))
|
||||
|
||||
// Ensure prefix is case-insensitive
|
||||
r, _ = NewTXTRegistry(p, "TxT.", "owner", time.Hour)
|
||||
records, _ = r.Records()
|
||||
|
||||
assert.True(t, testutils.SameEndpoints(records, expectedRecords))
|
||||
}
|
||||
|
||||
func testTXTRegistryRecordsNoPrefix(t *testing.T) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user