@@ -33,16 +33,29 @@ func TestMain(m *testing.M) {
3333 }
3434 // Run tests against all file systems.
3535 for _ , fsys := range []fs.FileSystem {fs .Mem , fs .OSMMap , fs .OS } {
36- testFS = fsys
36+ var tmpDir string
37+ if fsys == fs .Mem {
38+ testFS = fsys
39+ } else {
40+ var err error
41+ tmpDir , err = os .MkdirTemp ("" , "pogreb-test" )
42+ if err != nil {
43+ fmt .Printf ("failed to create temporary directory: %v" , err )
44+ os .Exit (1 )
45+ }
46+ testFS = fs .Sub (fsys , tmpDir )
47+ }
3748 if testing .Verbose () {
38- fmt .Printf ("=== SET\t FS=%T\n " , fsys )
49+ fmt .Printf ("=== SET\t FS=%T\t tmpDir=%s \ n " , fsys , tmpDir )
3950 }
40- if exitCode := m .Run (); exitCode != 0 {
51+ exitCode := m .Run ()
52+ if tmpDir != "" {
53+ _ = os .RemoveAll (tmpDir )
54+ }
55+ if exitCode != 0 {
4156 fmt .Printf ("DEBUG\t FS=%T\n " , fsys )
4257 os .Exit (exitCode )
4358 }
44- _ = cleanDir (testDBName )
45- _ = cleanDir (testDBBackupName )
4659 }
4760 os .Exit (0 )
4861}
@@ -83,6 +96,9 @@ func TestHeaderSize(t *testing.T) {
8396func cleanDir (path string ) error {
8497 files , err := testFS .ReadDir (path )
8598 if err != nil {
99+ if os .IsNotExist (err ) {
100+ return nil
101+ }
86102 return err
87103 }
88104 for _ , file := range files {
@@ -214,7 +230,7 @@ func fullTest(t *testing.T, getFunc func(db *DB, key []byte) ([]byte, error)) {
214230 verifyKeysAndClose (6 )
215231
216232 // Delete all items
217- db , err = Open (testDBName , & Options {BackgroundSyncInterval : time .Millisecond })
233+ db , err = Open (testDBName , & Options {BackgroundSyncInterval : time .Millisecond , FileSystem : testFS })
218234 assert .Nil (t , err )
219235 for i = 0 ; i < n ; i ++ {
220236 assert .Nil (t , db .Delete ([]byte {i }))
0 commit comments