Compare views rebuilt: from the zone's view, in sections, one line per record

The Compare views tab and jarl zone diff compare a zone with the same zone in other views from the view you're on: a summary per view, what is answered differently (Use this everywhere), the names only some views have (Add to VIEW), and how many are the same. One name can be compared (jarl zone diff ZONE NAME [TYPE], a Compare button per record). The CLI prints one line per record, cut to the terminal (--wide shows it whole); the web UI cuts long values with the whole one on hover. GET /zones/{zone}/compare returns these sections, with ?with, ?name and ?type.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
adamandClaude Opus 5.5 committed 2026-10-13 10:55:57 +01:00
1 parent ec16de875d
commit b1719ce362
12 files changed
+656 -146

No files matched your search

+45
View File
@@ -341,3 +341,48 @@ func TestCompareZones(t *testing.T) {
t.Errorf("sharing the shared version: external %q", v)
}
}
func TestCompareReport(t *testing.T) {
env := linkedEnv(t)
env.submit(env.admin, NewRequest(OpZoneCreate, 0, ZoneInput{Name: model.Ptr("example.com"), View: model.Ptr("external"), LinkWith: "internal"}))
env.submit(env.admin,
NewRequest(OpRRSetReplace, 0, RRSetInput{Zone: "example.com", View: "external", Name: "www", Type: "A", Data: []string{"203.0.113.10"}, Local: model.Ptr(true)}),
NewRequest(OpRecordCreate, 0, RecordInput{Zone: "example.com", View: "internal", Name: model.Ptr("nas"), Type: model.Ptr("A"), Data: model.Ptr("10.0.0.20"), Local: model.Ptr(true)}),
NewRequest(OpRecordCreate, 0, RecordInput{Zone: "example.com", View: "internal", Name: model.Ptr("printer"), Type: model.Ptr("A"), Data: model.Ptr("10.0.0.30"), Local: model.Ptr(true)}),
NewRequest(OpRecordCreate, 0, RecordInput{Zone: "example.com", View: "external", Name: model.Ptr("shop"), Type: model.Ptr("CNAME"), Data: model.Ptr("shops.example.net."), Local: model.Ptr(true)}))
st := env.state()
zones := []*model.Zone{st.FindZone("example.com.", st.ViewByName("internal").ID), st.FindZone("example.com.", st.ViewByName("external").ID)}
rep := Compare(st, zones, CompareFilter{})
if rep.Base != "internal" || !rep.Linked || !slices.Equal(rep.Views, []string{"internal", "external"}) {
t.Errorf("report %+v", rep)
}
if s := rep.Summary[0]; s.View != "external" || s.Different != 1 || s.OnlyBase != 2 || s.OnlyOther != 1 || s.Same != 2 {
t.Errorf("summary %+v", s)
}
if len(rep.Different) != 1 || rep.Different[0].Name != "www" {
t.Errorf("different %+v", rep.Different)
}
var only []string
for _, o := range rep.Only {
var names []string
for _, r := range o.Rows {
names = append(names, r.Name)
}
only = append(only, strings.Join(o.Views, "+")+": "+strings.Join(names, ","))
}
want(t, "only", only, "internal: nas,printer", "external: shop")
if rep.Same != 2 || rep.SameRows != nil {
t.Errorf("same %d, rows %v", rep.Same, rep.SameRows)
}
// One name: just its rows, the same ones included.
rep = Compare(st, zones, CompareFilter{Name: "www"})
if len(rep.Different) != 1 || len(rep.Only) != 0 || len(rep.SameRows) != 0 {
t.Errorf("www: %+v", rep)
}
rep = Compare(st, zones, CompareFilter{Name: "mail.example.com.", Type: "A"})
if len(rep.SameRows) != 1 || rep.SameRows[0].Name != "mail" || len(rep.Different)+len(rep.Only) != 0 {
t.Errorf("mail A: %+v", rep)
}
}