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:
@ -53,36 +53,15 @@ type differ struct {
|
||||
|
||||
// get normalized content for record. target, ttl, mxprio, and specified metadata
|
||||
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
|
||||
// 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
|
||||
}
|
||||
|
||||
// get the extra values maps to add to the comparison.
|
||||
var allMaps []map[string]string
|
||||
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)
|
||||
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 {
|
||||
fmt.Printf("CONTROL=%q CONTENT=%q\n", control, content)
|
||||
panic("OOPS! control != content")
|
||||
}
|
||||
return content
|
||||
|
||||
return r.ToDiffable(allMaps...)
|
||||
}
|
||||
|
||||
func apexException(rec *models.RecordConfig) bool {
|
||||
|
Reference in New Issue
Block a user