mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2025-11-12 09:20:32 +08:00
Integration tests should test diff2's IGNORE* (#2292)
Co-authored-by: Tom Limoncelli <tal@whatexit.org>
This commit is contained in:
parent
1690bae128
commit
be8495c5e8
4 changed files with 70 additions and 20 deletions
|
|
@ -209,6 +209,7 @@ func makeChanges(t *testing.T, prv providers.DNSServiceProvider, dc *models.Doma
|
||||||
}
|
}
|
||||||
dom.IgnoredNames = tst.IgnoredNames
|
dom.IgnoredNames = tst.IgnoredNames
|
||||||
dom.IgnoredTargets = tst.IgnoredTargets
|
dom.IgnoredTargets = tst.IgnoredTargets
|
||||||
|
dom.Unmanaged = tst.Unmanaged
|
||||||
models.PostProcessRecords(dom.Records)
|
models.PostProcessRecords(dom.Records)
|
||||||
dom2, _ := dom.Copy()
|
dom2, _ := dom.Copy()
|
||||||
|
|
||||||
|
|
@ -229,11 +230,13 @@ func makeChanges(t *testing.T, prv providers.DNSServiceProvider, dc *models.Doma
|
||||||
if *verbose {
|
if *verbose {
|
||||||
t.Log("\n" + c.Msg)
|
t.Log("\n" + c.Msg)
|
||||||
}
|
}
|
||||||
|
if c.F != nil { // F == nil if there is just a msg, no action.
|
||||||
err = c.F()
|
err = c.F()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// If we just emptied out the zone, no need for a second pass.
|
// If we just emptied out the zone, no need for a second pass.
|
||||||
if len(tst.Records) == 0 {
|
if len(tst.Records) == 0 {
|
||||||
|
|
@ -245,8 +248,8 @@ func makeChanges(t *testing.T, prv providers.DNSServiceProvider, dc *models.Doma
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if len(corrections) != 0 {
|
if count := zonerecs.CountActionable(corrections); count != 0 {
|
||||||
t.Logf("Expected 0 corrections on second run, but found %d.", len(corrections))
|
t.Logf("Expected 0 corrections on second run, but found %d.", count)
|
||||||
for i, c := range corrections {
|
for i, c := range corrections {
|
||||||
t.Logf("UNEXPECTED #%d: %s", i, c.Msg)
|
t.Logf("UNEXPECTED #%d: %s", i, c.Msg)
|
||||||
}
|
}
|
||||||
|
|
@ -362,8 +365,8 @@ func TestDualProviders(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if len(cs) != 0 {
|
if count := zonerecs.CountActionable(cs); count != 0 {
|
||||||
t.Logf("Expect no corrections on second run, but found %d.", len(cs))
|
t.Logf("Expect no corrections on second run, but found %d.", count)
|
||||||
for i, c := range cs {
|
for i, c := range cs {
|
||||||
t.Logf("#%d: %s", i, c.Msg)
|
t.Logf("#%d: %s", i, c.Msg)
|
||||||
}
|
}
|
||||||
|
|
@ -385,6 +388,7 @@ type TestCase struct {
|
||||||
Records []*models.RecordConfig
|
Records []*models.RecordConfig
|
||||||
IgnoredNames []*models.IgnoreName
|
IgnoredNames []*models.IgnoreName
|
||||||
IgnoredTargets []*models.IgnoreTarget
|
IgnoredTargets []*models.IgnoreTarget
|
||||||
|
Unmanaged []*models.UnmanagedConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetLabel(r *models.RecordConfig, label, domain string) {
|
func SetLabel(r *models.RecordConfig, label, domain string) {
|
||||||
|
|
@ -585,15 +589,24 @@ func tc(desc string, recs ...*models.RecordConfig) *TestCase {
|
||||||
var records []*models.RecordConfig
|
var records []*models.RecordConfig
|
||||||
var ignoredNames []*models.IgnoreName
|
var ignoredNames []*models.IgnoreName
|
||||||
var ignoredTargets []*models.IgnoreTarget
|
var ignoredTargets []*models.IgnoreTarget
|
||||||
|
var unmanagedItems []*models.UnmanagedConfig
|
||||||
for _, r := range recs {
|
for _, r := range recs {
|
||||||
if r.Type == "IGNORE_NAME" {
|
if r.Type == "IGNORE_NAME" {
|
||||||
ignoredNames = append(ignoredNames, &models.IgnoreName{Pattern: r.GetLabel(), Types: r.GetTargetField()})
|
ignoredNames = append(ignoredNames, &models.IgnoreName{Pattern: r.GetLabel(), Types: r.GetTargetField()})
|
||||||
|
unmanagedItems = append(unmanagedItems, &models.UnmanagedConfig{
|
||||||
|
LabelPattern: r.GetLabel(),
|
||||||
|
RTypePattern: r.GetTargetField(),
|
||||||
|
})
|
||||||
} else if r.Type == "IGNORE_TARGET" {
|
} else if r.Type == "IGNORE_TARGET" {
|
||||||
rec := &models.IgnoreTarget{
|
rec := &models.IgnoreTarget{
|
||||||
Pattern: r.GetLabel(),
|
Pattern: r.GetLabel(),
|
||||||
Type: r.GetTargetField(),
|
Type: r.GetTargetField(),
|
||||||
}
|
}
|
||||||
ignoredTargets = append(ignoredTargets, rec)
|
ignoredTargets = append(ignoredTargets, rec)
|
||||||
|
unmanagedItems = append(unmanagedItems, &models.UnmanagedConfig{
|
||||||
|
RTypePattern: r.GetTargetField(),
|
||||||
|
TargetPattern: r.GetLabel(),
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
records = append(records, r)
|
records = append(records, r)
|
||||||
}
|
}
|
||||||
|
|
@ -603,6 +616,7 @@ func tc(desc string, recs ...*models.RecordConfig) *TestCase {
|
||||||
Records: records,
|
Records: records,
|
||||||
IgnoredNames: ignoredNames,
|
IgnoredNames: ignoredNames,
|
||||||
IgnoredTargets: ignoredTargets,
|
IgnoredTargets: ignoredTargets,
|
||||||
|
Unmanaged: unmanagedItems,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -186,7 +186,14 @@ func ByZone(existing models.Records, dc *models.DomainConfig, compFunc Comparabl
|
||||||
|
|
||||||
// Only return the messages. The caller has the list of records needed to build the new zone.
|
// Only return the messages. The caller has the list of records needed to build the new zone.
|
||||||
instructions, err := byHelper(analyzeByRecord, existing, dc, compFunc)
|
instructions, err := byHelper(analyzeByRecord, existing, dc, compFunc)
|
||||||
return justMsgs(instructions), len(instructions) != 0, err
|
changes := false
|
||||||
|
for i, _ := range instructions {
|
||||||
|
//fmt.Printf("DEBUG: ByZone #%d: %v\n", i, ii)
|
||||||
|
if instructions[i].Type != REPORT {
|
||||||
|
changes = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return justMsgs(instructions), changes, err
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
|
||||||
|
|
@ -32,3 +32,16 @@ func CorrectZoneRecords(driver models.DNSProvider, dc *models.DomainConfig) ([]*
|
||||||
|
|
||||||
return driver.GetZoneRecordsCorrections(dc, existingRecords)
|
return driver.GetZoneRecordsCorrections(dc, existingRecords)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CountActionable returns the number of corrections that have
|
||||||
|
// actions. It is like `len(corrections)` but doesn't count any
|
||||||
|
// corrections that are purely informational. (i.e. `.F` is nil)
|
||||||
|
func CountActionable(corrections []*models.Correction) int {
|
||||||
|
count := 0
|
||||||
|
for i, _ := range corrections {
|
||||||
|
if corrections[i].F != nil {
|
||||||
|
count++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -483,6 +483,7 @@ func (r *route53Provider) GetZoneRecordsCorrections(dc *models.DomainConfig, exi
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
instructions = reorderInstructions(instructions)
|
instructions = reorderInstructions(instructions)
|
||||||
|
wasReport := false
|
||||||
for _, inst := range instructions {
|
for _, inst := range instructions {
|
||||||
instNameFQDN := inst.Key.NameFQDN
|
instNameFQDN := inst.Key.NameFQDN
|
||||||
instType := inst.Key.Type
|
instType := inst.Key.Type
|
||||||
|
|
@ -492,6 +493,7 @@ func (r *route53Provider) GetZoneRecordsCorrections(dc *models.DomainConfig, exi
|
||||||
|
|
||||||
case diff2.REPORT:
|
case diff2.REPORT:
|
||||||
chg = r53Types.Change{}
|
chg = r53Types.Change{}
|
||||||
|
wasReport = true
|
||||||
|
|
||||||
case diff2.CREATE:
|
case diff2.CREATE:
|
||||||
fallthrough
|
fallthrough
|
||||||
|
|
@ -545,6 +547,18 @@ func (r *route53Provider) GetZoneRecordsCorrections(dc *models.DomainConfig, exi
|
||||||
}
|
}
|
||||||
|
|
||||||
addCorrection := func(msg string, req *r53.ChangeResourceRecordSetsInput) {
|
addCorrection := func(msg string, req *r53.ChangeResourceRecordSetsInput) {
|
||||||
|
|
||||||
|
if wasReport {
|
||||||
|
|
||||||
|
// Add a "msg only" correction.
|
||||||
|
corrections = append(corrections,
|
||||||
|
&models.Correction{
|
||||||
|
Msg: msg,
|
||||||
|
})
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
// Add a function to execute.
|
||||||
corrections = append(corrections,
|
corrections = append(corrections,
|
||||||
&models.Correction{
|
&models.Correction{
|
||||||
Msg: msg,
|
Msg: msg,
|
||||||
|
|
@ -561,6 +575,8 @@ func (r *route53Provider) GetZoneRecordsCorrections(dc *models.DomainConfig, exi
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// Send the changes in as few API calls as possible.
|
// Send the changes in as few API calls as possible.
|
||||||
batcher := newChangeBatcher(changes)
|
batcher := newChangeBatcher(changes)
|
||||||
for batcher.Next() {
|
for batcher.Next() {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue