2018-09-14 23:47:05 +00:00
|
|
|
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
|
|
|
|
|
2018-09-15 00:24:32 +00:00
|
|
|
ctx := context.Background()
|
2018-09-14 23:47:05 +00:00
|
|
|
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
|
2018-09-14 23:47:05 +00:00
|
|
|
|
|
|
|
return &client, done
|
|
|
|
}
|
|
|
|
|
2018-09-15 02:08:49 +00:00
|
|
|
func TestUserService(t *testing.T) {
|
2018-09-14 23:47:05 +00:00
|
|
|
t.Parallel()
|
2018-09-15 02:08:49 +00:00
|
|
|
platformtesting.UserService(initUserService, t)
|
2018-09-14 23:47:05 +00:00
|
|
|
}
|