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) {
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(
[]*models.App{
@@ -187,24 +195,28 @@ func TestRouteRunnerExecution(t *testing.T) {
_, rec := routerRequest(t, srv.Router, test.method, test.path, body)
respBytes, _ := ioutil.ReadAll(rec.Body)
respBody := string(respBytes)
maxLog := len(respBody)
if maxLog > 1024 {
maxLog = 1024
}
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",
i, test.expectedCode, rec.Code, respBody)
i, test.expectedCode, rec.Code, respBody[:maxLog])
}
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",
i, test.expectedErrSubStr, respBody)
i, test.expectedErrSubStr, respBody[:maxLog])
}
if test.expectedHeaders != nil {
for name, header := range test.expectedHeaders {
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",
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 {
return New(context.Background(),
WithLogLevel(getEnv(EnvLogLevel, DefaultLogLevel)),
WithDatastore(ds),
WithMQ(mq),
WithLogstore(logDB),