mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
fn: test case additions (#755)
1) oom test 2) invalid http resp code test 3) check for error string contents in various error cases
This commit is contained in:
committed by
Reed Allman
parent
a2aad73664
commit
b2c95410f4
@@ -130,11 +130,13 @@ func TestRouteRunnerExecution(t *testing.T) {
|
|||||||
{Name: "myapp", Config: models.Config{}},
|
{Name: "myapp", Config: models.Config{}},
|
||||||
},
|
},
|
||||||
[]*models.Route{
|
[]*models.Route{
|
||||||
{Path: "/", AppName: "myapp", Image: "fnproject/hello", Type: "sync", Memory: 128, Timeout: 30, IdleTimeout: 30, Headers: map[string][]string{"X-Function": {"Test"}}},
|
{Path: "/", AppName: "myapp", Image: "fnproject/fn-test-utils", Type: "sync", Memory: 128, Timeout: 30, IdleTimeout: 30, Headers: map[string][]string{"X-Function": {"Test"}}},
|
||||||
{Path: "/myroute", AppName: "myapp", Image: "fnproject/hello", Type: "sync", Memory: 128, Timeout: 30, IdleTimeout: 30, Headers: map[string][]string{"X-Function": {"Test"}}},
|
{Path: "/myhot", AppName: "myapp", Image: "fnproject/fn-test-utils", Type: "sync", Format: "http", Memory: 128, Timeout: 30, IdleTimeout: 30, Headers: map[string][]string{"X-Function": {"Test"}}},
|
||||||
|
{Path: "/myroute", AppName: "myapp", Image: "fnproject/fn-test-utils", Type: "sync", Memory: 128, Timeout: 30, IdleTimeout: 30, Headers: map[string][]string{"X-Function": {"Test"}}},
|
||||||
{Path: "/myerror", AppName: "myapp", Image: "fnproject/fn-test-utils", Type: "sync", Memory: 128, Timeout: 30, IdleTimeout: 30, Headers: map[string][]string{"X-Function": {"Test"}}},
|
{Path: "/myerror", AppName: "myapp", Image: "fnproject/fn-test-utils", Type: "sync", Memory: 128, Timeout: 30, IdleTimeout: 30, Headers: map[string][]string{"X-Function": {"Test"}}},
|
||||||
{Path: "/mydne", AppName: "myapp", Image: "fnproject/imagethatdoesnotexist", Type: "sync", Memory: 128, Timeout: 30, IdleTimeout: 30},
|
{Path: "/mydne", AppName: "myapp", Image: "fnproject/imagethatdoesnotexist", Type: "sync", Memory: 128, Timeout: 30, IdleTimeout: 30},
|
||||||
{Path: "/mydnehot", AppName: "myapp", Image: "fnproject/imagethatdoesnotexist", Type: "sync", Format: "http", Memory: 128, Timeout: 30, IdleTimeout: 30},
|
{Path: "/mydnehot", AppName: "myapp", Image: "fnproject/imagethatdoesnotexist", Type: "sync", Format: "http", Memory: 128, Timeout: 30, IdleTimeout: 30},
|
||||||
|
{Path: "/myoom", AppName: "myapp", Image: "fnproject/fn-test-utils", Type: "sync", Memory: 8, Timeout: 30, IdleTimeout: 30},
|
||||||
}, nil,
|
}, nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -145,42 +147,65 @@ func TestRouteRunnerExecution(t *testing.T) {
|
|||||||
|
|
||||||
srv := testServer(ds, &mqs.Mock{}, fnl, rnr, ServerTypeFull)
|
srv := testServer(ds, &mqs.Mock{}, fnl, rnr, ServerTypeFull)
|
||||||
|
|
||||||
|
expHeaders := map[string][]string{"X-Function": {"Test"}}
|
||||||
|
|
||||||
|
crasher := `{"sleepTime": 0, "isDebug": true, "isCrash": true}` // crash container
|
||||||
|
oomer := `{"sleepTime": 0, "isDebug": true, "allocateMemory": 12000000}` // ask for 12MB
|
||||||
|
badHttp := `{"sleepTime": 0, "isDebug": true, "responseCode": -1}` // http status of -1 (invalid http)
|
||||||
|
ok := `{"sleepTime": 0, "isDebug": true}` // good response / ok
|
||||||
|
|
||||||
for i, test := range []struct {
|
for i, test := range []struct {
|
||||||
path string
|
path string
|
||||||
body string
|
body string
|
||||||
method string
|
method string
|
||||||
expectedCode int
|
expectedCode int
|
||||||
expectedHeaders map[string][]string
|
expectedHeaders map[string][]string
|
||||||
|
expectedErrSubStr string
|
||||||
}{
|
}{
|
||||||
{"/r/myapp/", ``, "GET", http.StatusOK, map[string][]string{"X-Function": {"Test"}}},
|
{"/r/myapp/", ok, "GET", http.StatusOK, expHeaders, ""},
|
||||||
{"/r/myapp/myroute", ``, "GET", http.StatusOK, map[string][]string{"X-Function": {"Test"}}},
|
|
||||||
{"/r/myapp/myerror", `{"sleepTime": 0, "isDebug": true, "isCrash": true}`, "GET", http.StatusBadGateway, map[string][]string{"X-Function": {"Test"}}},
|
// TODO: this should return 502 and description about container misbehaving
|
||||||
{"/r/myapp/mydne", ``, "GET", http.StatusNotFound, nil},
|
{"/r/myapp/myhot", badHttp, "GET", http.StatusInternalServerError, expHeaders, "internal server error"},
|
||||||
{"/r/myapp/mydnehot", ``, "GET", http.StatusNotFound, nil},
|
// hot container now back to normal, we should get OK
|
||||||
|
{"/r/myapp/myhot", ok, "GET", http.StatusOK, expHeaders, ""},
|
||||||
|
|
||||||
|
{"/r/myapp/myroute", ok, "GET", http.StatusOK, expHeaders, ""},
|
||||||
|
{"/r/myapp/myerror", crasher, "GET", http.StatusBadGateway, expHeaders, "container exit code 2"},
|
||||||
|
{"/r/myapp/mydne", ``, "GET", http.StatusNotFound, nil, "pull access denied"},
|
||||||
|
{"/r/myapp/mydnehot", ``, "GET", http.StatusNotFound, nil, "pull access denied"},
|
||||||
|
|
||||||
// Added same tests again to check if time is reduced by the auth cache
|
// Added same tests again to check if time is reduced by the auth cache
|
||||||
{"/r/myapp/", ``, "GET", http.StatusOK, map[string][]string{"X-Function": {"Test"}}},
|
{"/r/myapp/", ok, "GET", http.StatusOK, expHeaders, ""},
|
||||||
{"/r/myapp/myroute", ``, "GET", http.StatusOK, map[string][]string{"X-Function": {"Test"}}},
|
{"/r/myapp/myroute", ok, "GET", http.StatusOK, expHeaders, ""},
|
||||||
{"/r/myapp/myerror", `{"sleepTime": 0, "isDebug": true, "isCrash": true}`, "GET", http.StatusBadGateway, map[string][]string{"X-Function": {"Test"}}},
|
{"/r/myapp/myerror", crasher, "GET", http.StatusBadGateway, expHeaders, "container exit code 2"},
|
||||||
|
{"/r/myapp/myerror", crasher, "GET", http.StatusBadGateway, expHeaders, "container exit code 2"},
|
||||||
|
{"/r/myapp/myoom", oomer, "GET", http.StatusBadGateway, nil, "container out of memory"},
|
||||||
} {
|
} {
|
||||||
body := strings.NewReader(test.body)
|
body := strings.NewReader(test.body)
|
||||||
_, rec := routerRequest(t, srv.Router, test.method, test.path, body)
|
_, rec := routerRequest(t, srv.Router, test.method, test.path, body)
|
||||||
|
respBytes, _ := ioutil.ReadAll(rec.Body)
|
||||||
|
respBody := string(respBytes)
|
||||||
|
|
||||||
if rec.Code != test.expectedCode {
|
if rec.Code != test.expectedCode {
|
||||||
t.Log(buf.String())
|
t.Log(buf.String())
|
||||||
bod, _ := ioutil.ReadAll(rec.Body)
|
|
||||||
t.Errorf("Test %d: Expected status code to be %d but was %d. body: %s",
|
t.Errorf("Test %d: Expected status code to be %d but was %d. body: %s",
|
||||||
i, test.expectedCode, rec.Code, string(bod))
|
i, test.expectedCode, rec.Code, respBody)
|
||||||
}
|
}
|
||||||
|
|
||||||
if test.expectedHeaders == nil {
|
if test.expectedErrSubStr != "" && !strings.Contains(respBody, test.expectedErrSubStr) {
|
||||||
continue
|
t.Log(buf.String())
|
||||||
|
t.Errorf("Test %d: Expected response to include %s but got body: %s",
|
||||||
|
i, test.expectedErrSubStr, respBody)
|
||||||
|
|
||||||
}
|
}
|
||||||
for name, header := range test.expectedHeaders {
|
|
||||||
if header[0] != rec.Header().Get(name) {
|
if test.expectedHeaders != nil {
|
||||||
t.Log(buf.String())
|
for name, header := range test.expectedHeaders {
|
||||||
t.Errorf("Test %d: Expected header `%s` to be %s but was %s",
|
if header[0] != rec.Header().Get(name) {
|
||||||
i, name, header[0], rec.Header().Get(name))
|
t.Log(buf.String())
|
||||||
|
t.Errorf("Test %d: Expected header `%s` to be %s but was %s",
|
||||||
|
i, name, header[0], rec.Header().Get(name))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user