fix(launcher): Fix launcher tests

pull/19446/head
Stuart Carnie 2020-08-03 15:17:37 -07:00
parent 840d0a994f
commit 49067de49f
No known key found for this signature in database
GPG Key ID: 848D9C9718D78B4F
5 changed files with 43 additions and 23 deletions

View File

@ -977,6 +977,16 @@ func (m *Launcher) run(ctx context.Context) (err error) {
ts.BucketService = storage.NewBucketService(ts.BucketService, m.engine)
ts.BucketService = dbrp.NewBucketService(m.log, ts.BucketService, dbrpSvc)
var onboardOpts []tenant.OnboardServiceOptionFn
if m.testing {
onboardOpts = append(onboardOpts, tenant.WithAlwaysAllowInitialUser())
}
onboardSvc := tenant.NewOnboardService(ts, authSvc, onboardOpts...) // basic service
onboardSvc = tenant.NewAuthedOnboardSvc(onboardSvc) // with auth
onboardSvc = tenant.NewOnboardingMetrics(m.reg, onboardSvc, metric.WithSuffix("new")) // with metrics
onboardSvc = tenant.NewOnboardingLogger(m.log.With(zap.String("handler", "onboard")), onboardSvc) // with logging
m.apibackend = &http.APIBackend{
AssetsPath: m.assetsPath,
HTTPErrorHandler: kithttp.ErrorHandler(0),
@ -998,6 +1008,7 @@ func (m *Launcher) run(ctx context.Context) (err error) {
BucketService: ts.BucketService,
SessionService: sessionSvc,
UserService: ts.UserService,
OnboardingService: onboardSvc,
DBRPService: dbrpSvc,
OrganizationService: ts.OrganizationService,
UserResourceMappingService: ts.UserResourceMappingService,
@ -1074,16 +1085,7 @@ func (m *Launcher) run(ctx context.Context) (err error) {
}
userHTTPServer := ts.NewUserHTTPHandler(m.log)
var onboardHTTPServer *tenant.OnboardHandler
{
onboardSvc := tenant.NewOnboardService(ts, authSvc) // basic service
onboardSvc = tenant.NewAuthedOnboardSvc(onboardSvc) // with auth
onboardSvc = tenant.NewOnboardingMetrics(m.reg, onboardSvc, metric.WithSuffix("new")) // with metrics
onboardSvc = tenant.NewOnboardingLogger(m.log.With(zap.String("handler", "onboard")), onboardSvc) // with logging
onboardHTTPServer = tenant.NewHTTPOnboardHandler(m.log, onboardSvc)
}
onboardHTTPServer := tenant.NewHTTPOnboardHandler(m.log, onboardSvc)
// feature flagging for new labels service
var oldLabelHandler nethttp.Handler

View File

@ -85,6 +85,8 @@ func RunTestLauncherOrFail(tb testing.TB, ctx context.Context, flagger feature.F
// Passed arguments will overwrite/add to the default ones.
func (tl *TestLauncher) Run(ctx context.Context, args ...string) error {
largs := make([]string, 0, len(args)+8)
largs = append(largs, "--store", "memory")
largs = append(largs, "--e2e-testing")
largs = append(largs, "--bolt-path", filepath.Join(tl.Path, bolt.DefaultFilename))
largs = append(largs, "--engine-path", filepath.Join(tl.Path, "engine"))
largs = append(largs, "--http-bind-address", "127.0.0.1:0")
@ -137,15 +139,7 @@ func (tl *TestLauncher) SetupOrFail(tb testing.TB) {
// OnBoard attempts an on-boarding request.
// The on-boarding status is also reset to allow multiple user/org/buckets to be created.
func (tl *TestLauncher) OnBoard(req *platform.OnboardingRequest) (*platform.OnboardingResults, error) {
res, err := tl.KeyValueService().OnboardInitialUser(context.Background(), req)
if err != nil {
return nil, err
}
err = tl.KeyValueService().PutOnboardingStatus(context.Background(), false)
if err != nil {
return nil, err
}
return res, nil
return tl.apibackend.OnboardingService.OnboardInitialUser(context.Background(), req)
}
// OnBoardOrFail attempts an on-boarding request or fails on error.

View File

@ -752,6 +752,7 @@ from(bucket: "%s")
}
func TestQueryPushDowns(t *testing.T) {
t.Skip("Not supported yet")
testcases := []struct {
name string
data []string

View File

@ -59,6 +59,7 @@ type APIBackend struct {
BackupService influxdb.BackupService
KVBackupService influxdb.KVBackupService
AuthorizationService influxdb.AuthorizationService
OnboardingService influxdb.OnboardingService
DBRPService influxdb.DBRPMappingServiceV2
BucketService influxdb.BucketService
SessionService influxdb.SessionService

View File

@ -10,19 +10,41 @@ import (
)
type OnboardService struct {
service *Service
authSvc influxdb.AuthorizationService
service *Service
authSvc influxdb.AuthorizationService
alwaysAllow bool
}
func NewOnboardService(svc *Service, as influxdb.AuthorizationService) influxdb.OnboardingService {
return &OnboardService{
type OnboardServiceOptionFn func(*OnboardService)
// WithAlwaysAllowInitialUser configures the OnboardService to
// always return true for IsOnboarding to allow multiple
// initial onboard requests.
func WithAlwaysAllowInitialUser() OnboardServiceOptionFn {
return func(s *OnboardService) {
s.alwaysAllow = true
}
}
func NewOnboardService(svc *Service, as influxdb.AuthorizationService, opts ...OnboardServiceOptionFn) influxdb.OnboardingService {
s := &OnboardService{
service: svc,
authSvc: as,
}
for _, opt := range opts {
opt(s)
}
return s
}
// IsOnboarding determine if onboarding request is allowed.
func (s *OnboardService) IsOnboarding(ctx context.Context) (bool, error) {
if s.alwaysAllow {
return true, nil
}
allowed := false
err := s.service.store.View(ctx, func(tx kv.Tx) error {
// we are allowed to onboard a user if we have no users or orgs