The names are the setting HUB_OWN_NAMES; with no setting the hub makes no call. The setting is NOT in the manifest yet. Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
55 lines
2.4 KiB
Go
55 lines
2.4 KiB
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
|
|
"gitea.dooplex.hu/admin/felhom-hub/internal/monitor"
|
|
"gitea.dooplex.hu/admin/felhom-hub/internal/notify"
|
|
)
|
|
|
|
// D85 (R-1379): the own-names check is a component with a seam; unit-green and never called is the inert-seam defect.
|
|
// Read from main.go: the names come from the HUB_OWN_NAMES setting (never a literal list in code), the real dial is
|
|
// handed in, the job runs on the daily scheduler under the name the ledger watches, and no setting means no job.
|
|
func TestD85_MainWiresTheOwnNamesCheck(t *testing.T) {
|
|
b, err := os.ReadFile("main.go")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
src := string(b)
|
|
for _, want := range []string{
|
|
`monitor.ParseOwnNames(os.Getenv("HUB_OWN_NAMES"))`,
|
|
`monitor.NewOwnNameChecker(names, monitor.DialCertEnd, dataStore.OSAlarmRaised, dataStore.SetOSAlarmRaised, hubEvent, logger)`,
|
|
`go scheduleDaily(ctx, ownNamesJob, "06:40", ownNames.CheckOnce, logger)`,
|
|
`"deadline-check", "offsite-key-audit", ownNamesJob)`,
|
|
} {
|
|
if strings.Count(src, want) != 1 {
|
|
t.Errorf("main.go: want exactly one %q, found %d", want, strings.Count(src, want))
|
|
}
|
|
}
|
|
// the list is configuration, not code: no public name of the hub is written in main.go
|
|
for _, name := range []string{"hub.felhom.eu", "iso.felhom.eu", "files.felhom.eu"} {
|
|
if strings.Contains(src, name) {
|
|
t.Errorf("main.go names %s in code — the list of own names must come from the setting", name)
|
|
}
|
|
}
|
|
// the job is started only inside the „names were given” branch
|
|
at, job := strings.Index(src, `if len(names) > 0 {`+"\n\t\t\townNames :="), strings.Index(src, `go scheduleDaily(ctx, ownNamesJob`)
|
|
if at < 0 || job < at {
|
|
t.Error("the own-names job is not started inside the branch that has names — an empty setting would start it")
|
|
}
|
|
}
|
|
|
|
// The three events are the operator's only, and each NAME has its own mail (not one per type per hour).
|
|
func TestD85_TheEventsAreOperatorOnlyAndPerName(t *testing.T) {
|
|
for _, typ := range []string{monitor.EventHubNameEndsSoon, monitor.EventHubNameUnreachable, monitor.EventHubNameReachable} {
|
|
if !notify.IsOperatorOnly(typ) {
|
|
t.Errorf("%s is not operator-only: a household could get a mail about the hub's own names", typ)
|
|
}
|
|
if !notify.HasPerSubjectCooldown(typ) {
|
|
t.Errorf("%s has no per-name cooldown: the second name of the same day would be suppressed and never told again", typ)
|
|
}
|
|
}
|
|
}
|