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], ) } } }