mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Reduce test log verbosity (#150)
* Reduce test verbosity * Divert gin's log to the test buffer * Divert stdlib's log to the test buffer * Add bolt tests into log buffer * Add a linebreak to improve log output layout
This commit is contained in:
committed by
Seif Lotfy سيف لطفي
parent
5a1d9d4825
commit
4cbfb3ccfd
@@ -1,27 +1,35 @@
|
|||||||
package datastore
|
package datastore
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/Sirupsen/logrus"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/iron-io/functions/api/models"
|
"github.com/iron-io/functions/api/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
var tmpBolt = "/tmp/func_test_bolt.db"
|
func setLogBuffer() *bytes.Buffer {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
buf.WriteByte('\n')
|
||||||
|
logrus.SetOutput(&buf)
|
||||||
|
gin.DefaultErrorWriter = &buf
|
||||||
|
gin.DefaultWriter = &buf
|
||||||
|
log.SetOutput(&buf)
|
||||||
|
return &buf
|
||||||
|
}
|
||||||
|
|
||||||
func prepareBolt(t *testing.T) (models.Datastore, func()) {
|
func TestBolt(t *testing.T) {
|
||||||
|
buf := setLogBuffer()
|
||||||
|
|
||||||
|
const tmpBolt = "/tmp/func_test_bolt.db"
|
||||||
ds, err := New("bolt://" + tmpBolt)
|
ds, err := New("bolt://" + tmpBolt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("Error when creating datastore: %s", err)
|
t.Fatal("Error when creating datastore: %s", err)
|
||||||
}
|
}
|
||||||
return ds, func() {
|
defer os.Remove(tmpBolt)
|
||||||
os.Remove(tmpBolt)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestBolt(t *testing.T) {
|
|
||||||
ds, close := prepareBolt(t)
|
|
||||||
defer close()
|
|
||||||
|
|
||||||
testApp := &models.App{
|
testApp := &models.App{
|
||||||
Name: "Test",
|
Name: "Test",
|
||||||
@@ -34,57 +42,68 @@ func TestBolt(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Testing store app
|
// Testing store app
|
||||||
_, err := ds.StoreApp(nil)
|
_, err = ds.StoreApp(nil)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Fatalf("Test StoreApp: expected error when using nil app", err)
|
t.Fatalf("Test StoreApp: expected error when using nil app", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = ds.StoreApp(testApp)
|
_, err = ds.StoreApp(testApp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Fatalf("Test StoreApp: error when Bolt was storing new app: %s", err)
|
t.Fatalf("Test StoreApp: error when Bolt was storing new app: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Testing get app
|
// Testing get app
|
||||||
_, err = ds.GetApp("")
|
_, err = ds.GetApp("")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Fatalf("Test GetApp: expected error when using empty app name", err)
|
t.Fatalf("Test GetApp: expected error when using empty app name", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
app, err := ds.GetApp(testApp.Name)
|
app, err := ds.GetApp(testApp.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Fatalf("Test GetApp: error: %s", err)
|
t.Fatalf("Test GetApp: error: %s", err)
|
||||||
}
|
}
|
||||||
if app.Name != testApp.Name {
|
if app.Name != testApp.Name {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Fatalf("Test GetApp: expected `app.Name` to be `%s` but it was `%s`", app.Name, testApp.Name)
|
t.Fatalf("Test GetApp: expected `app.Name` to be `%s` but it was `%s`", app.Name, testApp.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Testing list apps
|
// Testing list apps
|
||||||
apps, err := ds.GetApps(&models.AppFilter{})
|
apps, err := ds.GetApps(&models.AppFilter{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Fatalf("Test GetApps: error: %s", err)
|
t.Fatalf("Test GetApps: error: %s", err)
|
||||||
}
|
}
|
||||||
if len(apps) == 0 {
|
if len(apps) == 0 {
|
||||||
t.Fatal("Test GetApps: expected result count to be greater than 0")
|
t.Fatal("Test GetApps: expected result count to be greater than 0")
|
||||||
}
|
}
|
||||||
if apps[0].Name != testApp.Name {
|
if apps[0].Name != testApp.Name {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Fatalf("Test GetApps: expected `app.Name` to be `%s` but it was `%s`", app.Name, testApp.Name)
|
t.Fatalf("Test GetApps: expected `app.Name` to be `%s` but it was `%s`", app.Name, testApp.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Testing app delete
|
// Testing app delete
|
||||||
err = ds.RemoveApp("")
|
err = ds.RemoveApp("")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Fatalf("Test RemoveApp: expected error when using empty app name", err)
|
t.Fatalf("Test RemoveApp: expected error when using empty app name", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = ds.RemoveApp(testApp.Name)
|
err = ds.RemoveApp(testApp.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Fatalf("Test RemoveApp: error: %s", err)
|
t.Fatalf("Test RemoveApp: error: %s", err)
|
||||||
}
|
}
|
||||||
app, err = ds.GetApp(testApp.Name)
|
app, err = ds.GetApp(testApp.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Fatalf("Test GetApp: error: %s", err)
|
t.Fatalf("Test GetApp: error: %s", err)
|
||||||
}
|
}
|
||||||
if app != nil {
|
if app != nil {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Fatalf("Test RemoveApp: failed to remove the app")
|
t.Fatalf("Test RemoveApp: failed to remove the app")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,78 +113,93 @@ func TestBolt(t *testing.T) {
|
|||||||
// Testing store route
|
// Testing store route
|
||||||
_, err = ds.StoreRoute(nil)
|
_, err = ds.StoreRoute(nil)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Fatalf("Test StoreRoute: expected error when using nil route", err)
|
t.Fatalf("Test StoreRoute: expected error when using nil route", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = ds.StoreRoute(testRoute)
|
_, err = ds.StoreRoute(testRoute)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Fatalf("Test StoreReoute: error when Bolt was storing new route: %s", err)
|
t.Fatalf("Test StoreReoute: error when Bolt was storing new route: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Testing get
|
// Testing get
|
||||||
_, err = ds.GetRoute("a", "")
|
_, err = ds.GetRoute("a", "")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Fatalf("Test GetRoute: expected error when using empty route name", err)
|
t.Fatalf("Test GetRoute: expected error when using empty route name", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = ds.GetRoute("", "a")
|
_, err = ds.GetRoute("", "a")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Fatalf("Test GetRoute: expected error when using empty app name", err)
|
t.Fatalf("Test GetRoute: expected error when using empty app name", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
route, err := ds.GetRoute(testApp.Name, testRoute.Path)
|
route, err := ds.GetRoute(testApp.Name, testRoute.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Fatalf("Test GetRoute: error: %s", err)
|
t.Fatalf("Test GetRoute: error: %s", err)
|
||||||
}
|
}
|
||||||
if route.Path != testRoute.Path {
|
if route.Path != testRoute.Path {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Fatalf("Test GetRoute: expected `route.Path` to be `%s` but it was `%s`", route.Path, testRoute.Path)
|
t.Fatalf("Test GetRoute: expected `route.Path` to be `%s` but it was `%s`", route.Path, testRoute.Path)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Testing list routes
|
// Testing list routes
|
||||||
routes, err := ds.GetRoutesByApp(testApp.Name, &models.RouteFilter{})
|
routes, err := ds.GetRoutesByApp(testApp.Name, &models.RouteFilter{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Fatalf("Test GetRoutes: error: %s", err)
|
t.Fatalf("Test GetRoutes: error: %s", err)
|
||||||
}
|
}
|
||||||
if len(routes) == 0 {
|
if len(routes) == 0 {
|
||||||
t.Fatal("Test GetRoutes: expected result count to be greater than 0")
|
t.Fatal("Test GetRoutes: expected result count to be greater than 0")
|
||||||
}
|
}
|
||||||
if routes[0].Path != testRoute.Path {
|
if routes[0].Path != testRoute.Path {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Fatalf("Test GetRoutes: expected `app.Name` to be `%s` but it was `%s`", testRoute.Path, routes[0].Path)
|
t.Fatalf("Test GetRoutes: expected `app.Name` to be `%s` but it was `%s`", testRoute.Path, routes[0].Path)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Testing list routes
|
// Testing list routes
|
||||||
routes, err = ds.GetRoutes(&models.RouteFilter{Image: testRoute.Image})
|
routes, err = ds.GetRoutes(&models.RouteFilter{Image: testRoute.Image})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Fatalf("Test GetRoutes: error: %s", err)
|
t.Fatalf("Test GetRoutes: error: %s", err)
|
||||||
}
|
}
|
||||||
if len(routes) == 0 {
|
if len(routes) == 0 {
|
||||||
t.Fatal("Test GetRoutes: expected result count to be greater than 0")
|
t.Fatal("Test GetRoutes: expected result count to be greater than 0")
|
||||||
}
|
}
|
||||||
if routes[0].Path != testRoute.Path {
|
if routes[0].Path != testRoute.Path {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Fatalf("Test GetRoutes: expected `app.Name` to be `%s` but it was `%s`", testRoute.Path, routes[0].Path)
|
t.Fatalf("Test GetRoutes: expected `app.Name` to be `%s` but it was `%s`", testRoute.Path, routes[0].Path)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Testing app delete
|
// Testing app delete
|
||||||
err = ds.RemoveRoute("", "")
|
err = ds.RemoveRoute("", "")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Fatalf("Test RemoveRoute: expected error when using empty app name", err)
|
t.Fatalf("Test RemoveRoute: expected error when using empty app name", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = ds.RemoveRoute("a", "")
|
err = ds.RemoveRoute("a", "")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Fatalf("Test RemoveRoute: expected error when using empty route name", err)
|
t.Fatalf("Test RemoveRoute: expected error when using empty route name", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = ds.RemoveRoute(testRoute.AppName, testRoute.Path)
|
err = ds.RemoveRoute(testRoute.AppName, testRoute.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Fatalf("Test RemoveApp: error: %s", err)
|
t.Fatalf("Test RemoveApp: error: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
route, err = ds.GetRoute(testRoute.AppName, testRoute.Path)
|
route, err = ds.GetRoute(testRoute.AppName, testRoute.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Fatalf("Test GetRoute: error: %s", err)
|
t.Fatalf("Test GetRoute: error: %s", err)
|
||||||
}
|
}
|
||||||
if route != nil {
|
if route != nil {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Fatalf("Test RemoveApp: failed to remove the route")
|
t.Fatalf("Test RemoveApp: failed to remove the route")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
package runner
|
package runner
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
@@ -19,6 +21,16 @@ import (
|
|||||||
"github.com/iron-io/runner/drivers"
|
"github.com/iron-io/runner/drivers"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func setLogBuffer() *bytes.Buffer {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
buf.WriteByte('\n')
|
||||||
|
logrus.SetOutput(&buf)
|
||||||
|
gin.DefaultErrorWriter = &buf
|
||||||
|
gin.DefaultWriter = &buf
|
||||||
|
log.SetOutput(&buf)
|
||||||
|
return &buf
|
||||||
|
}
|
||||||
|
|
||||||
func getMockTask() models.Task {
|
func getMockTask() models.Task {
|
||||||
priority := int32(0)
|
priority := int32(0)
|
||||||
image := fmt.Sprintf("Image-%d", rand.Int31()%1000)
|
image := fmt.Sprintf("Image-%d", rand.Int31()%1000)
|
||||||
@@ -97,6 +109,7 @@ func TestRunTask(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestGetTask(t *testing.T) {
|
func TestGetTask(t *testing.T) {
|
||||||
|
buf := setLogBuffer()
|
||||||
mockTask := getMockTask()
|
mockTask := getMockTask()
|
||||||
|
|
||||||
ts := getTestServer([]*models.Task{&mockTask})
|
ts := getTestServer([]*models.Task{&mockTask})
|
||||||
@@ -105,14 +118,18 @@ func TestGetTask(t *testing.T) {
|
|||||||
url := ts.URL + "/tasks"
|
url := ts.URL + "/tasks"
|
||||||
task, err := getTask(url)
|
task, err := getTask(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Error("expected no error, got", err)
|
t.Error("expected no error, got", err)
|
||||||
}
|
}
|
||||||
if task.ID != mockTask.ID {
|
if task.ID != mockTask.ID {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Errorf("expected task ID '%s', got '%s'", task.ID, mockTask.ID)
|
t.Errorf("expected task ID '%s', got '%s'", task.ID, mockTask.ID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetTaskError(t *testing.T) {
|
func TestGetTaskError(t *testing.T) {
|
||||||
|
buf := setLogBuffer()
|
||||||
|
|
||||||
tests := []map[string]interface{}{
|
tests := []map[string]interface{}{
|
||||||
{
|
{
|
||||||
"url": "/invalid",
|
"url": "/invalid",
|
||||||
@@ -134,15 +151,18 @@ func TestGetTaskError(t *testing.T) {
|
|||||||
url := ts.URL + test["url"].(string)
|
url := ts.URL + test["url"].(string)
|
||||||
_, err := getTask(url)
|
_, err := getTask(url)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Errorf("expected error '%s'", test["error"].(string))
|
t.Errorf("expected error '%s'", test["error"].(string))
|
||||||
}
|
}
|
||||||
if err.Error() != test["error"].(string) {
|
if err.Error() != test["error"].(string) {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Errorf("test %d: expected error '%s', got '%s'", i, test["error"].(string), err)
|
t.Errorf("test %d: expected error '%s', got '%s'", i, test["error"].(string), err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDeleteTask(t *testing.T) {
|
func TestDeleteTask(t *testing.T) {
|
||||||
|
buf := setLogBuffer()
|
||||||
mockTask := getMockTask()
|
mockTask := getMockTask()
|
||||||
|
|
||||||
ts := getTestServer([]*models.Task{&mockTask})
|
ts := getTestServer([]*models.Task{&mockTask})
|
||||||
@@ -151,16 +171,19 @@ func TestDeleteTask(t *testing.T) {
|
|||||||
url := ts.URL + "/tasks"
|
url := ts.URL + "/tasks"
|
||||||
err := deleteTask(url, &mockTask)
|
err := deleteTask(url, &mockTask)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Error("expected error 'Not reserver', got", err)
|
t.Error("expected error 'Not reserver', got", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = getTask(url)
|
_, err = getTask(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Error("expected no error, got", err)
|
t.Error("expected no error, got", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = deleteTask(url, &mockTask)
|
err = deleteTask(url, &mockTask)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Error("expected no error, got", err)
|
t.Error("expected no error, got", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -188,6 +211,7 @@ func TestTasksrvURL(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAsyncRunnersGracefulShutdown(t *testing.T) {
|
func TestAsyncRunnersGracefulShutdown(t *testing.T) {
|
||||||
|
buf := setLogBuffer()
|
||||||
mockTask := getMockTask()
|
mockTask := getMockTask()
|
||||||
ts := getTestServer([]*models.Task{&mockTask})
|
ts := getTestServer([]*models.Task{&mockTask})
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
@@ -201,6 +225,7 @@ func TestAsyncRunnersGracefulShutdown(t *testing.T) {
|
|||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|
||||||
if err := ctx.Err(); err != context.DeadlineExceeded {
|
if err := ctx.Err(); err != context.DeadlineExceeded {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Errorf("async runners stopped unexpectedly. context error: %v", err)
|
t.Errorf("async runners stopped unexpectedly. context error: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestRunnerHello(t *testing.T) {
|
func TestRunnerHello(t *testing.T) {
|
||||||
|
buf := setLogBuffer()
|
||||||
runner, err := New(NewMetricLogger())
|
runner, err := New(NewMetricLogger())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Test error during New() - %s", err)
|
t.Fatalf("Test error during New() - %s", err)
|
||||||
@@ -41,24 +42,29 @@ func TestRunnerHello(t *testing.T) {
|
|||||||
|
|
||||||
result, err := runner.Run(ctx, cfg)
|
result, err := runner.Run(ctx, cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Fatalf("Test %d: error during Run() - %s", i, err)
|
t.Fatalf("Test %d: error during Run() - %s", i, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if test.expectedStatus != result.Status() {
|
if test.expectedStatus != result.Status() {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Fatalf("Test %d: expected result status to be `%s` but it was `%s`", i, test.expectedStatus, result.Status())
|
t.Fatalf("Test %d: expected result status to be `%s` but it was `%s`", i, test.expectedStatus, result.Status())
|
||||||
}
|
}
|
||||||
|
|
||||||
if !bytes.Contains(stdout.Bytes(), []byte(test.expectedOut)) {
|
if !bytes.Contains(stdout.Bytes(), []byte(test.expectedOut)) {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Fatalf("Test %d: expected output log to contain `%s` in `%s`", i, test.expectedOut, stdout.String())
|
t.Fatalf("Test %d: expected output log to contain `%s` in `%s`", i, test.expectedOut, stdout.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
if !bytes.Contains(stderr.Bytes(), []byte(test.expectedErr)) {
|
if !bytes.Contains(stderr.Bytes(), []byte(test.expectedErr)) {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Fatalf("Test %d: expected error log to contain `%s` in `%s`", i, test.expectedErr, stderr.String())
|
t.Fatalf("Test %d: expected error log to contain `%s` in `%s`", i, test.expectedErr, stderr.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunnerError(t *testing.T) {
|
func TestRunnerError(t *testing.T) {
|
||||||
|
buf := setLogBuffer()
|
||||||
runner, err := New(NewMetricLogger())
|
runner, err := New(NewMetricLogger())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Test error during New() - %s", err)
|
t.Fatalf("Test error during New() - %s", err)
|
||||||
@@ -88,18 +94,22 @@ func TestRunnerError(t *testing.T) {
|
|||||||
|
|
||||||
result, err := runner.Run(ctx, cfg)
|
result, err := runner.Run(ctx, cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Fatalf("Test %d: error during Run() - %s", i, err)
|
t.Fatalf("Test %d: error during Run() - %s", i, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if test.expectedStatus != result.Status() {
|
if test.expectedStatus != result.Status() {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Fatalf("Test %d: expected result status to be `%s` but it was `%s`", i, test.expectedStatus, result.Status())
|
t.Fatalf("Test %d: expected result status to be `%s` but it was `%s`", i, test.expectedStatus, result.Status())
|
||||||
}
|
}
|
||||||
|
|
||||||
if !bytes.Contains(stdout.Bytes(), []byte(test.expectedOut)) {
|
if !bytes.Contains(stdout.Bytes(), []byte(test.expectedOut)) {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Fatalf("Test %d: expected output log to contain `%s` in `%s`", i, test.expectedOut, stdout.String())
|
t.Fatalf("Test %d: expected output log to contain `%s` in `%s`", i, test.expectedOut, stdout.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
if !bytes.Contains(stderr.Bytes(), []byte(test.expectedErr)) {
|
if !bytes.Contains(stderr.Bytes(), []byte(test.expectedErr)) {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Fatalf("Test %d: expected error log to contain `%s` in `%s`", i, test.expectedErr, stderr.String())
|
t.Fatalf("Test %d: expected error log to contain `%s` in `%s`", i, test.expectedErr, stderr.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,17 +2,30 @@ package server
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/Sirupsen/logrus"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
"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"
|
"github.com/iron-io/functions/api/mqs"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAppCreate(t *testing.T) {
|
func setLogBuffer() *bytes.Buffer {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
buf.WriteByte('\n')
|
||||||
|
logrus.SetOutput(&buf)
|
||||||
|
gin.DefaultErrorWriter = &buf
|
||||||
|
gin.DefaultWriter = &buf
|
||||||
|
log.SetOutput(&buf)
|
||||||
|
return &buf
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAppCreate(t *testing.T) {
|
||||||
|
buf := setLogBuffer()
|
||||||
New(&datastore.Mock{}, &mqs.Mock{}, testRunner(t))
|
New(&datastore.Mock{}, &mqs.Mock{}, testRunner(t))
|
||||||
router := testRouter()
|
router := testRouter()
|
||||||
|
|
||||||
@@ -38,6 +51,7 @@ func TestAppCreate(t *testing.T) {
|
|||||||
_, rec := routerRequest(t, router, "POST", test.path, body)
|
_, rec := routerRequest(t, router, "POST", test.path, body)
|
||||||
|
|
||||||
if rec.Code != test.expectedCode {
|
if rec.Code != test.expectedCode {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Errorf("Test %d: Expected status code to be %d but was %d",
|
t.Errorf("Test %d: Expected status code to be %d but was %d",
|
||||||
i, test.expectedCode, rec.Code)
|
i, test.expectedCode, rec.Code)
|
||||||
}
|
}
|
||||||
@@ -46,6 +60,7 @@ func TestAppCreate(t *testing.T) {
|
|||||||
resp := getErrorResponse(t, rec)
|
resp := getErrorResponse(t, rec)
|
||||||
|
|
||||||
if !strings.Contains(resp.Error.Message, test.expectedError.Error()) {
|
if !strings.Contains(resp.Error.Message, test.expectedError.Error()) {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Errorf("Test %d: Expected error message to have `%s`",
|
t.Errorf("Test %d: Expected error message to have `%s`",
|
||||||
i, test.expectedError.Error())
|
i, test.expectedError.Error())
|
||||||
}
|
}
|
||||||
@@ -54,6 +69,7 @@ func TestAppCreate(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAppDelete(t *testing.T) {
|
func TestAppDelete(t *testing.T) {
|
||||||
|
buf := setLogBuffer()
|
||||||
New(&datastore.Mock{}, &mqs.Mock{}, testRunner(t))
|
New(&datastore.Mock{}, &mqs.Mock{}, testRunner(t))
|
||||||
router := testRouter()
|
router := testRouter()
|
||||||
|
|
||||||
@@ -69,6 +85,7 @@ func TestAppDelete(t *testing.T) {
|
|||||||
_, rec := routerRequest(t, router, "DELETE", test.path, nil)
|
_, rec := routerRequest(t, router, "DELETE", test.path, nil)
|
||||||
|
|
||||||
if rec.Code != test.expectedCode {
|
if rec.Code != test.expectedCode {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Errorf("Test %d: Expected status code to be %d but was %d",
|
t.Errorf("Test %d: Expected status code to be %d but was %d",
|
||||||
i, test.expectedCode, rec.Code)
|
i, test.expectedCode, rec.Code)
|
||||||
}
|
}
|
||||||
@@ -77,6 +94,7 @@ func TestAppDelete(t *testing.T) {
|
|||||||
resp := getErrorResponse(t, rec)
|
resp := getErrorResponse(t, rec)
|
||||||
|
|
||||||
if !strings.Contains(resp.Error.Message, test.expectedError.Error()) {
|
if !strings.Contains(resp.Error.Message, test.expectedError.Error()) {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Errorf("Test %d: Expected error message to have `%s`",
|
t.Errorf("Test %d: Expected error message to have `%s`",
|
||||||
i, test.expectedError.Error())
|
i, test.expectedError.Error())
|
||||||
}
|
}
|
||||||
@@ -85,6 +103,7 @@ func TestAppDelete(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAppList(t *testing.T) {
|
func TestAppList(t *testing.T) {
|
||||||
|
buf := setLogBuffer()
|
||||||
New(&datastore.Mock{}, &mqs.Mock{}, testRunner(t))
|
New(&datastore.Mock{}, &mqs.Mock{}, testRunner(t))
|
||||||
router := testRouter()
|
router := testRouter()
|
||||||
|
|
||||||
@@ -99,6 +118,7 @@ func TestAppList(t *testing.T) {
|
|||||||
_, rec := routerRequest(t, router, "GET", test.path, nil)
|
_, rec := routerRequest(t, router, "GET", test.path, nil)
|
||||||
|
|
||||||
if rec.Code != test.expectedCode {
|
if rec.Code != test.expectedCode {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Errorf("Test %d: Expected status code to be %d but was %d",
|
t.Errorf("Test %d: Expected status code to be %d but was %d",
|
||||||
i, test.expectedCode, rec.Code)
|
i, test.expectedCode, rec.Code)
|
||||||
}
|
}
|
||||||
@@ -107,6 +127,7 @@ func TestAppList(t *testing.T) {
|
|||||||
resp := getErrorResponse(t, rec)
|
resp := getErrorResponse(t, rec)
|
||||||
|
|
||||||
if !strings.Contains(resp.Error.Message, test.expectedError.Error()) {
|
if !strings.Contains(resp.Error.Message, test.expectedError.Error()) {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Errorf("Test %d: Expected error message to have `%s`",
|
t.Errorf("Test %d: Expected error message to have `%s`",
|
||||||
i, test.expectedError.Error())
|
i, test.expectedError.Error())
|
||||||
}
|
}
|
||||||
@@ -115,6 +136,7 @@ func TestAppList(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAppGet(t *testing.T) {
|
func TestAppGet(t *testing.T) {
|
||||||
|
buf := setLogBuffer()
|
||||||
New(&datastore.Mock{}, &mqs.Mock{}, testRunner(t))
|
New(&datastore.Mock{}, &mqs.Mock{}, testRunner(t))
|
||||||
router := testRouter()
|
router := testRouter()
|
||||||
|
|
||||||
@@ -129,6 +151,7 @@ func TestAppGet(t *testing.T) {
|
|||||||
_, rec := routerRequest(t, router, "GET", test.path, nil)
|
_, rec := routerRequest(t, router, "GET", test.path, nil)
|
||||||
|
|
||||||
if rec.Code != test.expectedCode {
|
if rec.Code != test.expectedCode {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Errorf("Test %d: Expected status code to be %d but was %d",
|
t.Errorf("Test %d: Expected status code to be %d but was %d",
|
||||||
i, test.expectedCode, rec.Code)
|
i, test.expectedCode, rec.Code)
|
||||||
}
|
}
|
||||||
@@ -137,6 +160,7 @@ func TestAppGet(t *testing.T) {
|
|||||||
resp := getErrorResponse(t, rec)
|
resp := getErrorResponse(t, rec)
|
||||||
|
|
||||||
if !strings.Contains(resp.Error.Message, test.expectedError.Error()) {
|
if !strings.Contains(resp.Error.Message, test.expectedError.Error()) {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Errorf("Test %d: Expected error message to have `%s`",
|
t.Errorf("Test %d: Expected error message to have `%s`",
|
||||||
i, test.expectedError.Error())
|
i, test.expectedError.Error())
|
||||||
}
|
}
|
||||||
@@ -145,6 +169,7 @@ func TestAppGet(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAppUpdate(t *testing.T) {
|
func TestAppUpdate(t *testing.T) {
|
||||||
|
buf := setLogBuffer()
|
||||||
New(&datastore.Mock{}, &mqs.Mock{}, testRunner(t))
|
New(&datastore.Mock{}, &mqs.Mock{}, testRunner(t))
|
||||||
router := testRouter()
|
router := testRouter()
|
||||||
|
|
||||||
@@ -164,6 +189,7 @@ func TestAppUpdate(t *testing.T) {
|
|||||||
_, rec := routerRequest(t, router, "PUT", test.path, body)
|
_, rec := routerRequest(t, router, "PUT", test.path, body)
|
||||||
|
|
||||||
if rec.Code != test.expectedCode {
|
if rec.Code != test.expectedCode {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Errorf("Test %d: Expected status code to be %d but was %d",
|
t.Errorf("Test %d: Expected status code to be %d but was %d",
|
||||||
i, test.expectedCode, rec.Code)
|
i, test.expectedCode, rec.Code)
|
||||||
}
|
}
|
||||||
@@ -172,6 +198,7 @@ func TestAppUpdate(t *testing.T) {
|
|||||||
resp := getErrorResponse(t, rec)
|
resp := getErrorResponse(t, rec)
|
||||||
|
|
||||||
if !strings.Contains(resp.Error.Message, test.expectedError.Error()) {
|
if !strings.Contains(resp.Error.Message, test.expectedError.Error()) {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Errorf("Test %d: Expected error message to have `%s`",
|
t.Errorf("Test %d: Expected error message to have `%s`",
|
||||||
i, test.expectedError.Error())
|
i, test.expectedError.Error())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestRouteCreate(t *testing.T) {
|
func TestRouteCreate(t *testing.T) {
|
||||||
|
buf := setLogBuffer()
|
||||||
New(&datastore.Mock{}, &mqs.Mock{}, testRunner(t))
|
New(&datastore.Mock{}, &mqs.Mock{}, testRunner(t))
|
||||||
router := testRouter()
|
router := testRouter()
|
||||||
|
|
||||||
@@ -37,6 +38,7 @@ func TestRouteCreate(t *testing.T) {
|
|||||||
_, rec := routerRequest(t, router, "POST", test.path, body)
|
_, rec := routerRequest(t, router, "POST", test.path, body)
|
||||||
|
|
||||||
if rec.Code != test.expectedCode {
|
if rec.Code != test.expectedCode {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Errorf("Test %d: Expected status code to be %d but was %d",
|
t.Errorf("Test %d: Expected status code to be %d but was %d",
|
||||||
i, test.expectedCode, rec.Code)
|
i, test.expectedCode, rec.Code)
|
||||||
}
|
}
|
||||||
@@ -45,6 +47,7 @@ func TestRouteCreate(t *testing.T) {
|
|||||||
resp := getErrorResponse(t, rec)
|
resp := getErrorResponse(t, rec)
|
||||||
|
|
||||||
if !strings.Contains(resp.Error.Message, test.expectedError.Error()) {
|
if !strings.Contains(resp.Error.Message, test.expectedError.Error()) {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Errorf("Test %d: Expected error message to have `%s`",
|
t.Errorf("Test %d: Expected error message to have `%s`",
|
||||||
i, test.expectedError.Error())
|
i, test.expectedError.Error())
|
||||||
}
|
}
|
||||||
@@ -53,6 +56,7 @@ func TestRouteCreate(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestRouteDelete(t *testing.T) {
|
func TestRouteDelete(t *testing.T) {
|
||||||
|
buf := setLogBuffer()
|
||||||
New(&datastore.Mock{}, &mqs.Mock{}, testRunner(t))
|
New(&datastore.Mock{}, &mqs.Mock{}, testRunner(t))
|
||||||
router := testRouter()
|
router := testRouter()
|
||||||
|
|
||||||
@@ -68,6 +72,7 @@ func TestRouteDelete(t *testing.T) {
|
|||||||
_, rec := routerRequest(t, router, "DELETE", test.path, nil)
|
_, rec := routerRequest(t, router, "DELETE", test.path, nil)
|
||||||
|
|
||||||
if rec.Code != test.expectedCode {
|
if rec.Code != test.expectedCode {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Errorf("Test %d: Expected status code to be %d but was %d",
|
t.Errorf("Test %d: Expected status code to be %d but was %d",
|
||||||
i, test.expectedCode, rec.Code)
|
i, test.expectedCode, rec.Code)
|
||||||
}
|
}
|
||||||
@@ -76,6 +81,7 @@ func TestRouteDelete(t *testing.T) {
|
|||||||
resp := getErrorResponse(t, rec)
|
resp := getErrorResponse(t, rec)
|
||||||
|
|
||||||
if !strings.Contains(resp.Error.Message, test.expectedError.Error()) {
|
if !strings.Contains(resp.Error.Message, test.expectedError.Error()) {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Errorf("Test %d: Expected error message to have `%s`",
|
t.Errorf("Test %d: Expected error message to have `%s`",
|
||||||
i, test.expectedError.Error())
|
i, test.expectedError.Error())
|
||||||
}
|
}
|
||||||
@@ -84,6 +90,7 @@ func TestRouteDelete(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestRouteList(t *testing.T) {
|
func TestRouteList(t *testing.T) {
|
||||||
|
buf := setLogBuffer()
|
||||||
New(&datastore.Mock{}, &mqs.Mock{}, testRunner(t))
|
New(&datastore.Mock{}, &mqs.Mock{}, testRunner(t))
|
||||||
router := testRouter()
|
router := testRouter()
|
||||||
|
|
||||||
@@ -98,6 +105,7 @@ func TestRouteList(t *testing.T) {
|
|||||||
_, rec := routerRequest(t, router, "GET", test.path, nil)
|
_, rec := routerRequest(t, router, "GET", test.path, nil)
|
||||||
|
|
||||||
if rec.Code != test.expectedCode {
|
if rec.Code != test.expectedCode {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Errorf("Test %d: Expected status code to be %d but was %d",
|
t.Errorf("Test %d: Expected status code to be %d but was %d",
|
||||||
i, test.expectedCode, rec.Code)
|
i, test.expectedCode, rec.Code)
|
||||||
}
|
}
|
||||||
@@ -106,6 +114,7 @@ func TestRouteList(t *testing.T) {
|
|||||||
resp := getErrorResponse(t, rec)
|
resp := getErrorResponse(t, rec)
|
||||||
|
|
||||||
if !strings.Contains(resp.Error.Message, test.expectedError.Error()) {
|
if !strings.Contains(resp.Error.Message, test.expectedError.Error()) {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Errorf("Test %d: Expected error message to have `%s`",
|
t.Errorf("Test %d: Expected error message to have `%s`",
|
||||||
i, test.expectedError.Error())
|
i, test.expectedError.Error())
|
||||||
}
|
}
|
||||||
@@ -114,6 +123,7 @@ func TestRouteList(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestRouteGet(t *testing.T) {
|
func TestRouteGet(t *testing.T) {
|
||||||
|
buf := setLogBuffer()
|
||||||
New(&datastore.Mock{}, &mqs.Mock{}, testRunner(t))
|
New(&datastore.Mock{}, &mqs.Mock{}, testRunner(t))
|
||||||
router := testRouter()
|
router := testRouter()
|
||||||
|
|
||||||
@@ -128,6 +138,7 @@ func TestRouteGet(t *testing.T) {
|
|||||||
_, rec := routerRequest(t, router, "GET", test.path, nil)
|
_, rec := routerRequest(t, router, "GET", test.path, nil)
|
||||||
|
|
||||||
if rec.Code != test.expectedCode {
|
if rec.Code != test.expectedCode {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Errorf("Test %d: Expected status code to be %d but was %d",
|
t.Errorf("Test %d: Expected status code to be %d but was %d",
|
||||||
i, test.expectedCode, rec.Code)
|
i, test.expectedCode, rec.Code)
|
||||||
}
|
}
|
||||||
@@ -136,6 +147,7 @@ func TestRouteGet(t *testing.T) {
|
|||||||
resp := getErrorResponse(t, rec)
|
resp := getErrorResponse(t, rec)
|
||||||
|
|
||||||
if !strings.Contains(resp.Error.Message, test.expectedError.Error()) {
|
if !strings.Contains(resp.Error.Message, test.expectedError.Error()) {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Errorf("Test %d: Expected error message to have `%s`",
|
t.Errorf("Test %d: Expected error message to have `%s`",
|
||||||
i, test.expectedError.Error())
|
i, test.expectedError.Error())
|
||||||
}
|
}
|
||||||
@@ -144,6 +156,7 @@ func TestRouteGet(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestRouteUpdate(t *testing.T) {
|
func TestRouteUpdate(t *testing.T) {
|
||||||
|
buf := setLogBuffer()
|
||||||
New(&datastore.Mock{}, &mqs.Mock{}, testRunner(t))
|
New(&datastore.Mock{}, &mqs.Mock{}, testRunner(t))
|
||||||
router := testRouter()
|
router := testRouter()
|
||||||
|
|
||||||
@@ -165,6 +178,7 @@ func TestRouteUpdate(t *testing.T) {
|
|||||||
_, rec := routerRequest(t, router, "PUT", test.path, body)
|
_, rec := routerRequest(t, router, "PUT", test.path, body)
|
||||||
|
|
||||||
if rec.Code != test.expectedCode {
|
if rec.Code != test.expectedCode {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Errorf("Test %d: Expected status code to be %d but was %d",
|
t.Errorf("Test %d: Expected status code to be %d but was %d",
|
||||||
i, test.expectedCode, rec.Code)
|
i, test.expectedCode, rec.Code)
|
||||||
}
|
}
|
||||||
@@ -173,6 +187,7 @@ func TestRouteUpdate(t *testing.T) {
|
|||||||
resp := getErrorResponse(t, rec)
|
resp := getErrorResponse(t, rec)
|
||||||
|
|
||||||
if !strings.Contains(resp.Error.Message, test.expectedError.Error()) {
|
if !strings.Contains(resp.Error.Message, test.expectedError.Error()) {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Errorf("Test %d: Expected error message to have `%s`",
|
t.Errorf("Test %d: Expected error message to have `%s`",
|
||||||
i, test.expectedError.Error())
|
i, test.expectedError.Error())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ func testRunner(t *testing.T) *runner.Runner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestRouteRunnerGet(t *testing.T) {
|
func TestRouteRunnerGet(t *testing.T) {
|
||||||
|
buf := setLogBuffer()
|
||||||
New(&datastore.Mock{
|
New(&datastore.Mock{
|
||||||
FakeApps: []*models.App{
|
FakeApps: []*models.App{
|
||||||
{Name: "myapp", Config: models.Config{}},
|
{Name: "myapp", Config: models.Config{}},
|
||||||
@@ -42,6 +43,7 @@ func TestRouteRunnerGet(t *testing.T) {
|
|||||||
_, rec := routerRequest(t, router, "GET", test.path, nil)
|
_, rec := routerRequest(t, router, "GET", test.path, nil)
|
||||||
|
|
||||||
if rec.Code != test.expectedCode {
|
if rec.Code != test.expectedCode {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Errorf("Test %d: Expected status code to be %d but was %d",
|
t.Errorf("Test %d: Expected status code to be %d but was %d",
|
||||||
i, test.expectedCode, rec.Code)
|
i, test.expectedCode, rec.Code)
|
||||||
}
|
}
|
||||||
@@ -50,6 +52,7 @@ func TestRouteRunnerGet(t *testing.T) {
|
|||||||
resp := getErrorResponse(t, rec)
|
resp := getErrorResponse(t, rec)
|
||||||
|
|
||||||
if !strings.Contains(resp.Error.Message, test.expectedError.Error()) {
|
if !strings.Contains(resp.Error.Message, test.expectedError.Error()) {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Errorf("Test %d: Expected error message to have `%s`",
|
t.Errorf("Test %d: Expected error message to have `%s`",
|
||||||
i, test.expectedError.Error())
|
i, test.expectedError.Error())
|
||||||
}
|
}
|
||||||
@@ -58,6 +61,7 @@ func TestRouteRunnerGet(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestRouteRunnerPost(t *testing.T) {
|
func TestRouteRunnerPost(t *testing.T) {
|
||||||
|
buf := setLogBuffer()
|
||||||
New(&datastore.Mock{
|
New(&datastore.Mock{
|
||||||
FakeApps: []*models.App{
|
FakeApps: []*models.App{
|
||||||
{Name: "myapp", Config: models.Config{}},
|
{Name: "myapp", Config: models.Config{}},
|
||||||
@@ -79,6 +83,7 @@ func TestRouteRunnerPost(t *testing.T) {
|
|||||||
_, rec := routerRequest(t, router, "POST", test.path, body)
|
_, rec := routerRequest(t, router, "POST", test.path, body)
|
||||||
|
|
||||||
if rec.Code != test.expectedCode {
|
if rec.Code != test.expectedCode {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Errorf("Test %d: Expected status code to be %d but was %d",
|
t.Errorf("Test %d: Expected status code to be %d but was %d",
|
||||||
i, test.expectedCode, rec.Code)
|
i, test.expectedCode, rec.Code)
|
||||||
}
|
}
|
||||||
@@ -89,6 +94,7 @@ func TestRouteRunnerPost(t *testing.T) {
|
|||||||
expMsg := test.expectedError.Error()
|
expMsg := test.expectedError.Error()
|
||||||
fmt.Println(respMsg == expMsg)
|
fmt.Println(respMsg == expMsg)
|
||||||
if respMsg != expMsg && !strings.Contains(respMsg, expMsg) {
|
if respMsg != expMsg && !strings.Contains(respMsg, expMsg) {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Errorf("Test %d: Expected error message to have `%s`",
|
t.Errorf("Test %d: Expected error message to have `%s`",
|
||||||
i, test.expectedError.Error())
|
i, test.expectedError.Error())
|
||||||
}
|
}
|
||||||
@@ -97,6 +103,7 @@ func TestRouteRunnerPost(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestRouteRunnerExecution(t *testing.T) {
|
func TestRouteRunnerExecution(t *testing.T) {
|
||||||
|
buf := setLogBuffer()
|
||||||
New(&datastore.Mock{
|
New(&datastore.Mock{
|
||||||
FakeApps: []*models.App{
|
FakeApps: []*models.App{
|
||||||
{Name: "myapp", Config: models.Config{}},
|
{Name: "myapp", Config: models.Config{}},
|
||||||
@@ -125,6 +132,7 @@ func TestRouteRunnerExecution(t *testing.T) {
|
|||||||
_, rec := routerRequest(t, router, "GET", test.path, body)
|
_, rec := routerRequest(t, router, "GET", test.path, body)
|
||||||
|
|
||||||
if rec.Code != test.expectedCode {
|
if rec.Code != test.expectedCode {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Errorf("Test %d: Expected status code to be %d but was %d",
|
t.Errorf("Test %d: Expected status code to be %d but was %d",
|
||||||
i, test.expectedCode, rec.Code)
|
i, test.expectedCode, rec.Code)
|
||||||
}
|
}
|
||||||
@@ -132,6 +140,7 @@ func TestRouteRunnerExecution(t *testing.T) {
|
|||||||
if test.expectedHeaders != nil {
|
if test.expectedHeaders != nil {
|
||||||
for name, header := range test.expectedHeaders {
|
for name, header := range test.expectedHeaders {
|
||||||
if header[0] != rec.Header().Get(name) {
|
if header[0] != rec.Header().Get(name) {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Errorf("Test %d: Expected header `%s` to be %s but was %s",
|
t.Errorf("Test %d: Expected header `%s` to be %s but was %s",
|
||||||
i, name, header[0], rec.Header().Get(name))
|
i, name, header[0], rec.Header().Get(name))
|
||||||
}
|
}
|
||||||
@@ -141,6 +150,7 @@ func TestRouteRunnerExecution(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMatchRoute(t *testing.T) {
|
func TestMatchRoute(t *testing.T) {
|
||||||
|
buf := setLogBuffer()
|
||||||
for i, test := range []struct {
|
for i, test := range []struct {
|
||||||
baseRoute string
|
baseRoute string
|
||||||
route string
|
route string
|
||||||
@@ -154,12 +164,14 @@ func TestMatchRoute(t *testing.T) {
|
|||||||
if test.expectedParams != nil {
|
if test.expectedParams != nil {
|
||||||
for j, param := range test.expectedParams {
|
for j, param := range test.expectedParams {
|
||||||
if params[j].Key != param.Key || params[j].Value != param.Value {
|
if params[j].Key != param.Key || params[j].Value != param.Value {
|
||||||
|
t.Log(buf.String())
|
||||||
fmt.Println(params[j])
|
fmt.Println(params[j])
|
||||||
t.Errorf("Test %d: expected param %d, key = %s, value = %s", i, j, param.Key, param.Value)
|
t.Errorf("Test %d: expected param %d, key = %s, value = %s", i, j, param.Key, param.Value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Errorf("Test %d: %s should match %s", i, test.route, test.baseRoute)
|
t.Errorf("Test %d: %s should match %s", i, test.route, test.baseRoute)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ func prepareBolt(t *testing.T) (models.Datastore, func()) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFullStack(t *testing.T) {
|
func TestFullStack(t *testing.T) {
|
||||||
|
buf := setLogBuffer()
|
||||||
ds, close := prepareBolt(t)
|
ds, close := prepareBolt(t)
|
||||||
defer close()
|
defer close()
|
||||||
|
|
||||||
@@ -116,6 +117,7 @@ func TestFullStack(t *testing.T) {
|
|||||||
_, rec := routerRequest(t, router, test.method, test.path, bytes.NewBuffer([]byte(test.body)))
|
_, rec := routerRequest(t, router, test.method, test.path, bytes.NewBuffer([]byte(test.body)))
|
||||||
|
|
||||||
if rec.Code != test.expectedCode {
|
if rec.Code != test.expectedCode {
|
||||||
|
t.Log(buf.String())
|
||||||
t.Errorf("Test %d: Expected status code to be %d but was %d",
|
t.Errorf("Test %d: Expected status code to be %d but was %d",
|
||||||
i, test.expectedCode, rec.Code)
|
i, test.expectedCode, rec.Code)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user