mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
remove gin, fix specialhandler and added test (#448)
This commit is contained in:
committed by
Travis Reeder
parent
1aea433d05
commit
63c2b18ac5
49
api/server/special_handler_test.go
Normal file
49
api/server/special_handler_test.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/iron-io/functions/api/datastore"
|
||||
"github.com/iron-io/functions/api/models"
|
||||
"github.com/iron-io/functions/api/mqs"
|
||||
"github.com/iron-io/functions/api/runner"
|
||||
"github.com/iron-io/functions/api/runner/task"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type testSpecialHandler struct{}
|
||||
|
||||
func (h *testSpecialHandler) Handle(c HandlerContext) error {
|
||||
c.Set("appName", "test")
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestSpecialHandlerSet(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
tasks := make(chan task.Request)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
rnr, cancelrnr := testRunner(t)
|
||||
defer cancelrnr()
|
||||
|
||||
go runner.StartWorkers(ctx, rnr, tasks)
|
||||
|
||||
s := New(ctx, &datastore.Mock{
|
||||
Apps: []*models.App{
|
||||
{Name: "test"},
|
||||
},
|
||||
Routes: []*models.Route{
|
||||
{Path: "/test", Image: "iron/hello", AppName: "test"},
|
||||
},
|
||||
}, &mqs.Mock{}, rnr, tasks, DefaultEnqueue)
|
||||
router := s.Router
|
||||
router.Use(prepareMiddleware(ctx))
|
||||
s.bindHandlers()
|
||||
s.AddSpecialHandler(&testSpecialHandler{})
|
||||
|
||||
_, rec := routerRequest(t, router, "GET", "/test", nil)
|
||||
if rec.Code != 200 {
|
||||
t.Fatal("Test SpecialHandler: expected special handler to run functions successfully")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user