mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Merge pull request #47 from pedronasser/fix-tests-and-mock
fix mock and tests
This commit is contained in:
@@ -8,15 +8,19 @@ import (
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"golang.org/x/net/context"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/iron-io/functions/api/models"
|
||||
titancommon "github.com/iron-io/titan/common"
|
||||
)
|
||||
|
||||
func testRouter() *gin.Engine {
|
||||
r := gin.Default()
|
||||
ctx := context.Background()
|
||||
r.Use(func(c *gin.Context) {
|
||||
c.Set("log", logrus.WithFields(logrus.Fields{}))
|
||||
ctx, _ := titancommon.LoggerWithFields(ctx, extractFields(c))
|
||||
c.Set("ctx", ctx)
|
||||
c.Next()
|
||||
})
|
||||
bindHandlers(r)
|
||||
|
||||
@@ -2,6 +2,7 @@ package server
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -20,7 +21,7 @@ func TestRouteRunnerGet(t *testing.T) {
|
||||
expectedCode int
|
||||
expectedError error
|
||||
}{
|
||||
{"/route", "", http.StatusNotFound, models.ErrRunnerRouteNotFound},
|
||||
{"/route", "", http.StatusBadRequest, models.ErrAppsNotFound},
|
||||
{"/r/app/route", "", http.StatusNotFound, models.ErrRunnerRouteNotFound},
|
||||
{"/route?payload=test", "", http.StatusBadRequest, models.ErrInvalidJSON},
|
||||
{"/r/app/route?payload=test", "", http.StatusBadRequest, models.ErrInvalidJSON},
|
||||
@@ -55,7 +56,7 @@ func TestRouteRunnerPost(t *testing.T) {
|
||||
}{
|
||||
{"/route", `payload`, http.StatusBadRequest, models.ErrInvalidJSON},
|
||||
{"/r/app/route", `payload`, http.StatusBadRequest, models.ErrInvalidJSON},
|
||||
{"/route", `{ "payload": "" }`, http.StatusNotFound, models.ErrRunnerRouteNotFound},
|
||||
{"/route", `{ "payload": "" }`, http.StatusBadRequest, models.ErrAppsNotFound},
|
||||
{"/r/app/route", `{ "payload": "" }`, http.StatusNotFound, models.ErrRunnerRouteNotFound},
|
||||
} {
|
||||
body := bytes.NewBuffer([]byte(test.body))
|
||||
@@ -68,8 +69,10 @@ func TestRouteRunnerPost(t *testing.T) {
|
||||
|
||||
if test.expectedError != nil {
|
||||
resp := getErrorResponse(t, rec)
|
||||
|
||||
if !strings.Contains(resp.Error.Message, test.expectedError.Error()) {
|
||||
respMsg := resp.Error.Message
|
||||
expMsg := test.expectedError.Error()
|
||||
fmt.Println(respMsg == expMsg)
|
||||
if respMsg != expMsg && !strings.Contains(respMsg, expMsg) {
|
||||
t.Errorf("Test %d: Expected error message to have `%s`",
|
||||
i, test.expectedError.Error())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user