mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
deadcode: groupbyRSet
This commit is contained in:
@ -18,6 +18,19 @@ func init() {
|
|||||||
color.NoColor = true
|
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 testDataAA1234 = makeRec("laba", "A", "1.2.3.4") // [ 0]
|
||||||
var testDataAA5678 = makeRec("laba", "A", "5.6.7.8") //
|
var testDataAA5678 = makeRec("laba", "A", "5.6.7.8") //
|
||||||
var testDataAA1234ttl700 = makeRecTTL("laba", "A", "1.2.3.4", 700) //
|
var testDataAA1234ttl700 = makeRecTTL("laba", "A", "1.2.3.4", 700) //
|
||||||
|
@ -1,45 +1,40 @@
|
|||||||
package diff2
|
package diff2
|
||||||
|
|
||||||
import (
|
// type recset struct {
|
||||||
"github.com/StackExchange/dnscontrol/v4/models"
|
// Key models.RecordKey
|
||||||
"github.com/StackExchange/dnscontrol/v4/pkg/prettyzone"
|
// Recs []*models.RecordConfig
|
||||||
)
|
// }
|
||||||
|
|
||||||
type recset struct {
|
// func groupbyRSet(recs models.Records, origin string) []recset {
|
||||||
Key models.RecordKey
|
|
||||||
Recs []*models.RecordConfig
|
|
||||||
}
|
|
||||||
|
|
||||||
func groupbyRSet(recs models.Records, origin string) []recset {
|
// if len(recs) == 0 {
|
||||||
|
// return nil
|
||||||
|
// }
|
||||||
|
|
||||||
if len(recs) == 0 {
|
// // Sort the NameFQDN to a consistent order. The actual sort methodology
|
||||||
return nil
|
// // 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
|
// var result []recset
|
||||||
// doesn't matter as long as equal values are adjacent.
|
// var acc []*models.RecordConfig
|
||||||
// Use the PrettySort ordering so that the records are extra pretty.
|
|
||||||
pretty := prettyzone.PrettySort(recs, origin, 0, nil)
|
|
||||||
recs = pretty.Records
|
|
||||||
|
|
||||||
var result []recset
|
// // Do the first element
|
||||||
var acc []*models.RecordConfig
|
// prevkey := recs[0].Key()
|
||||||
|
// acc = append(acc, recs[0])
|
||||||
|
|
||||||
// Do the first element
|
// for i := 1; i < len(recs); i++ {
|
||||||
prevkey := recs[0].Key()
|
// curkey := recs[i].Key()
|
||||||
acc = append(acc, recs[0])
|
// 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++ {
|
// return result
|
||||||
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
|
|
||||||
}
|
|
||||||
|
@ -1,51 +1,32 @@
|
|||||||
package diff2
|
package diff2
|
||||||
|
|
||||||
import (
|
// func makeRecSet(recs ...*models.RecordConfig) *recset {
|
||||||
"reflect"
|
// result := recset{}
|
||||||
"testing"
|
// 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 {
|
// wwwa1 := makeRec("www", "A", "1.1.1.1")
|
||||||
origin := "f.com"
|
// wwwa2 := makeRec("www", "A", "2.2.2.2")
|
||||||
r := models.RecordConfig{TTL: 300}
|
// zzza1 := makeRec("zzz", "A", "1.1.0.0")
|
||||||
r.SetLabel(label, origin)
|
// zzza2 := makeRec("zzz", "A", "2.2.0.0")
|
||||||
r.PopulateFromString(rtype, content, origin)
|
// wwwmx1 := makeRec("www", "MX", "1 mx1.foo.com.")
|
||||||
return &r
|
// wwwmx2 := makeRec("www", "MX", "2 mx2.foo.com.")
|
||||||
}
|
// zzzmx1 := makeRec("zzz", "MX", "1 mx.foo.com.")
|
||||||
func makeRecTTL(label, rtype, content string, ttl uint32) *models.RecordConfig {
|
// orig := models.Records{wwwa1, wwwa2, zzza1, zzza2, wwwmx1, wwwmx2, zzzmx1}
|
||||||
r := makeRec(label, rtype, content)
|
// wantResult := []recset{
|
||||||
r.TTL = ttl
|
// *makeRecSet(wwwa1, wwwa2),
|
||||||
return r
|
// *makeRecSet(wwwmx1, wwwmx2),
|
||||||
}
|
// *makeRecSet(zzza1, zzza2),
|
||||||
func makeRecSet(recs ...*models.RecordConfig) *recset {
|
// *makeRecSet(zzzmx1),
|
||||||
result := recset{}
|
// }
|
||||||
result.Key = recs[0].Key()
|
|
||||||
result.Recs = append(result.Recs, recs...)
|
|
||||||
return &result
|
|
||||||
}
|
|
||||||
|
|
||||||
func Test_groupbyRSet(t *testing.T) {
|
// t.Run("afew", func(t *testing.T) {
|
||||||
|
// if gotResult := groupbyRSet(orig, "f.com"); !reflect.DeepEqual(gotResult, wantResult) {
|
||||||
wwwa1 := makeRec("www", "A", "1.1.1.1")
|
// t.Errorf("groupbyRSet() = %v, want %v", gotResult, wantResult)
|
||||||
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)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user