TestKillUserSessionsFansOut: the kill endpoint kills locally AND sums peer counts, reporting cluster-wide totals.
(t *testing.T)
| 34 | // TestKillUserSessionsFansOut: the kill endpoint kills locally AND sums peer |
| 35 | // counts, reporting cluster-wide totals. |
| 36 | func TestKillUserSessionsFansOut(t *testing.T) { |
| 37 | local := &fakeLiveInfo{killedPerUser: 2} |
| 38 | peerBody, _ := json.Marshal(map[string]any{"killed": 3}) |
| 39 | fetcher := &fakePeerFetcher{postByPath: map[string][][]byte{ |
| 40 | "/api/v1/orgs/acme/users/bob/kill": {peerBody}, |
| 41 | }} |
| 42 | r := killSwitchRouter(local, fetcher, nil) |
| 43 | |
| 44 | code, body := doPost(t, r, "/api/v1/orgs/acme/users/bob/kill") |
| 45 | if code != http.StatusOK { |
| 46 | t.Fatalf("expected 200, got %d (%v)", code, body) |
| 47 | } |
| 48 | if got := body["killed"]; got != float64(5) { |
| 49 | t.Fatalf("killed = %v, want 5 (2 local + 3 peer)", got) |
| 50 | } |
| 51 | if got := body["cp_total"]; got != float64(2) { |
| 52 | t.Fatalf("cp_total = %v, want 2", got) |
| 53 | } |
| 54 | if len(local.killUserCalls) != 1 || local.killUserCalls[0] != (killUserCall{"acme", "bob"}) { |
| 55 | t.Fatalf("local KillUserSessions calls = %+v, want one (acme,bob)", local.killUserCalls) |
| 56 | } |
| 57 | if fetcher.postCallCount() != 1 { |
| 58 | t.Fatalf("expected one POST fan-out, got %d", fetcher.postCallCount()) |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | // TestKillUserSessionsScopeLocal: a peer (scope=local) call kills only locally |
| 63 | // and must NOT fan out again (recursion guard). |
nothing calls this directly
no test coverage detected