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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
package behavior
import (
"os"
"path/filepath"
"testing"
)
// Regression: WalkYAMLDir only matched .yaml, so a .yml trigger file loaded
// and fired at runtime while every validation pass ignored it.
func TestWalkYAMLDirIncludesYml(t *testing.T) {
dir := t.TempDir()
if err := os.WriteFile(filepath.Join(dir, "a.yaml"), []byte("x: 1"), 0644); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(dir, "b.yml"), []byte("x: 2"), 0644); err != nil {
t.Fatal(err)
}
ids := map[string]bool{}
if err := WalkYAMLDir(dir, func(path, id string, data []byte) error {
ids[id] = true
return nil
}); err != nil {
t.Fatal(err)
}
if !ids["a"] || !ids["b"] {
t.Fatalf("WalkYAMLDir ids = %v, want both a and b", ids)
}
}
func TestBuildPathIndexIncludesYml(t *testing.T) {
dir := t.TempDir()
if err := os.WriteFile(filepath.Join(dir, "a.yaml"), []byte("x: 1"), 0644); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(dir, "b.yml"), []byte("x: 2"), 0644); err != nil {
t.Fatal(err)
}
idx := BuildPathIndex(dir)
if idx["a"] == "" || idx["b"] == "" {
t.Fatalf("BuildPathIndex = %v, want both a and b", idx)
}
}
func TestBuildRoomIndexIncludesYml(t *testing.T) {
dir := t.TempDir()
if err := os.WriteFile(filepath.Join(dir, "1001.yaml"), []byte("name: a"), 0644); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(dir, "1002.yml"), []byte("name: b"), 0644); err != nil {
t.Fatal(err)
}
idx := BuildRoomIndex(dir)
if idx[1001] == "" || idx[1002] == "" {
t.Fatalf("BuildRoomIndex = %v, want both 1001 and 1002", idx)
}
}
func TestLoadDropTableRejectsPathEscape(t *testing.T) {
dataDir := t.TempDir()
if _, err := LoadDropTable(dataDir, "../../../etc/passwd"); err == nil {
t.Fatal("accepted a path-escaping drop table id")
}
}
|