package conditions import ( "strings" "testing" "github.com/novox/mesh-controller/internal/outward" ) // **A summary the operator's channel would withhold is said in words, and kept whole in the evidence** // (novox/hq issue 277, ADR 0234 ยง6): the condition that carried a resolver's address reached the // operator as "its words are withheld" instead of the alert. func TestASummaryCarryingAnAddressIsSaidInWordsAndKeptInTheEvidence(t *testing.T) { k, _, _, _ := keeper(t) before := Unsayable var told []string Unsayable = func(o Observation, field string, r outward.Refusal) { told = append(told, field+": "+r.What) } t.Cleanup(func() { Unsayable = before }) raw := "AAAA for anchor.internal: no answer from 10.77.0.1: read udp 10.77.0.3:41234->10.77.0.1:53: i/o timeout" c, err := k.Observe(t.Context(), Observation{Scope: ScopeSeat, ID: "mesh-dns-resolver.anchor", Token: "wrong", Kind: "resolver-wrong", Machine: "anchor", Severity: Urgent, Source: "D2", Summary: "the mesh's resolver on anchor does not answer: " + raw}) if err != nil { t.Fatal(err) } if r, ok := outward.Check(c.Summary, "anchor"); !ok { t.Fatalf("the summary kept is still withheld (%s): %q", r, c.Summary) } if !strings.HasPrefix(c.Summary, "the mesh's resolver on anchor does not answer: ") { t.Errorf("the summary's words were not kept: %q", c.Summary) } if !strings.Contains(c.Evidence[0].Said, raw) { t.Errorf("the evidence lost what the summary carried: %q", c.Evidence[0].Said) } if len(told) != 1 || !strings.HasPrefix(told[0], "summary") { t.Errorf("the producer was not named to the test: %v", told) } // A summary that may leave is kept as it is said, machine names and all. ok, err := k.Observe(t.Context(), Observation{Scope: ScopeMachine, ID: "anchor", Kind: "silent", Machine: "anchor", Severity: Warning, Source: "S1", Summary: "anchor has not been heard from since 12:00 UTC (bound 3m0s)"}) if err != nil || ok.Summary != "anchor has not been heard from since 12:00 UTC (bound 3m0s)" { t.Fatalf("%q %v", ok.Summary, err) } }