-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathbuckets_test.go
More file actions
44 lines (38 loc) · 800 Bytes
/
buckets_test.go
File metadata and controls
44 lines (38 loc) · 800 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package buckets_test
import (
"io/ioutil"
"log"
"os"
"github.com/joyrexus/buckets"
)
type TestDB struct {
*buckets.DB
}
// NewTestDB returns a TestDB using a temporary path.
func NewTestDB() *TestDB {
bx, err := buckets.Open(tempfile())
if err != nil {
log.Fatalf("cannot open buckets database: %s", err)
}
// Return wrapped type.
return &TestDB{bx}
}
// Close and delete buckets database.
func (db *TestDB) Close() {
defer os.Remove(db.Path())
db.DB.Close()
}
// tempfile returns a temporary file path.
func tempfile() string {
f, err := ioutil.TempFile("", "bolt-")
if err != nil {
log.Fatalf("Could not create temp file: %s", err)
}
if err := f.Close(); err != nil {
log.Fatal(err)
}
if err := os.Remove(f.Name()); err != nil {
log.Fatal(err)
}
return f.Name()
}