fn: minor test improvements (#794)

This commit is contained in:
Tolga Ceylan
2018-02-26 15:10:40 -08:00
committed by Reed Allman
parent 5551d6318a
commit 95d64f3aa9
3 changed files with 19 additions and 6 deletions

View File

@@ -124,6 +124,14 @@ func TestRouteRunnerPost(t *testing.T) {
func TestRouteRunnerExecution(t *testing.T) { func TestRouteRunnerExecution(t *testing.T) {
buf := setLogBuffer() buf := setLogBuffer()
isFailure := false
// Log once after we are done, flow of events are important (hot/cold containers, idle timeout, etc.)
// for figuring out why things failed.
defer func() {
if isFailure {
t.Log(buf.String())
}
}()
ds := datastore.NewMockInit( ds := datastore.NewMockInit(
[]*models.App{ []*models.App{
@@ -187,24 +195,28 @@ func TestRouteRunnerExecution(t *testing.T) {
_, 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) respBytes, _ := ioutil.ReadAll(rec.Body)
respBody := string(respBytes) respBody := string(respBytes)
maxLog := len(respBody)
if maxLog > 1024 {
maxLog = 1024
}
if rec.Code != test.expectedCode { if rec.Code != test.expectedCode {
t.Log(buf.String()) isFailure = true
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, respBody) i, test.expectedCode, rec.Code, respBody[:maxLog])
} }
if test.expectedErrSubStr != "" && !strings.Contains(respBody, test.expectedErrSubStr) { if test.expectedErrSubStr != "" && !strings.Contains(respBody, test.expectedErrSubStr) {
t.Log(buf.String()) isFailure = true
t.Errorf("Test %d: Expected response to include %s but got body: %s", t.Errorf("Test %d: Expected response to include %s but got body: %s",
i, test.expectedErrSubStr, respBody) i, test.expectedErrSubStr, respBody[:maxLog])
} }
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()) isFailure = true
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))
} }

View File

@@ -26,6 +26,7 @@ var tmpDatastoreTests = "/tmp/func_test_datastore.db"
func testServer(ds models.Datastore, mq models.MessageQueue, logDB models.LogStore, rnr agent.Agent, nodeType ServerNodeType) *Server { func testServer(ds models.Datastore, mq models.MessageQueue, logDB models.LogStore, rnr agent.Agent, nodeType ServerNodeType) *Server {
return New(context.Background(), return New(context.Background(),
WithLogLevel(getEnv(EnvLogLevel, DefaultLogLevel)),
WithDatastore(ds), WithDatastore(ds),
WithMQ(mq), WithMQ(mq),
WithLogstore(logDB), WithLogstore(logDB),

View File

@@ -44,7 +44,7 @@ type AppRequest struct {
// fill created with with zero bytes of specified size // fill created with with zero bytes of specified size
CreateFileSize int `json:"createFileSize,omitempty"` CreateFileSize int `json:"createFileSize,omitempty"`
// allocate RAM and hold until next request // allocate RAM and hold until next request
AllocateMemory int `json:"allocateMemory,om itempty"` AllocateMemory int `json:"allocateMemory,omitempty"`
// leak RAM forever // leak RAM forever
LeakMemory int `json:"leakMemory,omitempty"` LeakMemory int `json:"leakMemory,omitempty"`
// respond with partial output // respond with partial output