Keep options in a fixed order, and say which block a diff hunk is in
Options of a block (server options, a view, a zone) are listed and
written grouped by topic, alphabetical within a group, so the same
option is in the same place everywhere. Top-level statements keep the
order they were added in.
named.conf diffs add the enclosing blocks to each hunk header, like
git's function context: @@ -50,6 +49,8 @@ view "internal" {.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
73d97ecc0a
commit
b097e10bef
9 files changed
+326
-3
No files matched your search
@@ -0,0 +1,40 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestScopedOptionsOrder(t *testing.T) {
|
||||
s := NewState()
|
||||
add := func(scope string, names ...string) {
|
||||
for i, n := range names {
|
||||
id := int64(len(s.Options) + 1)
|
||||
s.Options[id] = &Option{ID: id, Scope: scope, Name: n, Position: i}
|
||||
}
|
||||
}
|
||||
// Added in an arbitrary order; listen-on twice.
|
||||
add(ScopeView, "zzz-unknown", "forwarders", "listen-on", "recursion", "dnssec-validation", "aaa-unknown", "allow-query", "forward", "directory", "listen-on", "allow-transfer")
|
||||
var got []string
|
||||
for _, o := range s.ScopedOptions(ScopeView, 0) {
|
||||
got = append(got, o.Name)
|
||||
}
|
||||
want := "directory listen-on listen-on allow-query forward forwarders recursion dnssec-validation allow-transfer aaa-unknown zzz-unknown"
|
||||
if strings.Join(got, " ") != want {
|
||||
t.Errorf("order:\n got %s\nwant %s", strings.Join(got, " "), want)
|
||||
}
|
||||
// An option given twice keeps the order it was added in.
|
||||
l := s.ScopedOptions(ScopeView, 0)
|
||||
if l[1].Position > l[2].Position {
|
||||
t.Error("repeated listen-on swapped")
|
||||
}
|
||||
// Top-level statements stay as entered.
|
||||
add(ScopeTopLevel, "logging", "acl", "key")
|
||||
got = nil
|
||||
for _, o := range s.ScopedOptions(ScopeTopLevel, 0) {
|
||||
got = append(got, o.Name)
|
||||
}
|
||||
if strings.Join(got, " ") != "logging acl key" {
|
||||
t.Errorf("top level: %v", got)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user