2020-03-27 14:56:22 +00:00
|
|
|
package tenant_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"net/http/httptest"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/go-chi/chi"
|
2020-04-03 17:39:20 +00:00
|
|
|
platform "github.com/influxdata/influxdb/v2"
|
|
|
|
ihttp "github.com/influxdata/influxdb/v2/http"
|
|
|
|
"github.com/influxdata/influxdb/v2/tenant"
|
|
|
|
platformtesting "github.com/influxdata/influxdb/v2/testing"
|
2020-03-27 14:56:22 +00:00
|
|
|
"go.uber.org/zap/zaptest"
|
|
|
|
)
|
|
|
|
|
|
|
|
func initHttpUserService(f platformtesting.UserFields, t *testing.T) (platform.UserService, string, func()) {
|
|
|
|
t.Helper()
|
|
|
|
|
2021-08-31 20:43:45 +00:00
|
|
|
s := platformtesting.NewTestInmemStore(t)
|
2020-03-27 14:56:22 +00:00
|
|
|
|
2020-07-01 11:08:20 +00:00
|
|
|
storage := tenant.NewStore(s)
|
2020-03-27 14:56:22 +00:00
|
|
|
svc := tenant.NewService(storage)
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
for _, u := range f.Users {
|
|
|
|
if err := svc.CreateUser(ctx, u); err != nil {
|
|
|
|
t.Fatalf("failed to populate users")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handler := tenant.NewHTTPUserHandler(zaptest.NewLogger(t), svc, svc)
|
|
|
|
r := chi.NewRouter()
|
|
|
|
r.Mount("/api/v2/users", handler)
|
|
|
|
r.Mount("/api/v2/me", handler)
|
|
|
|
server := httptest.NewServer(r)
|
|
|
|
|
|
|
|
httpClient, err := ihttp.NewHTTPClient(server.URL, "", false)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
client := tenant.UserClientService{
|
|
|
|
Client: httpClient,
|
|
|
|
}
|
|
|
|
|
2021-08-31 20:43:45 +00:00
|
|
|
return &client, "http_tenant", server.Close
|
2020-03-27 14:56:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestUserService(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
platformtesting.UserService(initHttpUserService, t)
|
|
|
|
}
|