aboutsummaryrefslogtreecommitdiff
path: root/internal/casino/manager_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/casino/manager_test.go')
-rw-r--r--internal/casino/manager_test.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/internal/casino/manager_test.go b/internal/casino/manager_test.go
index b037efa..6601b52 100644
--- a/internal/casino/manager_test.go
+++ b/internal/casino/manager_test.go
@@ -127,3 +127,37 @@ func eventText(events []Event) string {
}
return ""
}
+
+// TestRekeyRoomsKeepsTableIdentityAndWhitespaceIDs: a room rekey must move
+// the manager key and the shared table identity together, and must not
+// truncate a table ID that legally contains whitespace.
+func TestRekeyRoomsKeepsTableIdentityAndWhitespaceIDs(t *testing.T) {
+ m := NewManager(1)
+ const id = "high stakes bj"
+ cfg := TableConfig{ID: id, Game: GameBlackjack}
+ m.Join(1, cfg, "alice")
+ table := m.Table(1, id)
+ if table == nil {
+ t.Fatal("table was not created for a valid whitespace-containing ID")
+ }
+ m.RekeyRooms(map[int]int{1: 12})
+ if m.Table(1, id) != nil {
+ t.Fatal("table left under the old room key")
+ }
+ moved := m.Table(12, id)
+ if moved != table {
+ t.Fatalf("rekey lost the table (or truncated its key): Table(12, %q)=%p want %p", id, moved, table)
+ }
+ if moved.RoomID != 12 {
+ t.Fatalf("moved table RoomID = %d, want 12", moved.RoomID)
+ }
+ // The game shares the table's base, so events must route to the new room.
+ events := moved.join("bob")
+ if len(events) == 0 || events[0].RoomID != 12 {
+ t.Fatalf("post-rekey events route to the wrong room: %+v", events)
+ }
+ // The old, truncated key must not have been created.
+ if m.Table(12, "high") != nil {
+ t.Fatal("rekey created a truncated table key from a whitespace ID")
+ }
+}