set up config structure for specifying actions
This commit is contained in:
parent
15eacddeed
commit
9ecbf7d7e9
5 changed files with 51 additions and 4 deletions
|
@ -63,6 +63,13 @@ func (cfg *Base) Add(child lib.Config) {
|
||||||
cfg.children = append(cfg.children, child)
|
cfg.children = append(cfg.children, child)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (cfg *Base) WithAction(pattern string, spec lib.ActionSpec) lib.Config {
|
||||||
|
act := ActionConfig(pattern, nil)
|
||||||
|
act.specs = append(act.specs, spec)
|
||||||
|
cfg.actions = append(cfg.actions, act)
|
||||||
|
return cfg
|
||||||
|
}
|
||||||
|
|
||||||
// implementation-specific methods and functions
|
// implementation-specific methods and functions
|
||||||
|
|
||||||
func (cfg *Base) WithStep(step lib.StepProc) *Base {
|
func (cfg *Base) WithStep(step lib.StepProc) *Base {
|
||||||
|
@ -83,6 +90,25 @@ func MakeBase(name string, starter lib.StartProc) *Base {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// action configuration
|
||||||
|
|
||||||
|
type ActBase struct {
|
||||||
|
pattern string
|
||||||
|
specs []lib.ActionSpec
|
||||||
|
}
|
||||||
|
|
||||||
|
func (act *ActBase) Pattern() string {
|
||||||
|
return act.pattern
|
||||||
|
}
|
||||||
|
|
||||||
|
func (act *ActBase) Specs() []lib.ActionSpec {
|
||||||
|
return act.specs
|
||||||
|
}
|
||||||
|
|
||||||
|
func ActionConfig(pattern string, specs []lib.ActionSpec) *ActBase {
|
||||||
|
return &ActBase{pattern, specs}
|
||||||
|
}
|
||||||
|
|
||||||
// overridable settings
|
// overridable settings
|
||||||
|
|
||||||
type Settings map[string]string
|
type Settings map[string]string
|
||||||
|
|
|
@ -25,6 +25,7 @@ type Config interface {
|
||||||
Actions() []ActionConfig
|
Actions() []ActionConfig
|
||||||
Children() []Config
|
Children() []Config
|
||||||
Add(Config)
|
Add(Config)
|
||||||
|
WithAction(string, ActionSpec) Config
|
||||||
}
|
}
|
||||||
|
|
||||||
type Services map[string]Context
|
type Services map[string]Context
|
||||||
|
|
|
@ -40,7 +40,7 @@ func SetUp(tbase *testing.T) *T {
|
||||||
|
|
||||||
func SetUpApp(tbase *testing.T, cfg lib.Config) *T {
|
func SetUpApp(tbase *testing.T, cfg lib.Config) *T {
|
||||||
t := SetUp(tbase)
|
t := SetUp(tbase)
|
||||||
t.Ctx = context.AppContext(cfg)
|
t.Ctx = context.AppContext(cfg).WithState(t)
|
||||||
cfg.Starter()(t.Ctx)
|
cfg.Starter()(t.Ctx)
|
||||||
time.Sleep(100 * time.Millisecond)
|
time.Sleep(100 * time.Millisecond)
|
||||||
return t
|
return t
|
||||||
|
|
|
@ -21,12 +21,19 @@ func Config() lib.Config {
|
||||||
Base: b("config", config.Start),
|
Base: b("config", config.Start),
|
||||||
ConfigFormat: "etc",
|
ConfigFormat: "etc",
|
||||||
})
|
})
|
||||||
cfg.Add(config.Cfg{
|
cfg.Add(b("test-receiver", core.Start))
|
||||||
Base: b("test-receiver", core.Start),
|
// WithAction("*", action.Base{
|
||||||
})
|
// Handler: AH_Receiver,
|
||||||
|
// }
|
||||||
return &cfg
|
return &cfg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// register action handlers from ..._test.go here:
|
||||||
|
|
||||||
|
var (
|
||||||
|
AH_Receiver lib.ActionHandler
|
||||||
|
)
|
||||||
|
|
||||||
// collect here the names of fields that may be overridden via
|
// collect here the names of fields that may be overridden via
|
||||||
// explicit Override() or SCOPES_* environment settings.
|
// explicit Override() or SCOPES_* environment settings.
|
||||||
const (
|
const (
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
tbase "testing"
|
tbase "testing"
|
||||||
|
|
||||||
"git.sr.ht/~cco/go-scopes/app"
|
"git.sr.ht/~cco/go-scopes/app"
|
||||||
|
"git.sr.ht/~cco/go-scopes/lib"
|
||||||
"git.sr.ht/~cco/go-scopes/lib/message"
|
"git.sr.ht/~cco/go-scopes/lib/message"
|
||||||
"git.sr.ht/~cco/go-scopes/testing"
|
"git.sr.ht/~cco/go-scopes/testing"
|
||||||
"git.sr.ht/~cco/go-scopes/tests/etc"
|
"git.sr.ht/~cco/go-scopes/tests/etc"
|
||||||
|
@ -39,3 +40,15 @@ func SendTest(t *testing.T) {
|
||||||
rcvr = message.SimpleAddress("test-receiver")
|
rcvr = message.SimpleAddress("test-receiver")
|
||||||
rcvr.Send(ctx, msg)
|
rcvr.Send(ctx, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// action handlers
|
||||||
|
|
||||||
|
func Receiver(act lib.Action) bool {
|
||||||
|
t := act.Context().Parent().State().(*testing.T)
|
||||||
|
t.AssertEqual(act.Message().Action(), "demo")
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
etc.AH_Receiver = Receiver
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue