testing: use testing.Start as app starter

This commit is contained in:
Helmut Merz 2023-06-03 11:44:32 +02:00
parent 4119d61c56
commit 92cefca3cb
4 changed files with 28 additions and 3 deletions

View file

@ -9,11 +9,15 @@ type Config interface {
type Services map[string]Context
type ContextState interface{}
type Context interface {
Config() Config
Parent() Context
Services() Services
ChildContext(Config) Context
State() ContextState
WithState(ContextState) Context
}
type StartFct = func(Context)
@ -24,6 +28,7 @@ type context struct {
cfg Config
parent Context
children []Context
state ContextState
}
func (ctx *context) Config() Config {
@ -45,8 +50,20 @@ func (ctx *context) ChildContext(cfg Config) Context {
return cctx
}
func (ctx *context) State() ContextState {
return ctx.state
}
func (ctx *context) WithState(state ContextState) Context {
ctx.state = state
return ctx
}
func makeCtx(cfg Config, parent Context) *context {
return &context{cfg, parent, nil}
return &context{
cfg: cfg,
parent: parent,
}
}
// top-level application context

View file

@ -6,9 +6,16 @@ import (
"regexp"
"testing"
"git.sr.ht/~cco/go-scopes"
"git.sr.ht/~cco/go-scopes/common"
)
func Start(ctx common.Context) {
scopes.Start(ctx)
}
// definitions
type Map map[string]interface{}
type T struct {

View file

@ -4,13 +4,14 @@ import (
"git.sr.ht/~cco/go-scopes"
"git.sr.ht/~cco/go-scopes/common"
"git.sr.ht/~cco/go-scopes/config"
"git.sr.ht/~cco/go-scopes/testing"
)
func Config() common.Config {
ovr := Overrides().Use
b := config.MakeBase
cfg := scopes.Cfg{
Base: b("dummy", scopes.Start),
Base: b("testing", testing.Start),
Home: ovr(".", HOME),
AppType: "standard",
}

View file

@ -15,7 +15,7 @@ func TestConfig(tb *tbase.T) {
func ConfigTest(t *testing.T) {
cfg := etc.Config()
t.AssertEqual(cfg.Name(), "dummy")
t.AssertEqual(cfg.Name(), "testing")
appCfg := cfg.(*scopes.Cfg)
t.AssertEqual(appCfg.Home, "tests")
confCtx := t.Ctx.Services()["config"]