influxdb/http/user_test.go

40 lines
817 B
Go
Raw Normal View History

package http
import (
"context"
"net/http/httptest"
"testing"
"github.com/influxdata/platform"
"github.com/influxdata/platform/inmem"
platformtesting "github.com/influxdata/platform/testing"
)
func initUserService(f platformtesting.UserFields, t *testing.T) (platform.UserService, func()) {
t.Helper()
svc := inmem.NewService()
svc.IDGenerator = f.IDGenerator
ctx := context.Background()
for _, u := range f.Users {
if err := svc.PutUser(ctx, u); err != nil {
t.Fatalf("failed to populate users")
}
}
handler := NewUserHandler()
handler.UserService = svc
server := httptest.NewServer(handler)
client := UserService{
Addr: server.URL,
}
2018-09-15 00:34:00 +00:00
done := server.Close
return &client, done
}
func TestUserService(t *testing.T) {
t.Parallel()
platformtesting.UserService(initUserService, t)
}