vain/testing.go
Stephen McQuay (smcquay) c575677088
Use in-memory, on-disk-backed DB
- removed sqlite
- added stubs for MemDB
- removed sqlite3 vendor

Fixes #7

Change-Id: I97b7f274be8db5ff02d9a4e4b8f616403fd6313a
2016-06-25 13:37:23 -07:00

30 lines
650 B
Go

package vain
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
)
// TestDB returns a populated MemDB in a temp location, as well as a function
// to call at cleanup time.
func TestDB(t *testing.T) (*MemDB, 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.json")
db, err := NewMemDB(name)
if err != nil {
t.Fatalf("could not create db: %v", err)
return nil, func() {}
}
return db, func() {
if err := os.RemoveAll(dir); err != nil {
t.Fatalf("could not clean up tmpdir: %v", err)
}
}
}