minor improvements; matrix: use message parts for setting up action pattern
This commit is contained in:
parent
c5f1fe6e81
commit
d0f2fbc346
5 changed files with 18 additions and 7 deletions
|
@ -30,7 +30,7 @@ func (cfg *defcfg) Actions() []lib.ActionConfig {
|
|||
}
|
||||
|
||||
func (cfg *defcfg) AddAction(pattern string, specs ...lib.ActionSpec) {
|
||||
act := ActionConfig(pattern, specs)
|
||||
act := actionConfig(pattern, specs)
|
||||
cfg.actions = append(cfg.actions, act)
|
||||
}
|
||||
|
||||
|
@ -142,7 +142,7 @@ func (act *action) Specs() []lib.ActionSpec {
|
|||
return act.specs
|
||||
}
|
||||
|
||||
func ActionConfig(pat string, specs []lib.ActionSpec) *action {
|
||||
func actionConfig(pat string, specs []lib.ActionSpec) *action {
|
||||
return &action{
|
||||
pattern: pattern(strings.Split(pat, "|")),
|
||||
specs: specs,
|
||||
|
@ -159,6 +159,10 @@ func (p pattern) Slice() []string {
|
|||
return []string(p)
|
||||
}
|
||||
|
||||
func Pattern(p ...string) lib.Pattern {
|
||||
return pattern(p)
|
||||
}
|
||||
|
||||
// overridable settings
|
||||
|
||||
type Settings map[string]string
|
||||
|
|
|
@ -22,6 +22,11 @@ func (spec *baseSpec) Receivers() []lib.Addressable {
|
|||
}
|
||||
|
||||
func (spec *baseSpec) AddReceiver(rcv lib.Addressable) {
|
||||
for _, r := range spec.receivers {
|
||||
if r == rcv {
|
||||
return
|
||||
}
|
||||
}
|
||||
spec.receivers = append(spec.receivers, rcv)
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ func createCell(ctx lib.Context) lib.Context {
|
|||
|
||||
func connect(src, tgt lib.Context, msg lib.Message) {
|
||||
cfg := src.Config()
|
||||
pattern := "matrix|data"
|
||||
pattern := config.Pattern(msg.Domain(), "data", msg.Class(), msg.Item()).String()
|
||||
for _, act := range cfg.Actions() {
|
||||
if act.Pattern().String() == pattern {
|
||||
for _, spec := range act.Specs() {
|
||||
|
|
|
@ -23,7 +23,7 @@ func ConfigMx() lib.Config {
|
|||
app_c.AddAction("demo", action.Base(action.Forward, "test-receiver"))
|
||||
|
||||
test_rcvr := config.Default("test-receiver")
|
||||
test_rcvr.AddAction("demo", action.Base(AH_MxReceiver))
|
||||
test_rcvr.AddAction("data", action.Base(AH_MxReceiver))
|
||||
|
||||
cell_0 := matrix.DefaultConfig("cell-0")
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package scopes
|
||||
package scopes_test
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
@ -16,7 +16,7 @@ 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), 7)
|
||||
t.AssertEqual(t.LogCheck(logfile, true), 13)
|
||||
}
|
||||
|
||||
func MxTest(t *testing.T) {
|
||||
|
@ -26,13 +26,15 @@ func MxTest(t *testing.T) {
|
|||
rcvr := ctx.Services()["test-receiver"]
|
||||
msg := message.New("matrix", "create").WithSender(rcvr)
|
||||
c0.Send(msg)
|
||||
msg = message.New("matrix", "data")
|
||||
c0.Send(msg)
|
||||
}
|
||||
|
||||
// action handlers
|
||||
|
||||
func MxReceiver(act lib.Action) bool {
|
||||
t := testing.GetT(act.Context())
|
||||
t.AssertEqual(act.Message().Action(), "demo")
|
||||
t.AssertEqual(act.Message().Action(), "data")
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue