github.com/runner-mei/ql@v1.1.0/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
     6  
     7  import (
     8  	"os"
     9  	"testing"
    10  )
    11  
    12  func fileExists(p string) bool {
    13  	_, err := os.Stat(p)
    14  	return err == nil
    15  }
    16  
    17  func TestWALRemoval(t *testing.T) {
    18  	const tempDBName = "./_test_was_removal.db"
    19  	wName := walName(tempDBName)
    20  	defer os.Remove(tempDBName)
    21  	defer os.Remove(wName)
    22  
    23  	db, err := OpenFile(tempDBName, &Options{CanCreate: true})
    24  	if err != nil {
    25  		t.Fatalf("Cannot open db %s: %s\n", tempDBName, err)
    26  	}
    27  	db.Close()
    28  	if !fileExists(wName) {
    29  		t.Fatalf("Expect WAL file %s to exist but it doesn't", wName)
    30  	}
    31  
    32  	db, err = OpenFile(tempDBName, &Options{CanCreate: true, RemoveEmptyWAL: true})
    33  	if err != nil {
    34  		t.Fatalf("Cannot open db %s: %s\n", tempDBName, err)
    35  	}
    36  	db.Close()
    37  	if fileExists(wName) {
    38  		t.Fatalf("Expect WAL file %s to be removed but it still exists", wName)
    39  	}
    40  }