2019-05-15 17:16:47 +00:00
|
|
|
package kv_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-01-21 22:22:45 +00:00
|
|
|
"io"
|
2019-05-15 17:16:47 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2020-04-03 17:39:20 +00:00
|
|
|
"github.com/influxdata/influxdb/v2"
|
|
|
|
"github.com/influxdata/influxdb/v2/kv"
|
2019-12-04 23:10:23 +00:00
|
|
|
"go.uber.org/zap/zaptest"
|
2019-05-15 17:16:47 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type mockStore struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s mockStore) View(context.Context, func(kv.Tx) error) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s mockStore) Update(context.Context, func(kv.Tx) error) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-01-21 22:22:45 +00:00
|
|
|
func (s mockStore) Backup(ctx context.Context, w io.Writer) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-05-15 17:16:47 +00:00
|
|
|
func TestNewService(t *testing.T) {
|
2019-12-04 23:10:23 +00:00
|
|
|
s := kv.NewService(zaptest.NewLogger(t), mockStore{})
|
2019-05-15 17:16:47 +00:00
|
|
|
|
|
|
|
if s.Config.SessionLength != influxdb.DefaultSessionLength {
|
|
|
|
t.Errorf("Service session length should use default length when not set")
|
|
|
|
}
|
|
|
|
|
|
|
|
config := kv.ServiceConfig{
|
|
|
|
SessionLength: time.Duration(time.Hour * 4),
|
|
|
|
}
|
|
|
|
|
2019-12-04 23:10:23 +00:00
|
|
|
s = kv.NewService(zaptest.NewLogger(t), mockStore{}, config)
|
2019-05-15 17:16:47 +00:00
|
|
|
|
|
|
|
if s.Config != config {
|
|
|
|
t.Errorf("Service config not set by constructor")
|
|
|
|
}
|
|
|
|
}
|