feat: record path handlingt to strip testDir prefix

This commit is contained in:
2026-03-18 10:22:43 +00:00
parent 9cf3ed6a5c
commit aecbefa7ba
3 changed files with 166 additions and 1 deletions
+75
View File
@@ -0,0 +1,75 @@
package miro
import (
"os"
"path/filepath"
"testing"
)
func TestRecordCreatesRelativePath(t *testing.T) {
root := t.TempDir()
testDir := filepath.Join(root, "e2e")
mustMkdirAll(t, testDir)
got := withWorkingDir(t, root, func() string {
path, err := Record(filepath.Join("a", "b", "c") + string(os.PathSeparator))
if err != nil {
t.Fatalf("Record() error = %v", err)
}
return path
})
want := filepath.Join(testDir, "a", "b", "c")
if got != want {
t.Fatalf("Record() = %q, want %q", got, want)
}
info, err := os.Stat(want)
if err != nil {
t.Fatalf("Stat() error = %v", err)
}
if !info.IsDir() {
t.Fatalf("created path %q is not a directory", want)
}
}
func TestRecordStripsExplicitTestDirPrefix(t *testing.T) {
root := t.TempDir()
testDir := filepath.Join(root, "e2e")
mustMkdirAll(t, testDir)
got := withWorkingDir(t, root, func() string {
path, err := Record(filepath.Join("e2e", "a", "b", "c"))
if err != nil {
t.Fatalf("Record() error = %v", err)
}
return path
})
want := filepath.Join(testDir, "a", "b", "c")
if got != want {
t.Fatalf("Record() = %q, want %q", got, want)
}
if _, err := os.Stat(want); err != nil {
t.Fatalf("Stat() error = %v", err)
}
}
func TestRecordRejectsAbsolutePathOutsideTestDir(t *testing.T) {
root := t.TempDir()
mustMkdirAll(t, filepath.Join(root, "e2e"))
outside := filepath.Join(root, "outside", "a", "b", "c")
err := withWorkingDir(t, root, func() error {
_, err := Record(outside)
return err
})
if err == nil {
t.Fatal("Record() error = nil, want error")
}
if _, statErr := os.Stat(outside); !os.IsNotExist(statErr) {
t.Fatalf("Stat(%q) error = %v, want not exists", outside, statErr)
}
}