modernc.org/ql@v1.4.7/file_test.go (about) 1 // Copyright (c) 2014 ql Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package ql // import "modernc.org/ql" 6 7 import ( 8 "io/ioutil" 9 "os" 10 "path/filepath" 11 "testing" 12 ) 13 14 func fileExists(p string) bool { 15 _, err := os.Stat(p) 16 return err == nil 17 } 18 19 func TestWALRemoval(t *testing.T) { 20 tmpDir, err := ioutil.TempDir("", "ql-test-") 21 if err != nil { 22 t.Fatal(err) 23 } 24 25 defer os.RemoveAll(tmpDir) 26 27 tempDBName := filepath.Join(tmpDir, "test_was_removal.db") 28 wName := WalName(tempDBName) 29 30 db, err := OpenFile(tempDBName, &Options{CanCreate: true}) 31 if err != nil { 32 t.Fatalf("Cannot open db %s: %s\n", tempDBName, err) 33 } 34 db.Close() 35 if !fileExists(wName) { 36 t.Fatalf("Expect WAL file %s to exist but it doesn't", wName) 37 } 38 39 db, err = OpenFile(tempDBName, &Options{CanCreate: true, RemoveEmptyWAL: true}) 40 if err != nil { 41 t.Fatalf("Cannot open db %s: %s\n", tempDBName, err) 42 } 43 db.Close() 44 if fileExists(wName) { 45 t.Fatalf("Expect WAL file %s to be removed but it still exists", wName) 46 } 47 }