mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2025-01-10 17:38:13 +08:00
deadcode: groupbyRSet
This commit is contained in:
parent
ed999b99bd
commit
34d6e079b2
3 changed files with 71 additions and 82 deletions
|
@ -18,6 +18,19 @@ func init() {
|
|||
color.NoColor = true
|
||||
}
|
||||
|
||||
func makeRec(label, rtype, content string) *models.RecordConfig {
|
||||
origin := "f.com"
|
||||
r := models.RecordConfig{TTL: 300}
|
||||
r.SetLabel(label, origin)
|
||||
r.PopulateFromString(rtype, content, origin)
|
||||
return &r
|
||||
}
|
||||
func makeRecTTL(label, rtype, content string, ttl uint32) *models.RecordConfig {
|
||||
r := makeRec(label, rtype, content)
|
||||
r.TTL = ttl
|
||||
return r
|
||||
}
|
||||
|
||||
var testDataAA1234 = makeRec("laba", "A", "1.2.3.4") // [ 0]
|
||||
var testDataAA5678 = makeRec("laba", "A", "5.6.7.8") //
|
||||
var testDataAA1234ttl700 = makeRecTTL("laba", "A", "1.2.3.4", 700) //
|
||||
|
|
|
@ -1,45 +1,40 @@
|
|||
package diff2
|
||||
|
||||
import (
|
||||
"github.com/StackExchange/dnscontrol/v4/models"
|
||||
"github.com/StackExchange/dnscontrol/v4/pkg/prettyzone"
|
||||
)
|
||||
// type recset struct {
|
||||
// Key models.RecordKey
|
||||
// Recs []*models.RecordConfig
|
||||
// }
|
||||
|
||||
type recset struct {
|
||||
Key models.RecordKey
|
||||
Recs []*models.RecordConfig
|
||||
}
|
||||
// func groupbyRSet(recs models.Records, origin string) []recset {
|
||||
|
||||
func groupbyRSet(recs models.Records, origin string) []recset {
|
||||
// if len(recs) == 0 {
|
||||
// return nil
|
||||
// }
|
||||
|
||||
if len(recs) == 0 {
|
||||
return nil
|
||||
}
|
||||
// // Sort the NameFQDN to a consistent order. The actual sort methodology
|
||||
// // doesn't matter as long as equal values are adjacent.
|
||||
// // Use the PrettySort ordering so that the records are extra pretty.
|
||||
// pretty := prettyzone.PrettySort(recs, origin, 0, nil)
|
||||
// recs = pretty.Records
|
||||
|
||||
// Sort the NameFQDN to a consistent order. The actual sort methodology
|
||||
// doesn't matter as long as equal values are adjacent.
|
||||
// Use the PrettySort ordering so that the records are extra pretty.
|
||||
pretty := prettyzone.PrettySort(recs, origin, 0, nil)
|
||||
recs = pretty.Records
|
||||
// var result []recset
|
||||
// var acc []*models.RecordConfig
|
||||
|
||||
var result []recset
|
||||
var acc []*models.RecordConfig
|
||||
// // Do the first element
|
||||
// prevkey := recs[0].Key()
|
||||
// acc = append(acc, recs[0])
|
||||
|
||||
// Do the first element
|
||||
prevkey := recs[0].Key()
|
||||
acc = append(acc, recs[0])
|
||||
// for i := 1; i < len(recs); i++ {
|
||||
// curkey := recs[i].Key()
|
||||
// if prevkey == curkey { // A run of equal keys.
|
||||
// acc = append(acc, recs[i])
|
||||
// } else { // New key. Append old data to result and start new acc.
|
||||
// result = append(result, recset{Key: prevkey, Recs: acc})
|
||||
// acc = []*models.RecordConfig{recs[i]}
|
||||
// }
|
||||
// prevkey = curkey
|
||||
// }
|
||||
// result = append(result, recset{Key: prevkey, Recs: acc}) // The remainder
|
||||
|
||||
for i := 1; i < len(recs); i++ {
|
||||
curkey := recs[i].Key()
|
||||
if prevkey == curkey { // A run of equal keys.
|
||||
acc = append(acc, recs[i])
|
||||
} else { // New key. Append old data to result and start new acc.
|
||||
result = append(result, recset{Key: prevkey, Recs: acc})
|
||||
acc = []*models.RecordConfig{recs[i]}
|
||||
}
|
||||
prevkey = curkey
|
||||
}
|
||||
result = append(result, recset{Key: prevkey, Recs: acc}) // The remainder
|
||||
|
||||
return result
|
||||
}
|
||||
// return result
|
||||
// }
|
||||
|
|
|
@ -1,51 +1,32 @@
|
|||
package diff2
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
// func makeRecSet(recs ...*models.RecordConfig) *recset {
|
||||
// result := recset{}
|
||||
// result.Key = recs[0].Key()
|
||||
// result.Recs = append(result.Recs, recs...)
|
||||
// return &result
|
||||
// }
|
||||
|
||||
"github.com/StackExchange/dnscontrol/v4/models"
|
||||
)
|
||||
// func Test_groupbyRSet(t *testing.T) {
|
||||
|
||||
func makeRec(label, rtype, content string) *models.RecordConfig {
|
||||
origin := "f.com"
|
||||
r := models.RecordConfig{TTL: 300}
|
||||
r.SetLabel(label, origin)
|
||||
r.PopulateFromString(rtype, content, origin)
|
||||
return &r
|
||||
}
|
||||
func makeRecTTL(label, rtype, content string, ttl uint32) *models.RecordConfig {
|
||||
r := makeRec(label, rtype, content)
|
||||
r.TTL = ttl
|
||||
return r
|
||||
}
|
||||
func makeRecSet(recs ...*models.RecordConfig) *recset {
|
||||
result := recset{}
|
||||
result.Key = recs[0].Key()
|
||||
result.Recs = append(result.Recs, recs...)
|
||||
return &result
|
||||
}
|
||||
// wwwa1 := makeRec("www", "A", "1.1.1.1")
|
||||
// wwwa2 := makeRec("www", "A", "2.2.2.2")
|
||||
// zzza1 := makeRec("zzz", "A", "1.1.0.0")
|
||||
// zzza2 := makeRec("zzz", "A", "2.2.0.0")
|
||||
// wwwmx1 := makeRec("www", "MX", "1 mx1.foo.com.")
|
||||
// wwwmx2 := makeRec("www", "MX", "2 mx2.foo.com.")
|
||||
// zzzmx1 := makeRec("zzz", "MX", "1 mx.foo.com.")
|
||||
// orig := models.Records{wwwa1, wwwa2, zzza1, zzza2, wwwmx1, wwwmx2, zzzmx1}
|
||||
// wantResult := []recset{
|
||||
// *makeRecSet(wwwa1, wwwa2),
|
||||
// *makeRecSet(wwwmx1, wwwmx2),
|
||||
// *makeRecSet(zzza1, zzza2),
|
||||
// *makeRecSet(zzzmx1),
|
||||
// }
|
||||
|
||||
func Test_groupbyRSet(t *testing.T) {
|
||||
|
||||
wwwa1 := makeRec("www", "A", "1.1.1.1")
|
||||
wwwa2 := makeRec("www", "A", "2.2.2.2")
|
||||
zzza1 := makeRec("zzz", "A", "1.1.0.0")
|
||||
zzza2 := makeRec("zzz", "A", "2.2.0.0")
|
||||
wwwmx1 := makeRec("www", "MX", "1 mx1.foo.com.")
|
||||
wwwmx2 := makeRec("www", "MX", "2 mx2.foo.com.")
|
||||
zzzmx1 := makeRec("zzz", "MX", "1 mx.foo.com.")
|
||||
orig := models.Records{wwwa1, wwwa2, zzza1, zzza2, wwwmx1, wwwmx2, zzzmx1}
|
||||
wantResult := []recset{
|
||||
*makeRecSet(wwwa1, wwwa2),
|
||||
*makeRecSet(wwwmx1, wwwmx2),
|
||||
*makeRecSet(zzza1, zzza2),
|
||||
*makeRecSet(zzzmx1),
|
||||
}
|
||||
|
||||
t.Run("afew", func(t *testing.T) {
|
||||
if gotResult := groupbyRSet(orig, "f.com"); !reflect.DeepEqual(gotResult, wantResult) {
|
||||
t.Errorf("groupbyRSet() = %v, want %v", gotResult, wantResult)
|
||||
}
|
||||
})
|
||||
}
|
||||
// t.Run("afew", func(t *testing.T) {
|
||||
// if gotResult := groupbyRSet(orig, "f.com"); !reflect.DeepEqual(gotResult, wantResult) {
|
||||
// t.Errorf("groupbyRSet() = %v, want %v", gotResult, wantResult)
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
|
|
Loading…
Reference in a new issue