2020-01-21 16:26:23 +00:00
|
|
|
package kv_test
|
2016-09-30 20:39:27 +00:00
|
|
|
|
|
|
|
import (
|
2017-12-18 20:06:17 +00:00
|
|
|
"context"
|
2016-09-30 20:39:27 +00:00
|
|
|
"errors"
|
|
|
|
"io/ioutil"
|
|
|
|
|
2017-12-18 20:06:17 +00:00
|
|
|
"github.com/influxdata/chronograf"
|
2020-01-21 16:26:23 +00:00
|
|
|
"github.com/influxdata/chronograf/kv"
|
2020-01-09 15:49:42 +00:00
|
|
|
"github.com/influxdata/chronograf/kv/bolt"
|
2020-01-22 00:21:54 +00:00
|
|
|
"github.com/influxdata/chronograf/mocks"
|
2016-09-30 20:39:27 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// NewTestClient creates new *bolt.Client with a set time and temp path.
|
2020-01-21 16:26:23 +00:00
|
|
|
func NewTestClient() (*kv.Service, error) {
|
2016-10-20 14:38:23 +00:00
|
|
|
f, err := ioutil.TempFile("", "chronograf-bolt-")
|
2016-09-30 20:39:27 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.New("unable to open temporary boltdb file")
|
|
|
|
}
|
|
|
|
f.Close()
|
|
|
|
|
2017-12-18 20:06:17 +00:00
|
|
|
build := chronograf.BuildInfo{
|
|
|
|
Version: "version",
|
|
|
|
Commit: "commit",
|
|
|
|
}
|
|
|
|
|
2020-01-21 16:26:23 +00:00
|
|
|
ctx := context.TODO()
|
|
|
|
b, err := bolt.NewClient(ctx,
|
|
|
|
bolt.WithPath(f.Name()),
|
|
|
|
bolt.WithBuildInfo(build),
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2016-09-30 20:39:27 +00:00
|
|
|
|
2020-01-22 00:21:54 +00:00
|
|
|
return kv.NewService(ctx, b, kv.WithLogger(mocks.NewLogger()))
|
2016-09-30 20:39:27 +00:00
|
|
|
}
|