add sharness test for log endpoint
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
Jeromy committed
Jun 18, 2015 at 08:18 UTC
96e98a8e13c42def19c57093ff62b68b897af441
3 files changed
+13
-1
core/corehttp/logs.go
+4
@@ -29,6 +29,9 @@ func (w *writeErrNotifier) Write(b []byte) (int, error) {
29
default:
30
}
31
}
32
+ if f, ok := w.w.(http.Flusher); ok {
33
+ f.Flush()
34
+ }
35
return n, err
36
}
37
@@ -38,6 +41,7 @@ func LogOption() ServeOption {
41
w.WriteHeader(200)
42
wnf, errs := newWriteErrNotifier(w)
43
eventlog.WriterGroup.AddWriter(wnf)
44
+ log.Event(n.Context(), "log API client connected")
45
<-errs
46
})
47
return mux, nil
test/sharness/t0110-gateway.sh
+8
@@ -75,6 +75,14 @@ test_expect_success "GET /webui/ returns code expected" '
75
test_curl_resp_http_code "http://127.0.0.1:$apiport/webui/" "HTTP/1.1 302 Found" "HTTP/1.1 301 Moved Permanently"
76
'
77
78
+test_expect_success "GET /logs returns logs" '
79
+ test_expect_code 28 curl http://127.0.0.1:$apiport/logs -m1 > log_out
80
+'
81
+
82
+test_expect_success "log output looks good" '
83
+ grep "log API client connected" log_out
84
+'
85
+
86
test_kill_ipfs_daemon
87
88
test_done
thirdparty/eventlog/writer.go
+1
-1
@@ -26,7 +26,7 @@ func (mw *MirrorWriter) Write(b []byte) (int, error) {
26
continue
27
}
28
29
- j := len(mw.writers)
29
+ j := len(mw.writers) - 1
30
for ; j > i; j-- {
31
if mw.writers[j] != nil {
32
mw.writers[i], mw.writers[j] = mw.writers[j], nil // swap