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