make helper NewTestDB more helpful with t.TempDir
parent
8883856a63
commit
6ba23e61c3
|
|
@ -3,7 +3,7 @@ package main
|
|||
import (
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"time"
|
||||
|
||||
"go.etcd.io/bbolt"
|
||||
|
|
@ -20,12 +20,12 @@ type BBolt struct {
|
|||
db *bbolt.DB
|
||||
}
|
||||
|
||||
func NewTestDB() BBolt {
|
||||
d, err := ioutil.TempDir(os.TempDir(), "test-db-*")
|
||||
func NewTestDBIn(d string) BBolt {
|
||||
d, err := ioutil.TempDir(d, "test-db-*")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
db, err := NewDB(d)
|
||||
db, err := NewDB(path.Join(d, "bb"))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,18 +4,11 @@ import (
|
|||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"path"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDriverBBolt(t *testing.T) {
|
||||
bb, err := NewDB(path.Join(t.TempDir(), "bb"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer bb.Close()
|
||||
|
||||
testDriver(t, bb)
|
||||
testDriver(t, NewTestDBIn(t.TempDir()))
|
||||
}
|
||||
|
||||
func testDriver(t *testing.T, d Driver) {
|
||||
|
|
|
|||
4
queue.go
4
queue.go
|
|
@ -11,8 +11,8 @@ type Queue struct {
|
|||
driver Driver
|
||||
}
|
||||
|
||||
func NewTestQueue() Queue {
|
||||
return Queue{driver: NewTestDB()}
|
||||
func NewTestQueueIn(d string) Queue {
|
||||
return Queue{driver: NewTestDBIn(d)}
|
||||
}
|
||||
|
||||
func NewQueue(driver Driver) Queue {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package main
|
|||
|
||||
import (
|
||||
"context"
|
||||
"path"
|
||||
"strconv"
|
||||
"testing"
|
||||
"time"
|
||||
|
|
@ -12,10 +11,7 @@ func TestQueue(t *testing.T) {
|
|||
ctx, can := context.WithTimeout(context.Background(), time.Second*10)
|
||||
defer can()
|
||||
|
||||
db, err := NewDB(path.Join(t.TempDir(), "q"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
db := NewTestDBIn(t.TempDir())
|
||||
defer db.Close()
|
||||
|
||||
q := NewQueue(db)
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ type Storage struct {
|
|||
driver Driver
|
||||
}
|
||||
|
||||
func NewTestStorage() Storage {
|
||||
return Storage{driver: NewTestDB()}
|
||||
func NewTestStorageIn(d string) Storage {
|
||||
return Storage{driver: NewTestDBIn(d)}
|
||||
}
|
||||
|
||||
func NewStorage(driver Driver) Storage {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
package main
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestStorage(t *testing.T) {
|
||||
}
|
||||
Loading…
Reference in New Issue