mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
* Stable comparison of metadata (#239) Iterating over a map in Go never produces twice the same ordering. Thus when comparing two metadata map with more than one key, the `differ` is always finding differences. To properly compare records metadata, we need to iterate the maps in a deterministic way. Signed-off-by: Brice Figureau <brice@daysofwonder.com> * Support for Route53 ALIAS record type (#239) Route53 ALIAS doesn't behave like a regular ALIAS, and is much more limited as its target can only be some specific AWS resources or another record in the same zone. According to #239, this change adds a new directive R53_ALIAS which implements this specific alias. This record type can only be used with the Route53 provider. This directive usage looks like this: ```js D("example.com", REGISTRAR, DnsProvider("ROUTE53"), R53_ALIAS("foo1", "A", "bar") // record in same zone R53_ALIAS("foo2", "A", "blahblah.elasticloadbalancing.us-west-1.amazonaws.com", R53_ZONE('Z368ELLRRE2KJ0')) // ELB in us-west-1 ``` Unfortunately, Route53 requires indicating the hosted zone id where the target is defined (those are listed in AWS documentation, see the R53_ALIAS documentation for links).
This commit is contained in:
committed by
Tom Limoncelli
parent
2fc55dfdc4
commit
7b8d608019
@@ -44,7 +44,16 @@ type differ struct {
|
||||
func (d *differ) content(r *models.RecordConfig) string {
|
||||
content := fmt.Sprintf("%v ttl=%d", r.Content(), r.TTL)
|
||||
for _, f := range d.extraValues {
|
||||
for k, v := range f(r) {
|
||||
// sort the extra values map keys to perform a deterministic
|
||||
// comparison since Golang maps iteration order is not guaranteed
|
||||
valueMap := f(r)
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
@@ -128,6 +128,26 @@ func TestMetaChange(t *testing.T) {
|
||||
checkLengths(t, existing, desired, 0, 0, 0, 1, getMeta)
|
||||
}
|
||||
|
||||
func TestMetaOrdering(t *testing.T) {
|
||||
existing := []*models.RecordConfig{
|
||||
myRecord("www MX 1 1.1.1.1"),
|
||||
}
|
||||
desired := []*models.RecordConfig{
|
||||
myRecord("www MX 1 1.1.1.1"),
|
||||
}
|
||||
existing[0].Metadata["k"] = "aa"
|
||||
existing[0].Metadata["x"] = "cc"
|
||||
desired[0].Metadata["k"] = "aa"
|
||||
desired[0].Metadata["x"] = "cc"
|
||||
checkLengths(t, existing, desired, 1, 0, 0, 0)
|
||||
getMeta := func(r *models.RecordConfig) map[string]string {
|
||||
return map[string]string{
|
||||
"k": r.Metadata["k"],
|
||||
}
|
||||
}
|
||||
checkLengths(t, existing, desired, 1, 0, 0, 0, getMeta)
|
||||
}
|
||||
|
||||
func checkLengths(t *testing.T, existing, desired []*models.RecordConfig, unCount, createCount, delCount, modCount int, valFuncs ...func(*models.RecordConfig) map[string]string) (un, cre, del, mod Changeset) {
|
||||
return checkLengthsWithKeepUnknown(t, existing, desired, unCount, createCount, delCount, modCount, false, valFuncs...)
|
||||
}
|
||||
|
Reference in New Issue
Block a user