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:
Seif Lotfy سيف لطفي
2017-02-10 01:31:39 +01:00
committed by Pedro Nasser
parent 6214f1711a
commit ab9428a937
5 changed files with 38 additions and 21 deletions

View File

@@ -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)
}
}