43 lines
1.0 KiB
Go
43 lines
1.0 KiB
Go
package bolt_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
platform "github.com/influxdata/influxdb"
|
|
"github.com/influxdata/influxdb/bolt"
|
|
platformtesting "github.com/influxdata/influxdb/testing"
|
|
)
|
|
|
|
func initSessionService(f platformtesting.SessionFields, t *testing.T) (platform.SessionService, string, func()) {
|
|
c, closeFn, err := NewTestClient()
|
|
if err != nil {
|
|
t.Fatalf("failed to create new bolt client: %v", err)
|
|
}
|
|
c.IDGenerator = f.IDGenerator
|
|
c.TokenGenerator = f.TokenGenerator
|
|
ctx := context.Background()
|
|
for _, u := range f.Users {
|
|
if err := c.PutUser(ctx, u); err != nil {
|
|
t.Fatalf("failed to populate users")
|
|
}
|
|
}
|
|
for _, s := range f.Sessions {
|
|
if err := c.PutSession(ctx, s); err != nil {
|
|
t.Fatalf("failed to populate sessions")
|
|
}
|
|
}
|
|
return c, bolt.OpPrefix, func() {
|
|
defer closeFn()
|
|
for _, u := range f.Users {
|
|
if err := c.DeleteUser(ctx, u.ID); err != nil {
|
|
t.Logf("failed to remove users: %v", err)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestSessionService(t *testing.T) {
|
|
platformtesting.SessionService(initSessionService, t)
|
|
}
|