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
|
package validate
import (
"path/filepath"
"testing"
"thehouseoficarus/internal/behavior"
)
// TestDropTableCycleIsAnError: a self/mutual drop-table reference must be a
// startup ERROR, because ResolveDrop recurses and would otherwise overflow the
// goroutine stack at runtime.
func TestDropTableCycleIsAnError(t *testing.T) {
dir := t.TempDir()
writeFile(t, filepath.Join(dir, "drops", "a.yaml"), "id: a\ndrops:\n - table: b\n weight: 1\n")
writeFile(t, filepath.Join(dir, "drops", "b.yaml"), "id: b\ndrops:\n - table: a\n weight: 1\n")
behavior.ClearDropIndex()
defer behavior.ClearDropIndex()
issues := validateDropTableCycles(Source{DataDir: dir}, dropTableIDSet(dir))
if len(issues) == 0 {
t.Fatal("expected a cycle error for a <-> b")
}
for _, issue := range issues {
if issue.Level != "ERROR" {
t.Fatalf("cycle issue must be ERROR: %+v", issue)
}
}
}
// TestNonNumericRoomFilenameIsAnError: the room index only accepts numeric
// stems, so a backup file must be flagged instead of silently ignored.
func TestNonNumericRoomFilenameIsAnError(t *testing.T) {
dir := t.TempDir()
writeFile(t, filepath.Join(dir, "rooms", "1001.yaml"), "id: 1001\nname: real\n")
writeFile(t, filepath.Join(dir, "rooms", "1001_copy.yaml"), "id: 1001\nname: copy\n")
issues := validateRoomFilenames(dir)
if len(issues) != 1 {
t.Fatalf("expected exactly one filename issue, got %+v", issues)
}
if issues[0].Level != "ERROR" {
t.Fatalf("expected ERROR, got %+v", issues[0])
}
}
|