66 "flag"
77 "fmt"
88 "io"
9- "io/ioutil"
109 "log"
1110 "os"
1211 "path/filepath"
3029func TestMain (m * testing.M ) {
3130 flag .Parse ()
3231 if ! testing .Verbose () {
33- SetLogger (log .New (ioutil .Discard , "" , 0 ))
32+ SetLogger (log .New (io .Discard , "" , 0 ))
3433 }
3534 // Run tests against all file systems.
3635 for _ , fsys := range []fs.FileSystem {fs .Mem , fs .OSMMap , fs .OS } {
@@ -43,6 +42,7 @@ func TestMain(m *testing.M) {
4342 os .Exit (exitCode )
4443 }
4544 }
45+ _ = cleanDir (testDBName )
4646 os .Exit (0 )
4747}
4848
@@ -87,6 +87,17 @@ func TestHeaderSize(t *testing.T) {
8787 }
8888}
8989
90+ func cleanDir (path string ) error {
91+ files , err := testFS .ReadDir (path )
92+ if err != nil {
93+ return err
94+ }
95+ for _ , file := range files {
96+ _ = testFS .Remove (filepath .Join (testDBName , file .Name ()))
97+ }
98+ return nil
99+ }
100+
90101func createTestDB (opts * Options ) (* DB , error ) {
91102 if opts == nil {
92103 opts = & Options {FileSystem : testFS }
@@ -95,15 +106,10 @@ func createTestDB(opts *Options) (*DB, error) {
95106 opts .FileSystem = testFS
96107 }
97108 }
98- path := testDBName
99- files , err := testFS .ReadDir (path )
100- if err != nil && ! os .IsNotExist (err ) {
109+ if err := cleanDir (testDBName ); err != nil {
101110 return nil , err
102111 }
103- for _ , file := range files {
104- _ = testFS .Remove (filepath .Join (path , file .Name ()))
105- }
106- return Open (path , opts )
112+ return Open (testDBName , opts )
107113}
108114
109115func TestEmpty (t * testing.T ) {
0 commit comments