refactor: path resolution to separate file
This commit is contained in:
@@ -104,76 +104,6 @@ func TestRunRecord(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestRunRecordWithExplicitTestDirPath(t *testing.T) {
|
||||
addFakeRecordDependencies(t, "script", "bwrap", "bash")
|
||||
|
||||
root := t.TempDir()
|
||||
wantDir := filepath.Join(root, "e2e")
|
||||
|
||||
withWorkingDir(t, root, func() {
|
||||
initStdout, initStderr := captureOutput(t, func() {
|
||||
if got := Run([]string{"init"}); got != 0 {
|
||||
t.Fatalf("Run() code = %d, want %d", got, 0)
|
||||
}
|
||||
})
|
||||
if initStdout != prefixed("Done initialising...\n") {
|
||||
t.Fatalf("stdout = %q, want %q", initStdout, prefixed("Done initialising...\n"))
|
||||
}
|
||||
if initStderr != "" {
|
||||
t.Fatalf("stderr = %q, want empty", initStderr)
|
||||
}
|
||||
|
||||
withStdin(t, "y\n", func() {})
|
||||
stdout, stderr := captureOutput(t, func() {
|
||||
if got := Run([]string{"record", filepath.Join("e2e", "suite", "spec")}); got != 0 {
|
||||
t.Fatalf("Run() code = %d, want %d", got, 0)
|
||||
}
|
||||
})
|
||||
|
||||
createdPath := filepath.Join(wantDir, "suite", "spec")
|
||||
if stdout != prefixed(createdPath+"\n") {
|
||||
t.Fatalf("stdout = %q, want %q", stdout, prefixed(createdPath+"\n"))
|
||||
}
|
||||
if !strings.Contains(stderr, "Save recording?") {
|
||||
t.Fatalf("stderr = %q, want save prompt", stderr)
|
||||
}
|
||||
|
||||
for _, name := range []string{"in", "out"} {
|
||||
if _, err := os.Stat(filepath.Join(createdPath, name)); err != nil {
|
||||
t.Fatalf("Stat(%q) error = %v", filepath.Join(createdPath, name), err)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestRunRecordRejectsAbsolutePathOutsideTestDir(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
wantDir := filepath.Join(root, "e2e")
|
||||
if err := os.MkdirAll(wantDir, 0o755); err != nil {
|
||||
t.Fatalf("MkdirAll() error = %v", err)
|
||||
}
|
||||
writeFile(t, filepath.Join(root, "miro.toml"), validConfigContent("e2e"))
|
||||
|
||||
outside := filepath.Join(root, "outside", "spec")
|
||||
withWorkingDir(t, root, func() {
|
||||
stdout, stderr := captureOutput(t, func() {
|
||||
if got := Run([]string{"record", outside}); got != 1 {
|
||||
t.Fatalf("Run() code = %d, want %d", got, 1)
|
||||
}
|
||||
})
|
||||
|
||||
if stdout != "" {
|
||||
t.Fatalf("stdout = %q, want empty", stdout)
|
||||
}
|
||||
if !strings.Contains(stderr, "must be inside test directory") {
|
||||
t.Fatalf("stderr = %q, want test directory error", stderr)
|
||||
}
|
||||
if _, err := os.Stat(outside); !os.IsNotExist(err) {
|
||||
t.Fatalf("Stat(%q) error = %v, want not exists", outside, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestRunInitFailsWhenDependenciesMissing(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
t.Setenv("PATH", "")
|
||||
|
||||
Reference in New Issue
Block a user