From 96e98a8e13c42def19c57093ff62b68b897af441 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Thu, 18 Jun 2015 08:18:55 -0700 Subject: [PATCH] add sharness test for log endpoint License: MIT Signed-off-by: Jeromy --- core/corehttp/logs.go | 4 ++++ test/sharness/t0110-gateway.sh | 8 ++++++++ thirdparty/eventlog/writer.go | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/core/corehttp/logs.go b/core/corehttp/logs.go index 4e46d0af0..7624644cf 100644 --- a/core/corehttp/logs.go +++ b/core/corehttp/logs.go @@ -29,6 +29,9 @@ func (w *writeErrNotifier) Write(b []byte) (int, error) { default: } } + if f, ok := w.w.(http.Flusher); ok { + f.Flush() + } return n, err } @@ -38,6 +41,7 @@ func LogOption() ServeOption { w.WriteHeader(200) wnf, errs := newWriteErrNotifier(w) eventlog.WriterGroup.AddWriter(wnf) + log.Event(n.Context(), "log API client connected") <-errs }) return mux, nil diff --git a/test/sharness/t0110-gateway.sh b/test/sharness/t0110-gateway.sh index ac421d652..36a94c671 100755 --- a/test/sharness/t0110-gateway.sh +++ b/test/sharness/t0110-gateway.sh @@ -75,6 +75,14 @@ test_expect_success "GET /webui/ returns code expected" ' test_curl_resp_http_code "http://127.0.0.1:$apiport/webui/" "HTTP/1.1 302 Found" "HTTP/1.1 301 Moved Permanently" ' +test_expect_success "GET /logs returns logs" ' + test_expect_code 28 curl http://127.0.0.1:$apiport/logs -m1 > log_out +' + +test_expect_success "log output looks good" ' + grep "log API client connected" log_out +' + test_kill_ipfs_daemon test_done diff --git a/thirdparty/eventlog/writer.go b/thirdparty/eventlog/writer.go index 2fed6949a..9a7728a19 100644 --- a/thirdparty/eventlog/writer.go +++ b/thirdparty/eventlog/writer.go @@ -26,7 +26,7 @@ func (mw *MirrorWriter) Write(b []byte) (int, error) { continue } - j := len(mw.writers) + j := len(mw.writers) - 1 for ; j > i; j-- { if mw.writers[j] != nil { mw.writers[i], mw.writers[j] = mw.writers[j], nil // swap