2018-05-15 21:19:44 +00:00
|
|
|
package bolt_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
2018-10-26 22:07:20 +00:00
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
2018-05-15 21:19:44 +00:00
|
|
|
|
|
|
|
"github.com/influxdata/platform/bolt"
|
2018-09-25 16:43:05 +00:00
|
|
|
"golang.org/x/crypto/bcrypt"
|
2018-05-15 21:19:44 +00:00
|
|
|
)
|
|
|
|
|
2018-11-09 22:13:02 +00:00
|
|
|
func init() {
|
|
|
|
bolt.HashCost = bcrypt.MinCost
|
|
|
|
}
|
|
|
|
|
2018-05-15 21:19:44 +00:00
|
|
|
func NewTestClient() (*bolt.Client, func(), error) {
|
|
|
|
c := bolt.NewClient()
|
|
|
|
|
|
|
|
f, err := ioutil.TempFile("", "influxdata-platform-bolt-")
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, errors.New("unable to open temporary boltdb file")
|
|
|
|
}
|
|
|
|
f.Close()
|
|
|
|
|
|
|
|
c.Path = f.Name()
|
|
|
|
|
|
|
|
if err := c.Open(context.TODO()); err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
close := func() {
|
|
|
|
c.Close()
|
|
|
|
os.Remove(c.Path)
|
|
|
|
}
|
|
|
|
|
|
|
|
return c, close, nil
|
|
|
|
}
|
2018-10-26 22:07:20 +00:00
|
|
|
|
|
|
|
func TestClientOpen(t *testing.T) {
|
|
|
|
tempDir, err := ioutil.TempDir("", "")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unable to create temporary test directory %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
if err := os.RemoveAll(tempDir); err != nil {
|
|
|
|
t.Fatalf("unable to delete temporary test directory %s: %v", tempDir, err)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
boltFile := filepath.Join(tempDir, "test", "bolt.db")
|
|
|
|
|
|
|
|
c := bolt.NewClient()
|
|
|
|
c.Path = boltFile
|
|
|
|
|
|
|
|
if err := c.Open(context.Background()); err != nil {
|
|
|
|
t.Fatalf("unable to create database %s: %v", boltFile, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := c.Close(); err != nil {
|
|
|
|
t.Fatalf("unable to close database %s: %v", boltFile, err)
|
|
|
|
}
|
|
|
|
}
|