mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Remove V1 endpoints and Routes (#1210)
Largely a removal job, however many tests, particularly system level ones relied on Routes. These have been migrated to use Fns. * Add 410 response to swagger * No app names in log tags * Adding constraint in GetCall for FnID * Adding test to check FnID is required on call * Add fn_id to call selector * Fix text in docker mem warning * Correct buildConfig func name * Test fix up * Removing CPU setting from Agent test CPU setting has been deprecated, but the code base is still riddled with it. This just removes it from this layer. Really we need to remove it from Call. * Remove fn id check on calls * Reintroduce fn id required on call * Adding fnID to calls for execute test * Correct setting of app id in middleware * Removes root middlewares ability to redirect fun invocations * Add over sized test check * Removing call fn id check
This commit is contained in:
committed by
Owen Cliffe
parent
6a01dae923
commit
d56a49b321
@@ -1,6 +1,7 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
@@ -24,11 +25,10 @@ func TestCallGet(t *testing.T) {
|
||||
}
|
||||
}()
|
||||
|
||||
app := &models.App{Name: "myapp", ID: "app_id"}
|
||||
fn := &models.Fn{Name: "myfn", ID: "fn_id"}
|
||||
call := &models.Call{
|
||||
AppID: app.ID,
|
||||
FnID: fn.ID,
|
||||
ID: id.New().String(),
|
||||
Path: "/thisisatest",
|
||||
Image: "fnproject/hello",
|
||||
// Delay: 0,
|
||||
Type: "sync",
|
||||
@@ -46,7 +46,7 @@ func TestCallGet(t *testing.T) {
|
||||
rnr, cancel := testRunner(t)
|
||||
defer cancel()
|
||||
ds := datastore.NewMockInit(
|
||||
[]*models.App{app},
|
||||
[]*models.Fn{fn},
|
||||
)
|
||||
fnl := logs.NewMock([]*models.Call{call})
|
||||
srv := testServer(ds, &mqs.Mock{}, fnl, rnr, ServerTypeFull)
|
||||
@@ -57,11 +57,11 @@ func TestCallGet(t *testing.T) {
|
||||
expectedCode int
|
||||
expectedError error
|
||||
}{
|
||||
{"/v1/apps//calls/" + call.ID, "", http.StatusBadRequest, models.ErrAppsMissingName},
|
||||
{"/v1/apps/nodawg/calls/" + call.ID, "", http.StatusNotFound, models.ErrAppsNotFound},
|
||||
{"/v1/apps/myapp/calls/" + id.New().String(), "", http.StatusNotFound, models.ErrCallNotFound},
|
||||
{"/v1/apps/myapp/calls/" + call.ID[:3], "", http.StatusNotFound, models.ErrCallNotFound},
|
||||
{"/v1/apps/myapp/calls/" + call.ID, "", http.StatusOK, nil},
|
||||
{"/v2/fns//calls/" + call.ID, "", http.StatusBadRequest, models.ErrFnsMissingID},
|
||||
{"/v2/fns/missing_fn/calls/" + call.ID, "", http.StatusNotFound, models.ErrFnsNotFound},
|
||||
{"/v2/fns/fn_id/calls/" + id.New().String(), "", http.StatusNotFound, models.ErrCallNotFound},
|
||||
{"/v2/fns/fn_id/calls/" + call.ID[:3], "", http.StatusNotFound, models.ErrCallNotFound},
|
||||
{"/v2/fns/fn_id/calls/" + call.ID, "", http.StatusOK, nil},
|
||||
} {
|
||||
_, rec := routerRequest(t, srv.Router, "GET", test.path, nil)
|
||||
|
||||
@@ -72,10 +72,10 @@ func TestCallGet(t *testing.T) {
|
||||
}
|
||||
|
||||
if test.expectedError != nil {
|
||||
resp := getV1ErrorResponse(t, rec)
|
||||
resp := getErrorResponse(t, rec)
|
||||
|
||||
if !strings.Contains(resp.Error.Message, test.expectedError.Error()) {
|
||||
t.Log(resp.Error.Message)
|
||||
if !strings.Contains(resp.Message, test.expectedError.Error()) {
|
||||
t.Log(resp.Message)
|
||||
t.Log(rec.Body.String())
|
||||
t.Errorf("Test %d: Expected error message to have `%s`",
|
||||
i, test.expectedError.Error())
|
||||
@@ -93,12 +93,11 @@ func TestCallList(t *testing.T) {
|
||||
}
|
||||
}()
|
||||
|
||||
app := &models.App{Name: "myapp", ID: "app_id"}
|
||||
fn := &models.Fn{ID: "fn_id"}
|
||||
|
||||
call := &models.Call{
|
||||
AppID: app.ID,
|
||||
FnID: fn.ID,
|
||||
ID: id.New().String(),
|
||||
Path: "/thisisatest",
|
||||
Image: "fnproject/hello",
|
||||
// Delay: 0,
|
||||
Type: "sync",
|
||||
@@ -116,15 +115,17 @@ func TestCallList(t *testing.T) {
|
||||
c3 := *call
|
||||
c2.CreatedAt = common.DateTime(time.Now().Add(100 * time.Second))
|
||||
c2.ID = id.New().String()
|
||||
c2.Path = "test2"
|
||||
c3.CreatedAt = common.DateTime(time.Now().Add(200 * time.Second))
|
||||
c3.ID = id.New().String()
|
||||
c3.Path = "/test3"
|
||||
|
||||
encodedC1ID := base64.RawURLEncoding.EncodeToString([]byte(call.ID))
|
||||
encodedC2ID := base64.RawURLEncoding.EncodeToString([]byte(c2.ID))
|
||||
encodedC3ID := base64.RawURLEncoding.EncodeToString([]byte(c3.ID))
|
||||
|
||||
rnr, cancel := testRunner(t)
|
||||
defer cancel()
|
||||
ds := datastore.NewMockInit(
|
||||
[]*models.App{app},
|
||||
[]*models.Fn{fn},
|
||||
)
|
||||
fnl := logs.NewMock([]*models.Call{call, &c2, &c3})
|
||||
srv := testServer(ds, &mqs.Mock{}, fnl, rnr, ServerTypeFull)
|
||||
@@ -143,20 +144,20 @@ func TestCallList(t *testing.T) {
|
||||
expectedLen int
|
||||
nextCursor string
|
||||
}{
|
||||
{"/v1/apps//calls", "", http.StatusBadRequest, models.ErrAppsMissingName, 0, ""},
|
||||
{"/v1/apps/nodawg/calls", "", http.StatusNotFound, models.ErrAppsNotFound, 0, ""},
|
||||
{"/v1/apps/myapp/calls", "", http.StatusOK, nil, 3, ""},
|
||||
{"/v1/apps/myapp/calls?per_page=1", "", http.StatusOK, nil, 1, c3.ID},
|
||||
{"/v1/apps/myapp/calls?per_page=1&cursor=" + c3.ID, "", http.StatusOK, nil, 1, c2.ID},
|
||||
{"/v1/apps/myapp/calls?per_page=1&cursor=" + c2.ID, "", http.StatusOK, nil, 1, call.ID},
|
||||
{"/v1/apps/myapp/calls?per_page=100&cursor=" + c2.ID, "", http.StatusOK, nil, 1, ""}, // cursor is empty if per_page > len(results)
|
||||
{"/v1/apps/myapp/calls?per_page=1&cursor=" + call.ID, "", http.StatusOK, nil, 0, ""}, // cursor could point to empty page
|
||||
{"/v1/apps/myapp/calls?" + rangeTest, "", http.StatusOK, nil, 1, ""},
|
||||
{"/v1/apps/myapp/calls?from_time=xyz", "", http.StatusBadRequest, models.ErrInvalidFromTime, 0, ""},
|
||||
{"/v1/apps/myapp/calls?to_time=xyz", "", http.StatusBadRequest, models.ErrInvalidToTime, 0, ""},
|
||||
{"/v2/fns//calls", "", http.StatusBadRequest, models.ErrFnsMissingID, 0, ""},
|
||||
{"/v2/fns/nodawg/calls", "", http.StatusNotFound, models.ErrFnsNotFound, 0, ""},
|
||||
{"/v2/fns/fn_id/calls", "", http.StatusOK, nil, 3, ""},
|
||||
{"/v2/fns/fn_id/calls?per_page=1", "", http.StatusOK, nil, 1, encodedC3ID},
|
||||
{"/v2/fns/fn_id/calls?per_page=1&cursor=" + encodedC3ID, "", http.StatusOK, nil, 1, encodedC2ID},
|
||||
{"/v2/fns/fn_id/calls?per_page=1&cursor=" + encodedC2ID, "", http.StatusOK, nil, 1, encodedC1ID},
|
||||
{"/v2/fns/fn_id/calls?per_page=100&cursor=" + encodedC2ID, "", http.StatusOK, nil, 1, ""}, // cursor is empty if per_page > len(results)
|
||||
{"/v2/fns/fn_id/calls?per_page=1&cursor=" + encodedC1ID, "", http.StatusOK, nil, 0, ""}, // cursor could point to empty page
|
||||
{"/v2/fns/fn_id/calls?" + rangeTest, "", http.StatusOK, nil, 1, ""},
|
||||
{"/v2/fns/fn_id/calls?from_time=xyz", "", http.StatusBadRequest, models.ErrInvalidFromTime, 0, ""},
|
||||
{"/v2/fns/fn_id/calls?to_time=xyz", "", http.StatusBadRequest, models.ErrInvalidToTime, 0, ""},
|
||||
|
||||
// TODO path isn't url safe w/ '/', so this is weird. hack in for tests
|
||||
{"/v1/apps/myapp/calls?path=test2", "", http.StatusOK, nil, 1, ""},
|
||||
// // TODO path isn't url safe w/ '/', so this is weird. hack in for tests
|
||||
// {"/v2/fns/fn_id/calls?path=test2", "", http.StatusOK, nil, 1, ""},
|
||||
} {
|
||||
_, rec := routerRequest(t, srv.Router, "GET", test.path, nil)
|
||||
|
||||
@@ -166,22 +167,22 @@ func TestCallList(t *testing.T) {
|
||||
}
|
||||
|
||||
if test.expectedError != nil {
|
||||
resp := getV1ErrorResponse(t, rec)
|
||||
resp := getErrorResponse(t, rec)
|
||||
|
||||
if resp.Error == nil || !strings.Contains(resp.Error.Message, test.expectedError.Error()) {
|
||||
if resp.Message == "" || !strings.Contains(resp.Message, test.expectedError.Error()) {
|
||||
t.Errorf("Test %d: Expected error message to have `%s`, got: `%s`",
|
||||
i, test.expectedError.Error(), resp.Error)
|
||||
i, test.expectedError.Error(), resp.Message)
|
||||
}
|
||||
} else {
|
||||
// normal path
|
||||
|
||||
var resp callsResponse
|
||||
var resp models.CallList
|
||||
err := json.NewDecoder(rec.Body).Decode(&resp)
|
||||
if err != nil {
|
||||
t.Errorf("Test %d: Expected response body to be a valid json object. err: %v", i, err)
|
||||
}
|
||||
if len(resp.Calls) != test.expectedLen {
|
||||
t.Fatalf("Test %d: Expected apps length to be %d, but got %d", i, test.expectedLen, len(resp.Calls))
|
||||
if len(resp.Items) != test.expectedLen {
|
||||
t.Fatalf("Test %d: Expected calls length to be %d, but got %d", i, test.expectedLen, len(resp.Items))
|
||||
}
|
||||
if resp.NextCursor != test.nextCursor {
|
||||
t.Errorf("Test %d: Expected next_cursor to be %s, but got %s", i, test.nextCursor, resp.NextCursor)
|
||||
|
||||
Reference in New Issue
Block a user