From 235ba65c644a482a0e23a7a81650c7535c28ae64 Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Sat, 8 Jul 2023 08:20:47 +0200 Subject: [PATCH] fix logging for unit tests --- lib/action/action.go | 1 + lib/core/core.go | 2 ++ logging/logging.go | 5 +++-- tests/unit_test.go | 3 ++- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/action/action.go b/lib/action/action.go index 00baeca..1e02363 100644 --- a/lib/action/action.go +++ b/lib/action/action.go @@ -40,6 +40,7 @@ func Select(ctx lib.Context, msg lib.Message) []lib.Action { } } } + // if len(acts) == 0 { logging.Warn().... } return acts } diff --git a/lib/core/core.go b/lib/core/core.go index 1e5a4ca..38b9b63 100644 --- a/lib/core/core.go +++ b/lib/core/core.go @@ -7,6 +7,8 @@ import ( "git.sr.ht/~cco/go-scopes/logging" ) +func NoOp(_ lib.Context) {} + func Start(ctx lib.Context) { logging.Debug(ctx).Msg("core.Start") lib.RunCtx(ctx, Listen) diff --git a/logging/logging.go b/logging/logging.go index 4c3238a..432f57f 100644 --- a/logging/logging.go +++ b/logging/logging.go @@ -28,7 +28,7 @@ var Levels = map[string]zerolog.Level{ type Logger = zerolog.Logger -var defaultLogger = log.Logger +var defaultLogger = log.Logger.Level(InfoLevel) var globalLogger *Logger = &log.Logger type Cfg struct { @@ -38,7 +38,8 @@ type Cfg struct { } func SetDefault() { - globalLogger = &defaultLogger + logger := defaultLogger + globalLogger = &logger } func Setup(ctx lib.Context, cfg *Cfg, home string) { diff --git a/tests/unit_test.go b/tests/unit_test.go index 4a54704..976879a 100644 --- a/tests/unit_test.go +++ b/tests/unit_test.go @@ -8,6 +8,7 @@ import ( "git.sr.ht/~cco/go-scopes/lib" "git.sr.ht/~cco/go-scopes/lib/action" "git.sr.ht/~cco/go-scopes/lib/context" + "git.sr.ht/~cco/go-scopes/lib/core" "git.sr.ht/~cco/go-scopes/lib/message" "git.sr.ht/~cco/go-scopes/testing" ) @@ -70,7 +71,7 @@ func ActionTest(t *testing.T) { return true } } - cfg := config.Base("testing", nil). + cfg := config.Base("testing", core.NoOp). AddAction("start", action.Base(hdlrGen("started"))). AddAction("scopes|doit|task", action.Base(hdlrGen("done"))) ctx := context.AppContext(cfg)