2018-10-23 17:51:13 +00:00
|
|
|
package http_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"net/http/httptest"
|
|
|
|
"testing"
|
|
|
|
|
2019-01-08 00:37:16 +00:00
|
|
|
platform "github.com/influxdata/influxdb"
|
|
|
|
"github.com/influxdata/influxdb/http"
|
|
|
|
"github.com/influxdata/influxdb/inmem"
|
2019-06-06 16:05:27 +00:00
|
|
|
"github.com/influxdata/influxdb/kv"
|
2019-01-08 00:37:16 +00:00
|
|
|
_ "github.com/influxdata/influxdb/query/builtin"
|
|
|
|
"github.com/influxdata/influxdb/task/servicetest"
|
2019-06-06 16:05:27 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
"go.uber.org/zap/zaptest"
|
2018-10-23 17:51:13 +00:00
|
|
|
)
|
|
|
|
|
2019-06-06 16:05:27 +00:00
|
|
|
func TestTaskService(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
servicetest.TestTaskService(
|
|
|
|
t,
|
|
|
|
func(t *testing.T) (*servicetest.System, context.CancelFunc) {
|
2019-02-07 01:34:54 +00:00
|
|
|
|
2019-06-06 16:05:27 +00:00
|
|
|
service := kv.NewService(inmem.NewKVStore())
|
|
|
|
ctx, cancelFunc := context.WithCancel(context.Background())
|
2018-10-23 17:51:13 +00:00
|
|
|
|
2019-06-06 16:05:27 +00:00
|
|
|
if err := service.Initialize(ctx); err != nil {
|
|
|
|
t.Fatalf("error initializing urm service: %v", err)
|
|
|
|
}
|
2018-10-23 17:51:13 +00:00
|
|
|
|
2019-06-27 01:33:20 +00:00
|
|
|
h := http.NewAuthenticationHandler(http.ErrorHandler(0))
|
2019-06-06 16:05:27 +00:00
|
|
|
h.AuthorizationService = service
|
|
|
|
th := http.NewTaskHandler(&http.TaskBackend{
|
2019-06-27 01:33:20 +00:00
|
|
|
HTTPErrorHandler: http.ErrorHandler(0),
|
2019-06-06 16:05:27 +00:00
|
|
|
Logger: zaptest.NewLogger(t).With(zap.String("handler", "task")),
|
|
|
|
TaskService: service,
|
|
|
|
AuthorizationService: service,
|
|
|
|
OrganizationService: service,
|
|
|
|
UserResourceMappingService: service,
|
|
|
|
LabelService: service,
|
|
|
|
UserService: service,
|
|
|
|
BucketService: service,
|
|
|
|
})
|
|
|
|
h.Handler = th
|
2018-10-23 17:51:13 +00:00
|
|
|
|
2019-06-06 16:05:27 +00:00
|
|
|
org := &platform.Organization{Name: t.Name() + "_org"}
|
|
|
|
if err := service.CreateOrganization(ctx, org); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
user := &platform.User{Name: t.Name() + "_user"}
|
|
|
|
if err := service.CreateUser(ctx, user); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
auth := platform.Authorization{UserID: user.ID, OrgID: org.ID}
|
|
|
|
if err := service.CreateAuthorization(ctx, &auth); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-10-23 17:51:13 +00:00
|
|
|
|
2019-06-06 16:05:27 +00:00
|
|
|
server := httptest.NewServer(h)
|
|
|
|
go func() {
|
|
|
|
<-ctx.Done()
|
|
|
|
server.Close()
|
|
|
|
}()
|
2018-10-23 17:51:13 +00:00
|
|
|
|
2019-06-06 16:05:27 +00:00
|
|
|
taskService := http.TaskService{
|
|
|
|
Addr: server.URL,
|
|
|
|
Token: auth.Token,
|
|
|
|
}
|
2018-10-23 17:51:13 +00:00
|
|
|
|
2019-06-06 16:05:27 +00:00
|
|
|
cFunc := func() (servicetest.TestCreds, error) {
|
|
|
|
return servicetest.TestCreds{
|
|
|
|
OrgID: org.ID,
|
|
|
|
Org: org.Name,
|
|
|
|
UserID: user.ID,
|
|
|
|
AuthorizationID: auth.ID,
|
|
|
|
Token: auth.Token,
|
|
|
|
}, nil
|
|
|
|
}
|
2018-10-23 17:51:13 +00:00
|
|
|
|
2019-06-06 16:05:27 +00:00
|
|
|
return &servicetest.System{
|
|
|
|
TaskControlService: service,
|
|
|
|
TaskService: taskService,
|
|
|
|
I: service,
|
|
|
|
Ctx: ctx,
|
|
|
|
CredsFunc: cFunc,
|
|
|
|
}, cancelFunc
|
|
|
|
},
|
|
|
|
"transactional",
|
|
|
|
)
|
2018-10-23 17:51:13 +00:00
|
|
|
}
|