work in progress: matrix; message: sender as Addressable type
This commit is contained in:
parent
f55416dddf
commit
9a609ce880
5 changed files with 49 additions and 8 deletions
|
@ -42,7 +42,7 @@ func (h *head) Item() string {
|
||||||
|
|
||||||
type message struct {
|
type message struct {
|
||||||
*head
|
*head
|
||||||
sender lib.Address
|
sender lib.Addressable
|
||||||
payload lib.Payload
|
payload lib.Payload
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ func (msg *message) Head() lib.MsgHead {
|
||||||
return msg
|
return msg
|
||||||
}
|
}
|
||||||
|
|
||||||
func (msg *message) Sender() lib.Address {
|
func (msg *message) Sender() lib.Addressable {
|
||||||
return msg.sender
|
return msg.sender
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ func (msg *message) Payload() lib.Payload {
|
||||||
return msg.payload
|
return msg.payload
|
||||||
}
|
}
|
||||||
|
|
||||||
func (msg *message) WithSender(s lib.Address) lib.Message {
|
func (msg *message) WithSender(s lib.Addressable) lib.Message {
|
||||||
msg.sender = s
|
msg.sender = s
|
||||||
return msg
|
return msg
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1,17 @@
|
||||||
package matrix
|
package matrix
|
||||||
|
|
||||||
|
import (
|
||||||
|
lib "git.sr.ht/~cco/go-scopes"
|
||||||
|
"git.sr.ht/~cco/go-scopes/core"
|
||||||
|
"git.sr.ht/~cco/go-scopes/core/action"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Start(ctx lib.Context) {
|
||||||
|
cfg := ctx.Config()
|
||||||
|
cfg.AddAction("create", action.Base(create))
|
||||||
|
core.Start(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
func create(act lib.Action) bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
|
@ -41,12 +41,17 @@ type MsgHead interface {
|
||||||
type Message interface {
|
type Message interface {
|
||||||
MsgHead
|
MsgHead
|
||||||
Head() MsgHead
|
Head() MsgHead
|
||||||
Sender() Address
|
Sender() Addressable
|
||||||
Payload() Payload
|
Payload() Payload
|
||||||
WithSender(Address) Message
|
WithSender(Addressable) Message
|
||||||
WithPayload(Payload) Message
|
WithPayload(Payload) Message
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Addressable interface {
|
||||||
|
Address() Address
|
||||||
|
Cell() Context
|
||||||
|
}
|
||||||
|
|
||||||
type Address interface {
|
type Address interface {
|
||||||
fmt.Stringer
|
fmt.Stringer
|
||||||
Url() string
|
Url() string
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"git.sr.ht/~cco/go-scopes/core"
|
"git.sr.ht/~cco/go-scopes/core"
|
||||||
"git.sr.ht/~cco/go-scopes/core/action"
|
"git.sr.ht/~cco/go-scopes/core/action"
|
||||||
"git.sr.ht/~cco/go-scopes/logging"
|
"git.sr.ht/~cco/go-scopes/logging"
|
||||||
|
"git.sr.ht/~cco/go-scopes/matrix"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ConfigMx() lib.Config {
|
func ConfigMx() lib.Config {
|
||||||
|
@ -25,7 +26,9 @@ func ConfigMx() lib.Config {
|
||||||
test_rcvr := b("test-receiver", core.Start).
|
test_rcvr := b("test-receiver", core.Start).
|
||||||
AddAction("demo", action.Base(AH_MxReceiver))
|
AddAction("demo", action.Base(AH_MxReceiver))
|
||||||
|
|
||||||
app_c.Add(test_rcvr)
|
cell_0 := b("cell-0", matrix.Start)
|
||||||
|
|
||||||
|
app_c.Add(cell_0, test_rcvr)
|
||||||
|
|
||||||
return app_c
|
return app_c
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,9 @@ import (
|
||||||
"os"
|
"os"
|
||||||
tbase "testing"
|
tbase "testing"
|
||||||
|
|
||||||
|
lib "git.sr.ht/~cco/go-scopes"
|
||||||
"git.sr.ht/~cco/go-scopes/common/testing"
|
"git.sr.ht/~cco/go-scopes/common/testing"
|
||||||
|
"git.sr.ht/~cco/go-scopes/core/message"
|
||||||
"git.sr.ht/~cco/go-scopes/tests/etc"
|
"git.sr.ht/~cco/go-scopes/tests/etc"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -14,10 +16,25 @@ func TestMatrixApp(tb *tbase.T) {
|
||||||
t := testing.SetUpApp(tb, etc.ConfigMx())
|
t := testing.SetUpApp(tb, etc.ConfigMx())
|
||||||
t.Run("app-matrix", MxTest)
|
t.Run("app-matrix", MxTest)
|
||||||
t.TearDownApp("matrix")
|
t.TearDownApp("matrix")
|
||||||
t.AssertEqual(t.LogCheck(logfile, true), 3)
|
t.AssertEqual(t.LogCheck(logfile, true), 6)
|
||||||
}
|
}
|
||||||
|
|
||||||
func MxTest(t *testing.T) {
|
func MxTest(t *testing.T) {
|
||||||
ctx := t.Ctx
|
ctx := t.Ctx
|
||||||
t.AssertEqual(len(ctx.Services()), 2)
|
t.AssertEqual(len(ctx.Services()), 3)
|
||||||
|
rcvr := message.SimpleAddress("cell-0")
|
||||||
|
msg := message.SimpleMessage("create")
|
||||||
|
lib.Send(ctx, rcvr, msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
// action handlers
|
||||||
|
|
||||||
|
func MxReceiver(act lib.Action) bool {
|
||||||
|
t := testing.GetT(act.Context())
|
||||||
|
t.AssertEqual(act.Message().Action(), "demo")
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
etc.AH_MxReceiver = MxReceiver
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue