package main import ( "strings" "testing" "github.com/novox/mesh-controller/internal/broker" "github.com/novox/mesh-controller/internal/conditions" ) // A grant naming a module the tool runner carries composes nothing, and doctor says so in plain words, naming the // module, the stream and the remedy (novox/hq ADR 0376 ยง2). func TestAGrantThatComposesNothingIsSaid(t *testing.T) { records := broker.Records{Nodes: []string{"ace"}, Assigned: map[string][]broker.Declared{"ace": { {Module: broker.RuntimeModule}, {Module: "reader", Hears: []broker.Heard{{Stream: "MAIL", Emitter: "mesh-mail", Restricted: true, Filters: []string{"mesh.stream.mesh-mail.event.mail.mesh.>"}}}}, {Module: "mailer", RunsAs: "mailer", Hears: []broker.Heard{{Stream: "MAIL", Emitter: "mesh-mail", Restricted: true, Filters: []string{"mesh.stream.mesh-mail.event.mail.mesh.>"}}}}, }}} found := withheldObservations(broker.WithheldOf(records)) if len(found) != 1 { t.Fatalf("said %+v", found) } o := found[0] if o.Kind != kindGrantComposesNothing || o.Machine != "ace" || !strings.Contains(o.Summary, "reader on ace") || !strings.Contains(o.Summary, "MAIL") || !strings.Contains(o.Summary, "runs-as") { t.Fatalf("%+v", o) } w := plainWordings[kindGrantComposesNothing](o) if why, ok := conditions.PlainWords(w, "ace"); !ok { t.Fatalf("not plain: %s (%+v)", why, w) } registered := false for _, p := range probeRegistry { if p.ID == probeWithheldID && p.Kind == kindGrantComposesNothing && p.run != nil { registered = true } } if !registered { t.Fatal("doctor does not run the probe of a grant that composes nothing") } }