test(11-07): cover lighthouse realtime and the Centrifugo driver

- lighthouse: TestSuppression (Widget silenced, Gadget not, nesting,
  stale outer ctx), TestBulkEmitsOnce, TestBroadcastEdges (zero-key batch,
  update actor, id-only delete, method contract, multi-channel, savepoint),
  TestBroadcastPublishFailure, TestFromSelectsDriver, TestMountSurfaces,
  TestRegistry under -race, drivers, args JSON, Bind (coverage 91.7%)
- centrifugo: TestTokenClaims, TestTokenHandler, TestClientRequests,
  TestClientLoadConfig and a TestProxy table porting the WinterCMS WS-005,
  WS-007 and WS-013 cases (coverage 92.4%)
This commit is contained in:
Jakub Zych
2026-09-30 14:21:03 +02:00
parent 35ac96d664
commit 33194a1f98
9 changed files with 1593 additions and 33 deletions

View File

@@ -76,9 +76,22 @@ func TestFormatChannels(t *testing.T) {
if got := FormatChannels("", []string{"Collection:5"}); !reflect.DeepEqual(got, []string{"collection:5"}) {
t.Fatalf("no namespace = %v", got)
}
// PHP treats the namespace "0" as empty; the prefix is applied once.
if got := FormatChannels("0", []string{"Room:1"}); !reflect.DeepEqual(got, []string{"room:1"}) {
t.Fatalf("namespace 0 = %v", got)
}
if got := FormatChannels("acme", []string{"ACME:room:1", "acme:acme:x"}); !reflect.DeepEqual(got, []string{"acme:room:1", "acme:acme:x"}) {
t.Fatalf("prefix once = %v", got)
}
if got := FormatChannels("acme", nil); len(got) != 0 {
t.Fatalf("nil channels = %v", got)
}
}
func TestClientID(t *testing.T) {
if ClientID(nil) != "" || ClientID(WithClientID(nil, "c-0")) != "c-0" {
t.Fatal("nil ctx handling")
}
if ClientID(context.Background()) != "" {
t.Fatal("empty ctx has a client id")
}
@@ -86,35 +99,3 @@ func TestClientID(t *testing.T) {
t.Fatalf("ClientID = %q", got)
}
}
func TestRegistry(t *testing.T) {
r := NewRegistry()
allow := AuthorizerFunc(func(context.Context, uint, string) Result { return Allowed(nil) })
if err := r.Register("b", allow); err != nil {
t.Fatal(err)
}
if err := r.Register("a", allow); err != nil {
t.Fatal(err)
}
for _, bad := range []struct {
ns string
a Authorizer
}{{"", allow}, {"x:y", allow}, {"c", nil}, {"a", allow}} {
if err := r.Register(bad.ns, bad.a); err == nil {
t.Errorf("Register(%q) accepted", bad.ns)
}
}
if got := r.Namespaces(); !reflect.DeepEqual(got, []string{"a", "b"}) {
t.Fatalf("Namespaces = %v", got)
}
if _, ok := r.Get("A"); ok {
t.Fatal("lookup is not case-sensitive")
}
if a, ok := r.Get("a"); !ok || !a.Authorize(context.Background(), 1, "a:1").Allowed {
t.Fatal("Get(a) failed")
}
d := Denied("why")
if d.Allowed || d.Reason() != "why" {
t.Fatalf("Denied = %+v", d)
}
}