test(http): add client tests for auth and bucket
parent
0b70dc99c4
commit
29a1eb4714
|
@ -5,6 +5,8 @@ import (
|
|||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/influxdata/platform/inmem"
|
||||
platformtesting "github.com/influxdata/platform/testing"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
|
@ -443,3 +445,55 @@ func TestService_handleDeleteAuthorization(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func initAuthorizationService(f platformtesting.AuthorizationFields, t *testing.T) (platform.AuthorizationService, func()) {
|
||||
t.Helper()
|
||||
|
||||
svc := inmem.NewService()
|
||||
svc.IDGenerator = f.IDGenerator
|
||||
svc.TokenGenerator = f.TokenGenerator
|
||||
|
||||
ctx := context.TODO()
|
||||
for _, u := range f.Users {
|
||||
if err := svc.PutUser(ctx, u); err != nil {
|
||||
t.Fatalf("failed to populate users")
|
||||
}
|
||||
}
|
||||
for _, u := range f.Authorizations {
|
||||
if err := svc.PutAuthorization(ctx, u); err != nil {
|
||||
t.Fatalf("failed to populate authorizations")
|
||||
}
|
||||
}
|
||||
|
||||
handler := NewAuthorizationHandler()
|
||||
handler.AuthorizationService = svc
|
||||
server := httptest.NewServer(handler)
|
||||
client := AuthorizationService{
|
||||
Addr: server.URL,
|
||||
}
|
||||
done := func() {
|
||||
server.Close()
|
||||
}
|
||||
|
||||
return &client, done
|
||||
}
|
||||
|
||||
func TestAuthorizationService_CreateAuthorization(t *testing.T) {
|
||||
platformtesting.CreateAuthorization(initAuthorizationService, t)
|
||||
}
|
||||
|
||||
func TestAuthorizationService_FindAuthorizationByID(t *testing.T) {
|
||||
platformtesting.FindAuthorizationByID(initAuthorizationService, t)
|
||||
}
|
||||
|
||||
func TestAuthorizationService_FindAuthorizationByToken(t *testing.T) {
|
||||
platformtesting.FindAuthorizationByToken(initAuthorizationService, t)
|
||||
}
|
||||
|
||||
func TestAuthorizationService_FindAuthorizations(t *testing.T) {
|
||||
platformtesting.FindAuthorizations(initAuthorizationService, t)
|
||||
}
|
||||
|
||||
func TestAuthorizationService_DeleteAuthorization(t *testing.T) {
|
||||
platformtesting.DeleteAuthorization(initAuthorizationService, t)
|
||||
}
|
||||
|
|
|
@ -12,7 +12,9 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/influxdata/platform"
|
||||
"github.com/influxdata/platform/inmem"
|
||||
"github.com/influxdata/platform/mock"
|
||||
platformtesting "github.com/influxdata/platform/testing"
|
||||
"github.com/julienschmidt/httprouter"
|
||||
)
|
||||
|
||||
|
@ -585,3 +587,57 @@ func TestService_handlePatchBucket(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func initBucketService(f platformtesting.BucketFields, t *testing.T) (platform.BucketService, func()) {
|
||||
t.Helper()
|
||||
|
||||
svc := inmem.NewService()
|
||||
svc.IDGenerator = f.IDGenerator
|
||||
|
||||
ctx := context.TODO()
|
||||
for _, o := range f.Organizations {
|
||||
if err := svc.PutOrganization(ctx, o); err != nil {
|
||||
t.Fatalf("failed to populate organizations")
|
||||
}
|
||||
}
|
||||
for _, b := range f.Buckets {
|
||||
if err := svc.PutBucket(ctx, b); err != nil {
|
||||
t.Fatalf("failed to populate buckets")
|
||||
}
|
||||
}
|
||||
|
||||
handler := NewBucketHandler()
|
||||
handler.BucketService = svc
|
||||
server := httptest.NewServer(handler)
|
||||
client := BucketService{
|
||||
Addr: server.URL,
|
||||
}
|
||||
done := func() {
|
||||
server.Close()
|
||||
}
|
||||
|
||||
return &client, done
|
||||
}
|
||||
func TestBucketService_CreateBucket(t *testing.T) {
|
||||
platformtesting.CreateBucket(initBucketService, t)
|
||||
}
|
||||
|
||||
func TestBucketService_FindBucketByID(t *testing.T) {
|
||||
platformtesting.FindBucketByID(initBucketService, t)
|
||||
}
|
||||
|
||||
func TestBucketService_FindBuckets(t *testing.T) {
|
||||
platformtesting.FindBuckets(initBucketService, t)
|
||||
}
|
||||
|
||||
func TestBucketService_DeleteBucket(t *testing.T) {
|
||||
platformtesting.DeleteBucket(initBucketService, t)
|
||||
}
|
||||
|
||||
func TestBucketService_FindBucket(t *testing.T) {
|
||||
platformtesting.FindBucket(initBucketService, t)
|
||||
}
|
||||
|
||||
func TestBucketService_UpdateBucket(t *testing.T) {
|
||||
platformtesting.UpdateBucket(initBucketService, t)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue