mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
Refactor in preparation to unexport RecordConfig.{Name,NameFQDN,Target} (#337)
* Preparing for the unexport of Name/NameFQDN/Target * Cleanups
This commit is contained in:
@ -77,7 +77,7 @@ func (d *differ) IncrementalDiff(existing []*models.RecordConfig) (unchanged, cr
|
||||
if d.matchIgnored(e.GetLabel()) {
|
||||
log.Printf("Ignoring record %s %s due to IGNORE", e.GetLabel(), e.Type)
|
||||
} else {
|
||||
k := key{e.NameFQDN, e.Type}
|
||||
k := key{e.GetLabelFQDN(), e.Type}
|
||||
existingByNameAndType[k] = append(existingByNameAndType[k], e)
|
||||
}
|
||||
}
|
||||
@ -85,7 +85,7 @@ func (d *differ) IncrementalDiff(existing []*models.RecordConfig) (unchanged, cr
|
||||
if d.matchIgnored(dr.GetLabel()) {
|
||||
panic(fmt.Sprintf("Trying to update/add IGNOREd record: %s %s", dr.GetLabel(), dr.Type))
|
||||
} else {
|
||||
k := key{dr.NameFQDN, dr.Type}
|
||||
k := key{dr.GetLabelFQDN(), dr.Type}
|
||||
desiredByNameAndType[k] = append(desiredByNameAndType[k], dr)
|
||||
}
|
||||
}
|
||||
@ -106,7 +106,7 @@ func (d *differ) IncrementalDiff(existing []*models.RecordConfig) (unchanged, cr
|
||||
for i := len(existingRecords) - 1; i >= 0; i-- {
|
||||
ex := existingRecords[i]
|
||||
for j, de := range desiredRecords {
|
||||
if de.Target == ex.Target {
|
||||
if de.GetTargetField() == ex.GetTargetField() {
|
||||
// they're either identical or should be a modification of each other (ttl or metadata changes)
|
||||
if d.content(de) == d.content(ex) {
|
||||
unchanged = append(unchanged, Correlation{d, ex, de})
|
||||
@ -197,12 +197,12 @@ func (d *differ) ChangedGroups(existing []*models.RecordConfig) map[models.Recor
|
||||
|
||||
func (c Correlation) String() string {
|
||||
if c.Existing == nil {
|
||||
return fmt.Sprintf("CREATE %s %s %s", c.Desired.Type, c.Desired.NameFQDN, c.d.content(c.Desired))
|
||||
return fmt.Sprintf("CREATE %s %s %s", c.Desired.Type, c.Desired.GetLabelFQDN(), c.d.content(c.Desired))
|
||||
}
|
||||
if c.Desired == nil {
|
||||
return fmt.Sprintf("DELETE %s %s %s", c.Existing.Type, c.Existing.NameFQDN, c.d.content(c.Existing))
|
||||
return fmt.Sprintf("DELETE %s %s %s", c.Existing.Type, c.Existing.GetLabelFQDN(), c.d.content(c.Existing))
|
||||
}
|
||||
return fmt.Sprintf("MODIFY %s %s: (%s) -> (%s)", c.Existing.Type, c.Existing.NameFQDN, c.d.content(c.Existing), c.d.content(c.Desired))
|
||||
return fmt.Sprintf("MODIFY %s %s: (%s) -> (%s)", c.Existing.Type, c.Existing.GetLabelFQDN(), c.d.content(c.Existing), c.d.content(c.Desired))
|
||||
}
|
||||
|
||||
func sortedKeys(m map[string]*models.RecordConfig) []string {
|
||||
|
@ -7,20 +7,19 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/StackExchange/dnscontrol/models"
|
||||
"github.com/miekg/dns/dnsutil"
|
||||
)
|
||||
|
||||
func myRecord(s string) *models.RecordConfig {
|
||||
parts := strings.Split(s, " ")
|
||||
ttl, _ := strconv.ParseUint(parts[2], 10, 32)
|
||||
return &models.RecordConfig{
|
||||
Name: parts[0],
|
||||
NameFQDN: dnsutil.AddOrigin(parts[0], "example.com"),
|
||||
r := &models.RecordConfig{
|
||||
Type: parts[1],
|
||||
TTL: uint32(ttl),
|
||||
Target: parts[3],
|
||||
Metadata: map[string]string{},
|
||||
}
|
||||
r.SetLabel(parts[0], "example.com")
|
||||
r.SetTarget(parts[3])
|
||||
return r
|
||||
}
|
||||
|
||||
func TestAdditionsOnly(t *testing.T) {
|
||||
|
Reference in New Issue
Block a user