// NewWorkItemLinkController creates a work-item-link controller. func NewWorkItemLinkController(service *goa.Service, db application.DB) *WorkItemLinkController { if db == nil { panic("db must not be nil") } return &WorkItemLinkController{ Controller: service.NewController("WorkItemLinkController"), db: db, } }
// MountPreflightController mounts the handlers for the CORS preflight requests onto service. func MountPreflightController(service goa.Service, spec Specification) { for _, res := range spec { path := res.Path if res.IsPathPrefix { if strings.HasSuffix(path, "/") { path += "*cors" } else { path += "/*cors" } } handle := service.ServeMux().Lookup("OPTIONS", path) if handle == nil { h := func(ctx *goa.Context) error { return ctx.Respond(200, nil) } ctrl := service.NewController("cors") service.ServeMux().Handle("OPTIONS", path, ctrl.HandleFunc("preflight", h, nil)) } } }
// NewSearchController creates a search controller. func NewSearchController(service *goa.Service, db application.DB) *SearchController { if db == nil { panic("db must not be nil") } return &SearchController{Controller: service.NewController("SearchController"), db: db} }
// NewStatusController creates a status controller. func NewStatusController(service *goa.Service, db *gorm.DB) *StatusController { return &StatusController{ Controller: service.NewController("StatusController"), db: db, } }
It("returns the middleware", func() { Ω(fmt.Sprintf("%#v", middleware)).Should(Equal(fmt.Sprintf("%#v", goa.Middleware(goaMiddlewareFunc)))) Ω(mErr).ShouldNot(HaveOccurred()) }) }) Context("with a context", func() { var service *goa.Service var req *http.Request var rw http.ResponseWriter var ctx context.Context BeforeEach(func() { service = goa.New("test") ctrl := service.NewController("foo") var err error req, err = http.NewRequest("GET", "/goo", nil) Ω(err).ShouldNot(HaveOccurred()) rw = new(TestResponseWriter) ctx = goa.NewContext(ctrl.Context, rw, req, nil) Ω(goa.ContextResponse(ctx).Status).Should(Equal(0)) }) Context("using a goa handler", func() { BeforeEach(func() { var goaHandler goa.Handler = func(ctx context.Context, rw http.ResponseWriter, req *http.Request) error { service.Send(ctx, 200, "ok") return nil } input = goaHandler
// NewIdentityController creates a identity controller. func NewIdentityController(service *goa.Service, db application.DB) *IdentityController { return &IdentityController{Controller: service.NewController("IdentityController"), db: db} }
// NewOperandsController creates a operands controller. func NewOperandsController(service *goa.Service) *OperandsController { return &OperandsController{Controller: service.NewController("operands")} }
// NewAreaController creates a area controller. func NewAreaController(service *goa.Service, db application.DB) *AreaController { return &AreaController{Controller: service.NewController("AreaController"), db: db} }
// Creates a test context func newContext(service *goa.Service, rw http.ResponseWriter, req *http.Request, params url.Values) context.Context { ctrl := service.NewController("test") return goa.NewContext(ctrl.Context, rw, req, params) }
// NewWorkItemCommentsController creates a work-item-relationships-comments controller. func NewWorkItemCommentsController(service *goa.Service, db application.DB) *WorkItemCommentsController { return &WorkItemCommentsController{Controller: service.NewController("WorkItemRelationshipsCommentsController"), db: db} }
// NewUserController creates a user controller. func NewUserController(service *goa.Service, db application.DB, tokenManager token.Manager) *UserController { return &UserController{Controller: service.NewController("UserController"), db: db, tokenManager: tokenManager} }
// NewSpaceIterationsController creates a space-iterations controller. func NewSpaceIterationsController(service *goa.Service, db application.DB) *SpaceIterationsController { return &SpaceIterationsController{Controller: service.NewController("SpaceIterationsController"), db: db} }
// NewIterationController creates a iteration controller. func NewIterationController(service *goa.Service, db application.DB) *IterationController { return &IterationController{Controller: service.NewController("IterationController"), db: db} }
// NewUserspaceController creates a userspace controller. func NewUserspaceController(service *goa.Service, db *gorm.DB) *UserspaceController { db.AutoMigrate(&Data{}).AddUniqueIndex("idx_userspace_path", "path") return &UserspaceController{Controller: service.NewController("UserspaceController"), db: db} }
// NewSwaggerController creates a swagger controller. func NewSwaggerController(service *goa.Service) *SwaggerController { return &SwaggerController{Controller: service.NewController("SwaggerController")} }
// NewAuthenticationController creates a authentication controller. func NewAuthenticationController(service *goa.Service) *AuthenticationController { return &AuthenticationController{Controller: service.NewController("authentication")} }
// NewRenderController creates a render controller. func NewRenderController(service *goa.Service) *RenderController { return &RenderController{Controller: service.NewController("RenderController")} }
// NewWorkitemtypeController creates a workitemtype controller. func NewWorkitemtypeController(service *goa.Service, db application.DB) *WorkitemtypeController { return &WorkitemtypeController{ Controller: service.NewController("WorkitemtypeController"), db: db, } }
var params url.Values var logger *testLogger var service *goa.Service payload := map[string]interface{}{"payload": 42} BeforeEach(func() { logger = new(testLogger) service = newService(logger) var err error req, err = http.NewRequest("POST", "/goo?param=value", strings.NewReader(`{"payload":42}`)) Ω(err).ShouldNot(HaveOccurred()) rw = new(testResponseWriter) params = url.Values{"query": []string{"value"}} ctrl := service.NewController("test") ctx = goa.NewContext(ctrl.Context, rw, req, params) goa.ContextRequest(ctx).Payload = payload }) It("logs requests", func() { // Add Action name to the context to make sure we log it properly. ctx = goa.WithAction(ctx, "goo") h := func(ctx context.Context, rw http.ResponseWriter, req *http.Request) error { return service.Send(ctx, 200, "ok") } lg := middleware.LogRequest(true)(h) Ω(lg(ctx, rw, req)).ShouldNot(HaveOccurred()) Ω(logger.InfoEntries).Should(HaveLen(4))
// NewUsersController creates a users controller. func NewUsersController(service *goa.Service, db application.DB) *UsersController { return &UsersController{Controller: service.NewController("UsersController"), db: db} }
} c.SetPayload(payload) } return nil } var err error reader := strings.NewReader(reqBody) request, err = http.NewRequest("POST", "/foo?filters=one&filters=two&filters=three", reader) request.Header.Set("Content-Type", "application/json") Ω(err).ShouldNot(HaveOccurred()) rw = new(TestResponseWriter) params = url.Values{"id": []string{"42"}, "filters": []string{"one", "two", "three"}} }) JustBeforeEach(func() { ctrl := app.NewController(resName) handleFunc = ctrl.HandleFunc(actName, handler, unmarshaler) handleFunc(rw, request, params) }) Describe("RespondBytes", func() { It("sets the context fields", func() { Ω(ctx.Request()).Should(Equal(request)) Ω(ctx.Header()).Should(Equal(rw.Header())) Ω(ctx.ResponseStatus()).Should(Equal(respStatus)) Ω(ctx.ResponseLength()).Should(Equal(len(respContent))) p := ctx.Get("id") Ω(p).Should(Equal("42")) ps := ctx.GetMany("filters") Ω(ps).Should(Equal([]string{"one", "two", "three"})) var payload string
}) Describe("Use", func() { Context("with a valid middleware", func() { var m goa.Middleware BeforeEach(func() { m = middleware.RequestID() }) JustBeforeEach(func() { s.Use(m) }) It("adds the middleware", func() { ctrl := s.NewController("test") Ω(ctrl.MiddlewareChain()).Should(HaveLen(1)) Ω(ctrl.MiddlewareChain()[0]).Should(BeAssignableToTypeOf(middleware.RequestID())) }) }) }) Describe("HandleFunc", func() { const resName = "res" const actName = "act" var handler, unmarshaler goa.Handler const respStatus = 200 var respContent = []byte("response") var handleFunc goa.HandleFunc var ctx *goa.Context
// NewBottleController creates a bottle controller. func NewBottleController(service *goa.Service) *BottleController { return &BottleController{Controller: service.NewController("BottleController")} }
// NewAeController creates a ae controller. func NewAeController(service *goa.Service) *AeController { return &AeController{Controller: service.NewController("AeController")} }
// NewLoginController creates a login controller. func NewLoginController(service *goa.Service, auth *login.KeycloakOAuthProvider, tokenManager token.Manager) *LoginController { return &LoginController{Controller: service.NewController("login"), auth: auth, tokenManager: tokenManager} }
// NewTrackerqueryController creates a trackerquery controller. func NewTrackerqueryController(service *goa.Service, db application.DB, scheduler *remoteworkitem.Scheduler) *TrackerqueryController { return &TrackerqueryController{Controller: service.NewController("TrackerqueryController"), db: db, scheduler: scheduler} }
// NewCommentsController creates a comments controller. func NewCommentsController(service *goa.Service, db application.DB) *CommentsController { return &CommentsController{Controller: service.NewController("CommentsController"), db: db} }