TestChdir changes the working directory to dir for the duration of the test. The original directory is restored via t.Cleanup. This enables tests to use LocalFileIO (which resolves relative paths under cwd) with temporary directories, keeping test artifacts out of the source tree. Not compatible wit
(t *testing.T, dir string)
| 93 | // with temporary directories, keeping test artifacts out of the source tree. |
| 94 | // Not compatible with t.Parallel() — os.Chdir is process-wide. |
| 95 | func TestChdir(t *testing.T, dir string) { |
| 96 | t.Helper() |
| 97 | orig, err := vfs.Getwd() |
| 98 | if err != nil { |
| 99 | t.Fatalf("Getwd: %v", err) |
| 100 | } |
| 101 | if err := os.Chdir(dir); err != nil { //nolint:forbidigo // no vfs.Chdir yet; test-only, process-wide chdir |
| 102 | t.Fatalf("Chdir(%s): %v", dir, err) |
| 103 | } |
| 104 | t.Cleanup(func() { os.Chdir(orig) }) //nolint:forbidigo // matching restore |
| 105 | } |
| 106 | |
| 107 | type testDefaultToken struct{} |
| 108 |
no test coverage detected