This commit is contained in:
Bel LaPointe
2019-03-14 11:12:08 -06:00
parent 97b53aab90
commit 10e02bac31
2 changed files with 60 additions and 3 deletions

View File

@@ -3,9 +3,11 @@ package storage
import (
"bytes"
"io/ioutil"
"log"
"net"
"os"
"path"
"sync"
"testing"
)
@@ -180,3 +182,33 @@ func TestToFromString(t *testing.T) {
}
}
}
func TestNew(t *testing.T) {
dir, err := ioutil.TempDir("", "storage_tests_")
if err != nil {
t.Fatalf("cannot create temp dir: %v", err)
return
}
defer os.RemoveAll(dir)
if b, err := New(BOLT); err == nil {
t.Errorf("can create bolt without path")
b.Close()
}
if b, err := New(BOLT, path.Join(dir, "bolt")); err != nil {
t.Errorf("cannot create bolt with path")
} else {
b.Close()
}
}
func recoverDeferred(c Type, t *testing.T, wg *sync.WaitGroup) {
if err := recover(); err != nil {
log.Printf("recover deferre fail: %s", c)
t.Errorf("[%s] panic: %v", c, err)
} else {
log.Printf("recover deferre ok: %s", c)
}
defer wg.Done()
}