mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Unskip tests (#516)
* Unskip tests * fix fn output for errors * Change Error model and add fn routes call return on error
This commit is contained in:
committed by
Pedro Nasser
parent
6214f1711a
commit
ab9428a937
@@ -12,6 +12,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"encoding/json"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/iron-io/functions/api"
|
||||
@@ -54,7 +56,7 @@ func (s *Server) handleSpecial(c *gin.Context) {
|
||||
s.handleRequest(c, nil)
|
||||
}
|
||||
|
||||
func ToEnvName(envtype, name string) string {
|
||||
func toEnvName(envtype, name string) string {
|
||||
name = strings.ToUpper(strings.Replace(name, "-", "_", -1))
|
||||
return fmt.Sprintf("%s_%s", envtype, name)
|
||||
}
|
||||
@@ -161,20 +163,20 @@ func (s *Server) serve(ctx context.Context, c *gin.Context, appName string, foun
|
||||
|
||||
// app config
|
||||
for k, v := range app.Config {
|
||||
envVars[ToEnvName("", k)] = v
|
||||
envVars[toEnvName("", k)] = v
|
||||
}
|
||||
for k, v := range found.Config {
|
||||
envVars[ToEnvName("", k)] = v
|
||||
envVars[toEnvName("", k)] = v
|
||||
}
|
||||
|
||||
// params
|
||||
for _, param := range params {
|
||||
envVars[ToEnvName("PARAM", param.Key)] = param.Value
|
||||
envVars[toEnvName("PARAM", param.Key)] = param.Value
|
||||
}
|
||||
|
||||
// headers
|
||||
for header, value := range c.Request.Header {
|
||||
envVars[ToEnvName("HEADER", header)] = strings.Join(value, " ")
|
||||
envVars[toEnvName("HEADER", header)] = strings.Join(value, " ")
|
||||
}
|
||||
|
||||
cfg := &task.Config{
|
||||
@@ -232,7 +234,17 @@ func (s *Server) serve(ctx context.Context, c *gin.Context, appName string, foun
|
||||
case "timeout":
|
||||
c.AbortWithStatus(http.StatusGatewayTimeout)
|
||||
default:
|
||||
c.AbortWithStatus(http.StatusInternalServerError)
|
||||
errMsg := &models.ErrorBody{
|
||||
Message: result.Error(),
|
||||
RequestID: cfg.ID,
|
||||
}
|
||||
|
||||
errStr, err := json.Marshal(errMsg)
|
||||
if err != nil {
|
||||
c.AbortWithStatus(http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
c.Data(http.StatusInternalServerError, "", errStr)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
"github.com/iron-io/functions/api/mqs"
|
||||
"github.com/iron-io/functions/api/runner"
|
||||
"github.com/iron-io/functions/api/runner/task"
|
||||
"github.com/iron-io/functions/api/server/internal/routecache"
|
||||
)
|
||||
|
||||
func testRouterAsync(ds models.Datastore, mq models.MessageQueue, rnr *runner.Runner, tasks chan task.Request, enqueue models.Enqueue) *gin.Engine {
|
||||
@@ -26,6 +27,7 @@ func testRouterAsync(ds models.Datastore, mq models.MessageQueue, rnr *runner.Ru
|
||||
MQ: mq,
|
||||
tasks: tasks,
|
||||
Enqueue: enqueue,
|
||||
hotroutes: routecache.New(10),
|
||||
}
|
||||
|
||||
r := s.Router
|
||||
@@ -37,7 +39,6 @@ func testRouterAsync(ds models.Datastore, mq models.MessageQueue, rnr *runner.Ru
|
||||
}
|
||||
|
||||
func TestRouteRunnerAsyncExecution(t *testing.T) {
|
||||
t.Skip()
|
||||
tasks := mockTasksConduit()
|
||||
ds := &datastore.Mock{
|
||||
Apps: []*models.App{
|
||||
@@ -58,24 +59,24 @@ func TestRouteRunnerAsyncExecution(t *testing.T) {
|
||||
expectedCode int
|
||||
expectedEnv map[string]string
|
||||
}{
|
||||
{"/r/myapp/myroute", ``, map[string][]string{}, http.StatusOK, map[string]string{"TEST": "true", "APP": "true"}},
|
||||
{"/r/myapp/myroute", ``, map[string][]string{}, http.StatusAccepted, map[string]string{"TEST": "true", "APP": "true"}},
|
||||
// FIXME: this just hangs
|
||||
//{"/r/myapp/myroute/1", ``, map[string][]string{}, http.StatusAccepted, map[string]string{"TEST": "true", "APP": "true"}},
|
||||
{"/r/myapp/myerror", ``, map[string][]string{}, http.StatusAccepted, map[string]string{"TEST": "true", "APP": "true"}},
|
||||
{"/r/myapp/myroute", `{ "name": "test" }`, map[string][]string{}, http.StatusAccepted, map[string]string{"TEST": "true", "APP": "true"}},
|
||||
{
|
||||
"/r/myapp/myroute/1",
|
||||
"/r/myapp/myroute",
|
||||
``,
|
||||
map[string][]string{"X-Function": []string{"test"}},
|
||||
http.StatusOK,
|
||||
http.StatusAccepted,
|
||||
map[string]string{
|
||||
"TEST": "true",
|
||||
"APP": "true",
|
||||
"PARAM_PARAM": "1",
|
||||
"HEADER_X_FUNCTION": "test",
|
||||
},
|
||||
},
|
||||
{"/r/myapp/myerror", ``, map[string][]string{}, http.StatusOK, map[string]string{"TEST": "true", "APP": "true"}},
|
||||
{"/r/myapp/myroute", `{ "name": "test" }`, map[string][]string{}, http.StatusOK, map[string]string{"TEST": "true", "APP": "true"}},
|
||||
} {
|
||||
body := bytes.NewBuffer([]byte(test.body))
|
||||
|
||||
var wg sync.WaitGroup
|
||||
|
||||
wg.Add(1)
|
||||
@@ -88,9 +89,13 @@ func TestRouteRunnerAsyncExecution(t *testing.T) {
|
||||
|
||||
if test.expectedEnv != nil {
|
||||
for name, value := range test.expectedEnv {
|
||||
if value != task.EnvVars[name] {
|
||||
taskName := name
|
||||
if name == "APP" || name == "TEST" {
|
||||
taskName = fmt.Sprintf("_%s", name)
|
||||
}
|
||||
if value != task.EnvVars[taskName] {
|
||||
t.Errorf("Test %d: Expected header `%s` to be `%s` but was `%s`",
|
||||
i, name, value, task.EnvVars[name])
|
||||
i, name, value, task.EnvVars[taskName])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user