//go:build integration package link import ( "fmt" "os" "strings" "testing" "time" "github.com/nats-io/nats.go" "github.com/novox/mesh-controller/internal/testbus" ) func TestNatsARefusedQuestionIsSaidAtOnce(t *testing.T) { url := os.Getenv("MESH_TEST_NATS_REFUSING") if url == "" { t.Skip("MESH_TEST_NATS_REFUSING unset: a server whose user may not publish mesh.seat.>") } conn, err := nats.Connect(url) if err != nil { t.Fatal(err) } defer conn.Close() started := time.Now() _, err = AskSeatTool(t.Context(), conn, "node-intrusion-prevention", "banned", "anchor", map[string]any{}, 10*time.Second) if err == nil || !strings.Contains(err.Error(), "the bus refused") { t.Fatalf("answered %v", err) } if took := time.Since(started); took > 3*time.Second { t.Fatalf("a refusal took %s to be known", took) } } func TestNatsARefusalReachesItsWaiter(t *testing.T) { url := testbus.URL(t) conn, err := nats.Connect(url) if err != nil { t.Fatal(err) } defer conn.Close() mine, stop := refusalsOf(conn, "mesh.seat.s.tool.v.anchor") defer stop() other, stopOther := refusalsOf(conn, "mesh.seat.s.tool.v.laptop") defer stopOther() conn.ErrorHandler()(conn, nil, fmt.Errorf("%w: Permissions Violation for Publish to %q", nats.ErrPermissionViolation, "mesh.seat.s.tool.v.anchor")) select { case <-mine: case <-time.After(time.Second): t.Fatal("the waiter was not told") } select { case <-other: t.Fatal("another subject's waiter was told") default: } }