Skip to content

Commit fc4d47b

Browse files
committed
db: use (*testing.T).Chdir
Update a couple tests that chdir to use (*testing.T).Chdir (new in Go 1.24) to change directories with the guarantee that the Go test runner will change the directory back to the original after the test completes.
1 parent 21a7dff commit fc4d47b

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

open_test.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -535,15 +535,11 @@ func TestOpenAlreadyLocked(t *testing.T) {
535535
})
536536

537537
t.Run("relative", func(t *testing.T) {
538-
original, err := os.Getwd()
539-
require.NoError(t, err)
540-
541538
for _, tc := range testCases {
542539
t.Run(tc.name, func(t *testing.T) {
543540
// Create a temporary directory structure for relative paths.
544541
tempRoot := t.TempDir()
545-
require.NoError(t, os.Chdir(tempRoot))
546-
defer func() { require.NoError(t, os.Chdir(original)) }()
542+
t.Chdir(tempRoot)
547543

548544
var tmpDirs [4]string
549545
for i := range tmpDirs {
@@ -1790,9 +1786,6 @@ func TestMkdirAllAndSyncParents(t *testing.T) {
17901786
if filepath.Separator != '/' {
17911787
t.Skip("skipping due to path separator")
17921788
}
1793-
pwd, err := os.Getwd()
1794-
require.NoError(t, err)
1795-
defer func() { os.Chdir(pwd) }()
17961789

17971790
filesystems := map[string]vfs.FS{}
17981791
rootPaths := map[string]string{}
@@ -1815,7 +1808,7 @@ func TestMkdirAllAndSyncParents(t *testing.T) {
18151808
td.ScanArgs(t, "fs", &fsName)
18161809
td.ScanArgs(t, "path", &path)
18171810
if p, ok := rootPaths[fsName]; ok {
1818-
require.NoError(t, os.Chdir(p))
1811+
t.Chdir(p)
18191812
}
18201813
fs := vfs.WithLogging(filesystems[fsName], func(format string, args ...interface{}) {
18211814
fmt.Fprintf(&buf, format+"\n", args...)

0 commit comments

Comments
 (0)