Files
Felis/internal/operator/prober_internal_test.go
T
flyemoji 98739044a5 fix(operator): populate Status.Players from an RCON list probe
A Running, ready server always reported 0/0 players: markRunningReady
never wrote Status.Players, and markStopped only cleared it. The panel
therefore showed an empty tally for live servers.

Extend the readiness probe to also sample the player count. Prober.Probe
now returns a PlayerCount{Online, Max}: RconProber still gates readiness
on Dial+auth, then runs a best-effort `list` and parses the vanilla
reply ("There are N of a max of M players online"). A failed or
unparseable tally is swallowed (0/0) so it never blocks readiness. The
reconciler threads the count into markRunningReady, which writes
Status.Players; markStopped still resets it to zero.
2026-06-30 20:04:46 +09:00

55 lines
1.2 KiB
Go

package operator
import "testing"
func TestParseListReply(t *testing.T) {
cases := []struct {
name string
reply string
want PlayerCount
wantOK bool
}{
{
name: "empty server",
reply: "There are 0 of a max of 20 players online:",
want: PlayerCount{Online: 0, Max: 20},
wantOK: true,
},
{
name: "with player names",
reply: "There are 3 of a max of 20 players online: alice, bob, carol",
want: PlayerCount{Online: 3, Max: 20},
wantOK: true,
},
{
name: "full server",
reply: "There are 20 of a max of 20 players online: ...",
want: PlayerCount{Online: 20, Max: 20},
wantOK: true,
},
{
name: "unrecognized reply yields no sample",
reply: "Unknown command. Try /help for a list of commands.",
want: PlayerCount{},
wantOK: false,
},
{
name: "empty reply yields no sample",
reply: "",
want: PlayerCount{},
wantOK: false,
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
got, ok := parseListReply(tc.reply)
if ok != tc.wantOK {
t.Fatalf("ok = %v, want %v", ok, tc.wantOK)
}
if got != tc.want {
t.Errorf("count = %+v, want %+v", got, tc.want)
}
})
}
}