check / check (push) Successful in 1m9s
A Record Change notification printed the nameserver's whole old and new record sets in Go map syntax, and an Inconsistency notification the two nameservers' whole sets, so a one-address change had to be found by eye among kilobytes of unchanged TXT, CAA, MX and NS values. Both now list, in sorted order of type, only the record types whose values differ: a line naming the type, then each side's values separated by commas, or none when that side has no records of that type. The dashboard's Recent alerts shows the same text. Model: opus-5-5
67 lines
1.6 KiB
Go
67 lines
1.6 KiB
Go
package watcher_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"sneak.berlin/go/dnswatcher/internal/watcher"
|
|
)
|
|
|
|
// When one nameserver's A record changes and its TXT record does not,
|
|
// the record change and the inconsistency it starts name the A record
|
|
// alone, with its values written as plain text.
|
|
func TestChangeMessagesNameTheChangedType(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
// A nameserver's records: this A address and the same TXT record.
|
|
records := func(address string) map[string][]string {
|
|
return map[string][]string{
|
|
"A": {address},
|
|
"TXT": {"v=spf1 -all"},
|
|
}
|
|
}
|
|
|
|
before := hostnameState(map[string]map[string][]string{
|
|
nsA: records(ip1),
|
|
nsB: records(ip1),
|
|
})
|
|
after := hostnameState(map[string]map[string][]string{
|
|
nsA: records(ip1),
|
|
nsB: records(ip2),
|
|
})
|
|
|
|
// The hostname change detection uses only the notifier.
|
|
notifier := &mockNotifier{}
|
|
w := watcher.NewForTest(nil, nil, nil, nil, nil, notifier)
|
|
|
|
w.DetectHostnameChanges(t.Context(), host, before, after)
|
|
|
|
want := map[string]string{
|
|
"Record Change: " + host: `Hostname: www.example.net
|
|
Nameserver: b.ns.example.net.
|
|
Type: A
|
|
Old: 192.0.2.1
|
|
New: 192.0.2.2`,
|
|
"Inconsistency: " + host: `Hostname: www.example.net
|
|
Type: A
|
|
a.ns.example.net.: 192.0.2.1
|
|
b.ns.example.net.: 192.0.2.2`,
|
|
}
|
|
|
|
notifications := notifier.getNotifications()
|
|
if len(notifications) != len(want) {
|
|
t.Fatalf(
|
|
"sent %d notifications, want %d: %v",
|
|
len(notifications), len(want), notifications,
|
|
)
|
|
}
|
|
|
|
for _, n := range notifications {
|
|
if n.Message != want[n.Title] {
|
|
t.Errorf(
|
|
"%s message:\n%s\nwant:\n%s",
|
|
n.Title, n.Message, want[n.Title],
|
|
)
|
|
}
|
|
}
|
|
}
|