Merge pull request #47 from pedronasser/fix-tests-and-mock

fix mock and tests
This commit is contained in:
Travis Reeder
2016-08-11 08:39:25 -07:00
committed by GitHub
3 changed files with 21 additions and 6 deletions

View File

@@ -40,3 +40,11 @@ func (m *Mock) StoreRoute(route *models.Route) (*models.Route, error) {
func (m *Mock) RemoveRoute(app, route string) error {
return nil
}
func (m *Mock) Put(key, value []byte) error {
return nil
}
func (m *Mock) Get(key []byte) ([]byte, error) {
return []byte{}, nil
}

View File

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

View File

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