1
0
mirror of https://github.com/StackExchange/dnscontrol.git synced 2024-05-11 05:55:12 +00:00

CHORE: Remove duplicate ToDiff code (#1684)

This commit is contained in:
Tom Limoncelli
2022-08-11 16:13:24 -04:00
committed by GitHub
parent d6f1575ae5
commit 443b99aa59

View File

@ -53,36 +53,15 @@ type differ struct {
// get normalized content for record. target, ttl, mxprio, and specified metadata // get normalized content for record. target, ttl, mxprio, and specified metadata
func (d *differ) content(r *models.RecordConfig) string { func (d *differ) content(r *models.RecordConfig) string {
// NB(tlim): This function will eventually be replaced by calling
// r.GetTargetDiffable(). In the meanwhile, this function compares // get the extra values maps to add to the comparison.
// its output with r.GetTargetDiffable() to make sure the same
// results are generated. Once we have confidence, this function will go away.
content := fmt.Sprintf("%v ttl=%d", r.GetTargetCombined(), r.TTL)
if r.Type == "SOA" {
content = fmt.Sprintf("%s %v %d %d %d %d ttl=%d", r.GetTargetField(), r.SoaMbox, r.SoaRefresh, r.SoaRetry, r.SoaExpire, r.SoaMinttl, r.TTL) // SoaSerial is not used in comparison
}
var allMaps []map[string]string var allMaps []map[string]string
for _, f := range d.extraValues { for _, f := range d.extraValues {
// sort the extra values map keys to perform a deterministic
// comparison since Golang maps iteration order is not guaranteed
valueMap := f(r) valueMap := f(r)
allMaps = append(allMaps, valueMap) allMaps = append(allMaps, valueMap)
keys := make([]string, 0)
for k := range valueMap {
keys = append(keys, k)
}
sort.Strings(keys)
for _, k := range keys {
v := valueMap[k]
content += fmt.Sprintf(" %s=%s", k, v)
}
} }
control := r.ToDiffable(allMaps...)
if control != content { return r.ToDiffable(allMaps...)
fmt.Printf("CONTROL=%q CONTENT=%q\n", control, content)
panic("OOPS! control != content")
}
return content
} }
func apexException(rec *models.RecordConfig) bool { func apexException(rec *models.RecordConfig) bool {