mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
App ID (#641)
* App ID * Clean-up * Use ID or name to reference apps * Can use app by name or ID * Get rid of AppName for routes API and model routes API is completely backwards-compatible routes API accepts both app ID and name * Get rid of AppName from calls API and model * Fixing tests * Get rid of AppName from logs API and model * Restrict API to work with app names only * Addressing review comments * Fix for hybrid mode * Fix rebase problems * Addressing review comments * Addressing review comments pt.2 * Fixing test issue * Addressing review comments pt.3 * Updated docstring * Adjust UpdateApp SQL implementation to work with app IDs instead of names * Fixing tests * fmt after rebase * Make tests green again! * Use GetAppByID wherever it is necessary - adding new v2 endpoints to keep hybrid api/runner mode working - extract CallBase from Call object to expose that to a user (it doesn't include any app reference, as we do for all other API objects) * Get rid of GetAppByName * Adjusting server router setup * Make hybrid work again * Fix datastore tests * Fixing tests * Do not ignore app_id * Resolve issues after rebase * Updating test to make it work as it was * Tabula rasa for migrations * Adding calls API test - we need to ensure we give "App not found" for the missing app and missing call in first place - making previous test work (request missing call for the existing app) * Make datastore tests work fine with correctly applied migrations * Make CallFunction middleware work again had to adjust its implementation to set app ID before proceeding * The biggest rebase ever made * Fix 8's migration * Fix tests * Fix hybrid client * Fix tests problem * Increment app ID migration version * Fixing TestAppUpdate * Fix rebase issues * Addressing review comments * Renew vendor * Updated swagger doc per recommendations
This commit is contained in:
committed by
Reed Allman
parent
4e90844a67
commit
3c15ca6ea6
@@ -16,6 +16,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/fnproject/fn/api/datastore"
|
||||
"github.com/fnproject/fn/api/id"
|
||||
"github.com/fnproject/fn/api/models"
|
||||
"github.com/fnproject/fn/api/mqs"
|
||||
"github.com/sirupsen/logrus"
|
||||
@@ -35,7 +36,7 @@ func init() {
|
||||
func checkExpectedHeaders(t *testing.T, expectedHeaders http.Header, receivedHeaders http.Header) {
|
||||
|
||||
checkMap := make([]string, 0, len(expectedHeaders))
|
||||
for k, _ := range expectedHeaders {
|
||||
for k := range expectedHeaders {
|
||||
checkMap = append(checkMap, k)
|
||||
}
|
||||
|
||||
@@ -46,7 +47,7 @@ func checkExpectedHeaders(t *testing.T, expectedHeaders http.Header, receivedHea
|
||||
}
|
||||
}
|
||||
|
||||
for i, _ := range checkMap {
|
||||
for i := range checkMap {
|
||||
if checkMap[i] == k {
|
||||
checkMap = append(checkMap[:i], checkMap[i+1:]...)
|
||||
break
|
||||
@@ -72,15 +73,15 @@ func TestCallConfigurationRequest(t *testing.T) {
|
||||
cfg := models.Config{"APP_VAR": "FOO"}
|
||||
rCfg := models.Config{"ROUTE_VAR": "BAR"}
|
||||
|
||||
app := &models.App{Name: appName, Config: cfg}
|
||||
app.SetDefaults()
|
||||
ds := datastore.NewMockInit(
|
||||
[]*models.App{
|
||||
{Name: appName, Config: cfg},
|
||||
},
|
||||
[]*models.App{app},
|
||||
[]*models.Route{
|
||||
{
|
||||
AppID: app.ID,
|
||||
Config: rCfg,
|
||||
Path: path,
|
||||
AppName: appName,
|
||||
Image: image,
|
||||
Type: typ,
|
||||
Format: format,
|
||||
@@ -112,7 +113,7 @@ func TestCallConfigurationRequest(t *testing.T) {
|
||||
|
||||
call, err := a.GetCall(
|
||||
WithWriter(w), // XXX (reed): order matters [for now]
|
||||
FromRequest(appName, path, req),
|
||||
FromRequest(app, path, req),
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -124,8 +125,8 @@ func TestCallConfigurationRequest(t *testing.T) {
|
||||
if model.ID == "" {
|
||||
t.Fatal("model does not have id, GetCall should assign id")
|
||||
}
|
||||
if model.AppName != appName {
|
||||
t.Fatal("app name mismatch", model.AppName, appName)
|
||||
if model.AppID != app.ID {
|
||||
t.Fatal("app ID mismatch", model.ID, app.ID)
|
||||
}
|
||||
if model.Path != path {
|
||||
t.Fatal("path mismatch", model.Path, path)
|
||||
@@ -191,7 +192,8 @@ func TestCallConfigurationRequest(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCallConfigurationModel(t *testing.T) {
|
||||
appName := "myapp"
|
||||
app := &models.App{Name: "myapp"}
|
||||
app.SetDefaults()
|
||||
path := "/"
|
||||
image := "fnproject/fn-test-utils"
|
||||
const timeout = 1
|
||||
@@ -199,13 +201,13 @@ func TestCallConfigurationModel(t *testing.T) {
|
||||
const memory = 256
|
||||
CPUs := models.MilliCPUs(1000)
|
||||
method := "GET"
|
||||
url := "http://127.0.0.1:8080/r/" + appName + path
|
||||
url := "http://127.0.0.1:8080/r/" + app.Name + path
|
||||
payload := "payload"
|
||||
typ := "sync"
|
||||
format := "default"
|
||||
cfg := models.Config{
|
||||
"FN_FORMAT": format,
|
||||
"FN_APP_NAME": appName,
|
||||
"FN_APP_NAME": app.Name,
|
||||
"FN_PATH": path,
|
||||
"FN_MEMORY": strconv.Itoa(memory),
|
||||
"FN_CPUS": CPUs.String(),
|
||||
@@ -215,8 +217,8 @@ func TestCallConfigurationModel(t *testing.T) {
|
||||
}
|
||||
|
||||
cm := &models.Call{
|
||||
AppID: app.ID,
|
||||
Config: cfg,
|
||||
AppName: appName,
|
||||
Path: path,
|
||||
Image: image,
|
||||
Type: typ,
|
||||
@@ -252,7 +254,8 @@ func TestCallConfigurationModel(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAsyncCallHeaders(t *testing.T) {
|
||||
appName := "myapp"
|
||||
app := &models.App{Name: "myapp"}
|
||||
app.SetDefaults()
|
||||
path := "/"
|
||||
image := "fnproject/fn-test-utils"
|
||||
const timeout = 1
|
||||
@@ -260,7 +263,7 @@ func TestAsyncCallHeaders(t *testing.T) {
|
||||
const memory = 256
|
||||
CPUs := models.MilliCPUs(200)
|
||||
method := "GET"
|
||||
url := "http://127.0.0.1:8080/r/" + appName + path
|
||||
url := "http://127.0.0.1:8080/r/" + app.Name + path
|
||||
payload := "payload"
|
||||
typ := "async"
|
||||
format := "http"
|
||||
@@ -268,7 +271,7 @@ func TestAsyncCallHeaders(t *testing.T) {
|
||||
contentLength := strconv.FormatInt(int64(len(payload)), 10)
|
||||
config := map[string]string{
|
||||
"FN_FORMAT": format,
|
||||
"FN_APP_NAME": appName,
|
||||
"FN_APP_NAME": app.Name,
|
||||
"FN_PATH": path,
|
||||
"FN_MEMORY": strconv.Itoa(memory),
|
||||
"FN_CPUS": CPUs.String(),
|
||||
@@ -279,14 +282,14 @@ func TestAsyncCallHeaders(t *testing.T) {
|
||||
}
|
||||
headers := map[string][]string{
|
||||
// FromRequest would insert these from original HTTP request
|
||||
"Content-Type": []string{contentType},
|
||||
"Content-Length": []string{contentLength},
|
||||
"Content-Type": {contentType},
|
||||
"Content-Length": {contentLength},
|
||||
}
|
||||
|
||||
cm := &models.Call{
|
||||
AppID: app.ID,
|
||||
Config: config,
|
||||
Headers: headers,
|
||||
AppName: appName,
|
||||
Path: path,
|
||||
Image: image,
|
||||
Type: typ,
|
||||
@@ -389,7 +392,8 @@ func TestLoggerTooBig(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSubmitError(t *testing.T) {
|
||||
appName := "myapp"
|
||||
app := &models.App{Name: "myapp"}
|
||||
app.SetDefaults()
|
||||
path := "/"
|
||||
image := "fnproject/fn-test-utils"
|
||||
const timeout = 10
|
||||
@@ -397,13 +401,13 @@ func TestSubmitError(t *testing.T) {
|
||||
const memory = 256
|
||||
CPUs := models.MilliCPUs(200)
|
||||
method := "GET"
|
||||
url := "http://127.0.0.1:8080/r/" + appName + path
|
||||
url := "http://127.0.0.1:8080/r/" + app.Name + path
|
||||
payload := `{"sleepTime": 0, "isDebug": true, "isCrash": true}`
|
||||
typ := "sync"
|
||||
format := "default"
|
||||
config := map[string]string{
|
||||
"FN_FORMAT": format,
|
||||
"FN_APP_NAME": appName,
|
||||
"FN_APP_NAME": app.Name,
|
||||
"FN_PATH": path,
|
||||
"FN_MEMORY": strconv.Itoa(memory),
|
||||
"FN_CPUS": CPUs.String(),
|
||||
@@ -414,8 +418,8 @@ func TestSubmitError(t *testing.T) {
|
||||
}
|
||||
|
||||
cm := &models.Call{
|
||||
AppID: app.ID,
|
||||
Config: config,
|
||||
AppName: appName,
|
||||
Path: path,
|
||||
Image: image,
|
||||
Type: typ,
|
||||
@@ -469,15 +473,15 @@ func TestHTTPWithoutContentLengthWorks(t *testing.T) {
|
||||
path := "/hello"
|
||||
url := "http://127.0.0.1:8080/r/" + appName + path
|
||||
|
||||
app := &models.App{Name: appName}
|
||||
app.SetDefaults()
|
||||
// we need to load in app & route so that FromRequest works
|
||||
ds := datastore.NewMockInit(
|
||||
[]*models.App{
|
||||
{Name: appName},
|
||||
},
|
||||
[]*models.App{app},
|
||||
[]*models.Route{
|
||||
{
|
||||
Path: path,
|
||||
AppName: appName,
|
||||
AppID: app.ID,
|
||||
Image: "fnproject/fn-test-utils",
|
||||
Type: "sync",
|
||||
Format: "http", // this _is_ the test
|
||||
@@ -503,7 +507,7 @@ func TestHTTPWithoutContentLengthWorks(t *testing.T) {
|
||||
|
||||
// grab a buffer so we can read what gets written to this guy
|
||||
var out bytes.Buffer
|
||||
callI, err := a.GetCall(FromRequest(appName, path, req), WithWriter(&out))
|
||||
callI, err := a.GetCall(FromRequest(app, path, req), WithWriter(&out))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -538,7 +542,7 @@ func TestHTTPWithoutContentLengthWorks(t *testing.T) {
|
||||
|
||||
func TestGetCallReturnsResourceImpossibility(t *testing.T) {
|
||||
call := &models.Call{
|
||||
AppName: "yo",
|
||||
AppID: id.New().String(),
|
||||
Path: "/yoyo",
|
||||
Image: "fnproject/fn-test-utils",
|
||||
Type: "sync",
|
||||
@@ -565,6 +569,8 @@ func testCall() *models.Call {
|
||||
appName := "myapp"
|
||||
path := "/"
|
||||
image := "fnproject/fn-test-utils:latest"
|
||||
app := &models.App{Name: appName}
|
||||
app.SetDefaults()
|
||||
const timeout = 10
|
||||
const idleTimeout = 20
|
||||
const memory = 256
|
||||
@@ -594,9 +600,9 @@ func testCall() *models.Call {
|
||||
}
|
||||
|
||||
return &models.Call{
|
||||
AppID: app.ID,
|
||||
Config: config,
|
||||
Headers: headers,
|
||||
AppName: appName,
|
||||
Path: path,
|
||||
Image: image,
|
||||
Type: typ,
|
||||
@@ -637,16 +643,14 @@ func TestPipesAreClear(t *testing.T) {
|
||||
ca.Format = "http"
|
||||
ca.IdleTimeout = 60 // keep this bad boy alive
|
||||
ca.Timeout = 4 // short
|
||||
|
||||
app := &models.App{Name: "myapp", ID: ca.AppID}
|
||||
// we need to load in app & route so that FromRequest works
|
||||
ds := datastore.NewMockInit(
|
||||
[]*models.App{
|
||||
{Name: ca.AppName},
|
||||
},
|
||||
[]*models.App{app},
|
||||
[]*models.Route{
|
||||
{
|
||||
Path: ca.Path,
|
||||
AppName: ca.AppName,
|
||||
AppID: ca.AppID,
|
||||
Image: ca.Image,
|
||||
Type: ca.Type,
|
||||
Format: ca.Format,
|
||||
@@ -676,7 +680,7 @@ func TestPipesAreClear(t *testing.T) {
|
||||
req.Header.Set("Content-Length", fmt.Sprintf("%d", len(bodOne)))
|
||||
|
||||
var outOne bytes.Buffer
|
||||
callI, err := a.GetCall(FromRequest(ca.AppName, ca.Path, req), WithWriter(&outOne))
|
||||
callI, err := a.GetCall(FromRequest(app, ca.Path, req), WithWriter(&outOne))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -710,7 +714,7 @@ func TestPipesAreClear(t *testing.T) {
|
||||
req.Header.Set("Content-Length", fmt.Sprintf("%d", len(bodTwo)))
|
||||
|
||||
var outTwo bytes.Buffer
|
||||
callI, err = a.GetCall(FromRequest(ca.AppName, ca.Path, req), WithWriter(&outTwo))
|
||||
callI, err = a.GetCall(FromRequest(app, ca.Path, req), WithWriter(&outTwo))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -787,16 +791,16 @@ func TestPipesDontMakeSpuriousCalls(t *testing.T) {
|
||||
call.Format = "http"
|
||||
call.IdleTimeout = 60 // keep this bad boy alive
|
||||
call.Timeout = 4 // short
|
||||
|
||||
app := &models.App{Name: "myapp"}
|
||||
app.SetDefaults()
|
||||
app.ID = call.AppID
|
||||
// we need to load in app & route so that FromRequest works
|
||||
ds := datastore.NewMockInit(
|
||||
[]*models.App{
|
||||
{Name: call.AppName},
|
||||
},
|
||||
[]*models.App{app},
|
||||
[]*models.Route{
|
||||
{
|
||||
Path: call.Path,
|
||||
AppName: call.AppName,
|
||||
AppID: call.AppID,
|
||||
Image: call.Image,
|
||||
Type: call.Type,
|
||||
Format: call.Format,
|
||||
@@ -817,7 +821,7 @@ func TestPipesDontMakeSpuriousCalls(t *testing.T) {
|
||||
}
|
||||
|
||||
var outOne bytes.Buffer
|
||||
callI, err := a.GetCall(FromRequest(call.AppName, call.Path, req), WithWriter(&outOne))
|
||||
callI, err := a.GetCall(FromRequest(app, call.Path, req), WithWriter(&outOne))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -842,7 +846,7 @@ func TestPipesDontMakeSpuriousCalls(t *testing.T) {
|
||||
}
|
||||
|
||||
var outTwo bytes.Buffer
|
||||
callI, err = a.GetCall(FromRequest(call.AppName, call.Path, req), WithWriter(&outTwo))
|
||||
callI, err = a.GetCall(FromRequest(app, call.Path, req), WithWriter(&outTwo))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user