mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
add error to call model (#539)
* add error to call model closes #331 previously, for async this error was being masked completely even if it was something useful like the image not existing. for sync, the error was returned in the http request but now it's also being stored. this error itself can cover a lot of landscape, it could be an error in getting a slot, pulling an image, running a container, among other things. anyway, no longer being masked. we can likely improve it in certain cases we run into in the future, but it's open ended at the moment and not being masked like some errors in sync http request returns (503 non-models.APIError) for now. * tucks in callTrigger stuff to keep api clean * adds swagger * adds migration * adds tests for datastore and agent to ensure behavior * pull images before tests are ran * gofmt migrations file
This commit is contained in:
@@ -310,3 +310,67 @@ func TestLoggerIsStringerAndWorks(t *testing.T) {
|
||||
|
||||
// TODO we could check for the toilet to flush here to logrus
|
||||
}
|
||||
|
||||
func TestSubmitError(t *testing.T) {
|
||||
appName := "myapp"
|
||||
path := "/error"
|
||||
image := "fnproject/error"
|
||||
const timeout = 1
|
||||
const idleTimeout = 20
|
||||
const memory = 256
|
||||
method := "GET"
|
||||
url := "http://127.0.0.1:8080/r/" + appName + path
|
||||
payload := "payload"
|
||||
typ := "sync"
|
||||
format := "default"
|
||||
env := map[string]string{
|
||||
"FN_FORMAT": format,
|
||||
"FN_APP_NAME": appName,
|
||||
"FN_PATH": path,
|
||||
"FN_MEMORY": strconv.Itoa(memory),
|
||||
"FN_TYPE": typ,
|
||||
"APP_VAR": "FOO",
|
||||
"ROUTE_VAR": "BAR",
|
||||
"DOUBLE_VAR": "BIZ, BAZ",
|
||||
}
|
||||
|
||||
cm := &models.Call{
|
||||
BaseEnv: env,
|
||||
EnvVars: env,
|
||||
AppName: appName,
|
||||
Path: path,
|
||||
Image: image,
|
||||
Type: typ,
|
||||
Format: format,
|
||||
Timeout: timeout,
|
||||
IdleTimeout: idleTimeout,
|
||||
Memory: memory,
|
||||
Payload: payload,
|
||||
URL: url,
|
||||
Method: method,
|
||||
}
|
||||
|
||||
// FromModel doesn't need a datastore, for now...
|
||||
ds := datastore.NewMockInit(nil, nil, nil)
|
||||
|
||||
a := New(ds, ds, new(mqs.Mock))
|
||||
defer a.Close()
|
||||
|
||||
callI, err := a.GetCall(FromModel(cm))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = a.Submit(callI)
|
||||
if err == nil {
|
||||
t.Fatal("expected error but got none")
|
||||
}
|
||||
|
||||
if cm.Status != "error" {
|
||||
t.Fatal("expected status to be set to 'error' but was", cm.Status)
|
||||
}
|
||||
|
||||
if cm.Error == "" {
|
||||
t.Fatal("expected error string to be set on call")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user