1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
package game
import (
"os"
"path/filepath"
"testing"
"thehouseoficarus/internal/player"
)
// TestRoomAddMobReconcilesLiveState: the in-game room editor used to write the
// YAML but leave the live room untouched, so an added mob did not appear until
// the room was re-entered or the server restarted. A successful room edit must
// reconcile runtime state like the admin editor does.
func TestRoomAddMobReconcilesLiveState(t *testing.T) {
dir := t.TempDir()
for _, sub := range []string{"mobs", "rooms"} {
if err := os.MkdirAll(filepath.Join(dir, sub), 0755); err != nil {
t.Fatal(err)
}
}
if err := os.WriteFile(filepath.Join(dir, "mobs", "rat.yaml"),
[]byte("id: rat\nname: giant rat\ndescription: A scruffy rat.\ncombat:\n stats:\n hp: 5\n"), 0644); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(dir, "rooms", "1.yaml"),
[]byte("name: Central\n"), 0644); err != nil {
t.Fatal(err)
}
g := newRemoveGame(t, dir)
sess := newRemoveSession(player.New("alice"))
sess.Player.RoomID = 1
if got := len(g.MobStore.MobsInRoom(1)); got != 0 {
t.Fatalf("room should start with no mobs, got %d", got)
}
g.roomAddMob(sess, []string{"rat"})
if got := len(g.MobStore.MobsInRoom(1)); got != 1 {
t.Fatalf("room addmob did not reconcile live state: %d mobs in room, want 1", got)
}
for _, m := range g.MobStore.MobsInRoom(1) {
if m.DefID != "rat" {
t.Fatalf("seeded mob DefID = %q, want rat", m.DefID)
}
}
}
|