1
0
forked from sm/vain
vain/testing.go
stephen mcquay 680eecb111
Added simple user auth
Fixes #14.

Change-Id: I748933214f43ac7298f1e93c14bb0ee881976d43
2016-04-27 21:29:48 -07:00

34 lines
613 B
Go

package vain
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
)
func testDB(t *testing.T) (*DB, func()) {
dir, err := ioutil.TempDir("", "vain-testing-")
if err != nil {
t.Fatalf("could not create tmpdir for db: %v", err)
return nil, func() {}
}
name := filepath.Join(dir, "test.db")
db, err := NewDB(name)
if err != nil {
t.Fatalf("could not create db: %v", err)
return nil, func() {}
}
if err := db.Init(); err != nil {
return nil, func() {}
}
return db, func() {
db.Close()
if err := os.RemoveAll(dir); err != nil {
t.Fatalf("could not clean up tmpdir: %v", err)
}
}
}