From f85237ff5e07c7c92b2c3876dcd3a7e00af10e88 Mon Sep 17 00:00:00 2001 From: Reed Allman Date: Wed, 28 Jun 2017 23:09:43 -0700 Subject: [PATCH] add tests --- api/runner/func_logger.go | 6 ++++-- api/runner/runner_test.go | 7 ------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/api/runner/func_logger.go b/api/runner/func_logger.go index 06c561d35..194b21bef 100644 --- a/api/runner/func_logger.go +++ b/api/runner/func_logger.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "errors" + "fmt" "io" "github.com/Sirupsen/logrus" @@ -12,6 +13,7 @@ import ( ) // TODO kind of no reason to have FuncLogger interface... we can just do the thing. +// TODO recycle buffers used in various writers type FuncLogger interface { Writer(ctx context.Context, appName, path, image, reqID string) io.WriteCloser @@ -182,7 +184,7 @@ func (l *limitWriter) Write(b []byte) (int, error) { if l.n >= l.max { return 0, errors.New("max log size exceeded, truncating log") } - if l.n+len(b) > l.max { + if l.n+len(b) >= l.max { // cut off to prevent gigantic line attack b = b[:l.max-l.n] } @@ -190,7 +192,7 @@ func (l *limitWriter) Write(b []byte) (int, error) { l.n += n if l.n >= l.max { // write in truncation message to log once - l.WriteClose.Write([]byte(fmt.Sprintf("\n-----max log size %d bytes exceeded, truncating log-----\n"))) + l.WriteCloser.Write([]byte(fmt.Sprintf("\n-----max log size %d bytes exceeded, truncating log-----\n"))) } return n, err } diff --git a/api/runner/runner_test.go b/api/runner/runner_test.go index cc7792f17..7f69fda1c 100644 --- a/api/runner/runner_test.go +++ b/api/runner/runner_test.go @@ -4,7 +4,6 @@ import ( "bytes" "context" "fmt" - "io" "strings" "testing" "time" @@ -16,12 +15,6 @@ import ( "gitlab-odx.oracle.com/odx/functions/api/runner/task" ) -type nopCloser struct { - io.Writer -} - -func (n nopCloser) Close() error { return nil } - func TestRunnerHello(t *testing.T) { buf := setLogBuffer() ctx, cancel := context.WithCancel(context.Background())