From fbff96dcc09d6e89915cdb44f57642607e69f040 Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Tue, 25 Jul 2023 09:39:59 +0200 Subject: [PATCH] work in progress: matrix.connect() --- core/action/action.go | 4 +++- core/core.go | 2 +- logging/event.go | 2 +- matrix/matrix.go | 15 ++++++++++----- tests/matrix_test.go | 9 +++++---- 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/core/action/action.go b/core/action/action.go index 47bafd7..3414b09 100644 --- a/core/action/action.go +++ b/core/action/action.go @@ -40,7 +40,9 @@ func Select(ctx lib.Context, msg lib.Message) []lib.Action { } } } - // if len(acts) == 0 { logging.Warn().... } + if len(acts) == 0 { + logging.WarnM(ctx, msg).Msg("action.Select: no match") + } return acts } diff --git a/core/core.go b/core/core.go index aefbc93..a3199ae 100644 --- a/core/core.go +++ b/core/core.go @@ -34,7 +34,7 @@ func Step(ctx lib.Context) (loop bool) { func HandleMessage(ctx lib.Context, msg lib.Message) (loop bool) { loop = true - logging.Debug(ctx).Str("msg.action", msg.Action()).Msg("core.HandleMessage") + logging.DebugM(ctx, msg).Msg("core.HandleMessage") for _, act := range action.Select(ctx, msg) { loop = act.Handle() } diff --git a/logging/event.go b/logging/event.go index 01907ed..76ff088 100644 --- a/logging/event.go +++ b/logging/event.go @@ -38,7 +38,7 @@ func WithMessage(ctx lib.Context, msg lib.Message, e *Evt) *Evt { if e == nil { return e } - return WithContext(ctx, e).Str("action", msg.Action()) + return WithContext(ctx, e).Str("msg", msg.String()) } func DebugM(ctx lib.Context, msg lib.Message) *Evt { diff --git a/matrix/matrix.go b/matrix/matrix.go index c899bfd..a5628d1 100644 --- a/matrix/matrix.go +++ b/matrix/matrix.go @@ -4,7 +4,6 @@ import ( lib "git.sr.ht/~cco/go-scopes" "git.sr.ht/~cco/go-scopes/config" "git.sr.ht/~cco/go-scopes/core/action" - "git.sr.ht/~cco/go-scopes/core/message" ) func DefaultConfig(name string) lib.Config { @@ -14,11 +13,14 @@ func DefaultConfig(name string) lib.Config { } func create(act lib.Action) bool { + ctx := act.Context() + spec := act.Spec() msg := act.Message() - //spec := act.ActionSpec() - cctx := createCell(act.Context()) - nmsg := message.New("matrix", "connect").WithSender(cctx) - msg.Sender().Cell().Send(nmsg) + cctx := createCell(ctx) + //nmsg := message.New("matrix", "connect").WithSender(cctx) + //msg.Sender().Cell().Send(nmsg) + connect(ctx, cctx, spec, msg) + connect(cctx, msg.Sender().Cell(), spec, msg) return true } @@ -28,3 +30,6 @@ func createCell(ctx lib.Context) lib.Context { cfg.Starter()(cctx) return cctx } + +func connect(src, tgt lib.Context, spec lib.ActionSpec, msg lib.Message) { +} diff --git a/tests/matrix_test.go b/tests/matrix_test.go index 979c8a4..4658b48 100644 --- a/tests/matrix_test.go +++ b/tests/matrix_test.go @@ -16,15 +16,16 @@ func TestMatrixApp(tb *tbase.T) { t := testing.SetUpApp(tb, etc.ConfigMx()) t.Run("app-matrix", MxTest) t.TearDownApp("matrix") - t.AssertEqual(t.LogCheck(logfile, true), 8) + t.AssertEqual(t.LogCheck(logfile, true), 7) } func MxTest(t *testing.T) { ctx := t.Ctx t.AssertEqual(len(ctx.Services()), 3) - rcvr := ctx.Services()["cell-0"] - msg := message.SimpleMessage("create").WithSender(rcvr) - rcvr.Send(msg) + c0 := ctx.Services()["cell-0"] + rcvr := ctx.Services()["test-receiver"] + msg := message.New("matrix", "create").WithSender(rcvr) + c0.Send(msg) } // action handlers