Fix unit tests due to missing mock MQ

This commit is contained in:
Seif Lotfy
2016-09-30 18:52:38 +02:00
parent c452d845fe
commit f5c4f5f7a9
6 changed files with 43 additions and 15 deletions

22
api/mqs/mock.go Normal file
View File

@@ -0,0 +1,22 @@
package mqs
import "github.com/iron-io/functions/api/models"
type Mock struct {
FakeApp *models.App
FakeApps []*models.App
FakeRoute *models.Route
FakeRoutes []*models.Route
}
func (mock *Mock) Push(*models.Task) (*models.Task, error) {
return nil, nil
}
func (mock *Mock) Reserve() (*models.Task, error) {
return nil, nil
}
func (mock *Mock) Delete(*models.Task) error {
return nil
}

View File

@@ -2,13 +2,14 @@ package runner
import ( import (
"bytes" "bytes"
"context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"time" "time"
"golang.org/x/net/context"
log "github.com/Sirupsen/logrus" log "github.com/Sirupsen/logrus"
"github.com/iron-io/functions/api/models" "github.com/iron-io/functions/api/models"

View File

@@ -8,10 +8,12 @@ import (
"github.com/iron-io/functions/api/datastore" "github.com/iron-io/functions/api/datastore"
"github.com/iron-io/functions/api/models" "github.com/iron-io/functions/api/models"
"github.com/iron-io/functions/api/mqs"
) )
func TestAppCreate(t *testing.T) { func TestAppCreate(t *testing.T) {
New(&datastore.Mock{}, testRunner(t))
New(&datastore.Mock{}, &mqs.Mock{}, testRunner(t))
router := testRouter() router := testRouter()
for i, test := range []struct { for i, test := range []struct {
@@ -52,7 +54,7 @@ func TestAppCreate(t *testing.T) {
} }
func TestAppDelete(t *testing.T) { func TestAppDelete(t *testing.T) {
New(&datastore.Mock{}, testRunner(t)) New(&datastore.Mock{}, &mqs.Mock{}, testRunner(t))
router := testRouter() router := testRouter()
for i, test := range []struct { for i, test := range []struct {
@@ -83,7 +85,7 @@ func TestAppDelete(t *testing.T) {
} }
func TestAppList(t *testing.T) { func TestAppList(t *testing.T) {
New(&datastore.Mock{}, testRunner(t)) New(&datastore.Mock{}, &mqs.Mock{}, testRunner(t))
router := testRouter() router := testRouter()
for i, test := range []struct { for i, test := range []struct {
@@ -113,7 +115,7 @@ func TestAppList(t *testing.T) {
} }
func TestAppGet(t *testing.T) { func TestAppGet(t *testing.T) {
New(&datastore.Mock{}, testRunner(t)) New(&datastore.Mock{}, &mqs.Mock{}, testRunner(t))
router := testRouter() router := testRouter()
for i, test := range []struct { for i, test := range []struct {
@@ -143,7 +145,7 @@ func TestAppGet(t *testing.T) {
} }
func TestAppUpdate(t *testing.T) { func TestAppUpdate(t *testing.T) {
New(&datastore.Mock{}, testRunner(t)) New(&datastore.Mock{}, &mqs.Mock{}, testRunner(t))
router := testRouter() router := testRouter()
for i, test := range []struct { for i, test := range []struct {

View File

@@ -8,10 +8,11 @@ import (
"github.com/iron-io/functions/api/datastore" "github.com/iron-io/functions/api/datastore"
"github.com/iron-io/functions/api/models" "github.com/iron-io/functions/api/models"
"github.com/iron-io/functions/api/mqs"
) )
func TestRouteCreate(t *testing.T) { func TestRouteCreate(t *testing.T) {
New(&datastore.Mock{}, testRunner(t)) New(&datastore.Mock{}, &mqs.Mock{}, testRunner(t))
router := testRouter() router := testRouter()
for i, test := range []struct { for i, test := range []struct {
@@ -52,7 +53,7 @@ func TestRouteCreate(t *testing.T) {
} }
func TestRouteDelete(t *testing.T) { func TestRouteDelete(t *testing.T) {
New(&datastore.Mock{}, testRunner(t)) New(&datastore.Mock{}, &mqs.Mock{}, testRunner(t))
router := testRouter() router := testRouter()
for i, test := range []struct { for i, test := range []struct {
@@ -83,7 +84,7 @@ func TestRouteDelete(t *testing.T) {
} }
func TestRouteList(t *testing.T) { func TestRouteList(t *testing.T) {
New(&datastore.Mock{}, testRunner(t)) New(&datastore.Mock{}, &mqs.Mock{}, testRunner(t))
router := testRouter() router := testRouter()
for i, test := range []struct { for i, test := range []struct {
@@ -113,7 +114,7 @@ func TestRouteList(t *testing.T) {
} }
func TestRouteGet(t *testing.T) { func TestRouteGet(t *testing.T) {
New(&datastore.Mock{}, testRunner(t)) New(&datastore.Mock{}, &mqs.Mock{}, testRunner(t))
router := testRouter() router := testRouter()
for i, test := range []struct { for i, test := range []struct {
@@ -143,7 +144,7 @@ func TestRouteGet(t *testing.T) {
} }
func TestRouteUpdate(t *testing.T) { func TestRouteUpdate(t *testing.T) {
New(&datastore.Mock{}, testRunner(t)) New(&datastore.Mock{}, &mqs.Mock{}, testRunner(t))
router := testRouter() router := testRouter()
for i, test := range []struct { for i, test := range []struct {

View File

@@ -9,6 +9,7 @@ import (
"github.com/iron-io/functions/api/datastore" "github.com/iron-io/functions/api/datastore"
"github.com/iron-io/functions/api/models" "github.com/iron-io/functions/api/models"
"github.com/iron-io/functions/api/mqs"
) )
func TestRouteRunnerGet(t *testing.T) { func TestRouteRunnerGet(t *testing.T) {
@@ -16,7 +17,7 @@ func TestRouteRunnerGet(t *testing.T) {
FakeApps: []*models.App{ FakeApps: []*models.App{
{Name: "myapp", Config: models.Config{}}, {Name: "myapp", Config: models.Config{}},
}, },
}, testRunner(t)) }, &mqs.Mock{}, testRunner(t))
router := testRouter() router := testRouter()
for i, test := range []struct { for i, test := range []struct {
@@ -54,7 +55,7 @@ func TestRouteRunnerPost(t *testing.T) {
FakeApps: []*models.App{ FakeApps: []*models.App{
{Name: "myapp", Config: models.Config{}}, {Name: "myapp", Config: models.Config{}},
}, },
}, testRunner(t)) }, &mqs.Mock{}, testRunner(t))
router := testRouter() router := testRouter()
for i, test := range []struct { for i, test := range []struct {
@@ -99,7 +100,7 @@ func TestRouteRunnerExecution(t *testing.T) {
{Path: "/myroute", AppName: "myapp", Image: "iron/hello", Headers: map[string][]string{"X-Function": []string{"Test"}}}, {Path: "/myroute", AppName: "myapp", Image: "iron/hello", Headers: map[string][]string{"X-Function": []string{"Test"}}},
{Path: "/myerror", AppName: "myapp", Image: "iron/error", Headers: map[string][]string{"X-Function": []string{"Test"}}}, {Path: "/myerror", AppName: "myapp", Image: "iron/error", Headers: map[string][]string{"X-Function": []string{"Test"}}},
}, },
}, testRunner(t)) }, &mqs.Mock{}, testRunner(t))
router := testRouter() router := testRouter()
for i, test := range []struct { for i, test := range []struct {

View File

@@ -8,6 +8,7 @@ import (
"github.com/iron-io/functions/api/datastore" "github.com/iron-io/functions/api/datastore"
"github.com/iron-io/functions/api/models" "github.com/iron-io/functions/api/models"
"github.com/iron-io/functions/api/mqs"
) )
var tmpBolt = "/tmp/func_test_bolt.db" var tmpBolt = "/tmp/func_test_bolt.db"
@@ -26,7 +27,7 @@ func TestFullStack(t *testing.T) {
ds, close := prepareBolt(t) ds, close := prepareBolt(t)
defer close() defer close()
New(ds, testRunner(t)) New(ds, &mqs.Mock{}, testRunner(t))
router := testRouter() router := testRouter()
for i, test := range []struct { for i, test := range []struct {