diff options
Diffstat (limited to 'internal/behavior/yml_test.go')
| -rw-r--r-- | internal/behavior/yml_test.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/internal/behavior/yml_test.go b/internal/behavior/yml_test.go index 9452e9e..82acb19 100644 --- a/internal/behavior/yml_test.go +++ b/internal/behavior/yml_test.go @@ -27,3 +27,38 @@ func TestWalkYAMLDirIncludesYml(t *testing.T) { 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") + } +} |
