mirror of
https://github.com/kubernetes-sigs/external-dns.git
synced 2025-10-29 01:31:08 +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{}
|
var _ nameMapper = prefixNameMapper{}
|
||||||
|
|
||||||
func newPrefixNameMapper(prefix string) prefixNameMapper {
|
func newPrefixNameMapper(prefix string) prefixNameMapper {
|
||||||
return prefixNameMapper{prefix: prefix}
|
return prefixNameMapper{prefix: strings.ToLower(prefix)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pr prefixNameMapper) toEndpointName(txtDNSName string) string {
|
func (pr prefixNameMapper) toEndpointName(txtDNSName string) string {
|
||||||
log.Debugf("TXT record is %s", txtDNSName)
|
if strings.HasPrefix(txtDNSName, pr.prefix) {
|
||||||
log.Debugf("Prefix is %s", pr.prefix)
|
return strings.TrimPrefix(txtDNSName, 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)
|
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|||||||
@ -136,6 +136,12 @@ func testTXTRegistryRecordsPrefixed(t *testing.T) {
|
|||||||
records, _ := r.Records()
|
records, _ := r.Records()
|
||||||
|
|
||||||
assert.True(t, testutils.SameEndpoints(records, expectedRecords))
|
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) {
|
func testTXTRegistryRecordsNoPrefix(t *testing.T) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user