some code improvements and rearrangements
This commit is contained in:
parent
9797c3515a
commit
4119d61c56
7 changed files with 18 additions and 16 deletions
|
@ -46,8 +46,7 @@ func (ctx *context) ChildContext(cfg Config) Context {
|
|||
}
|
||||
|
||||
func makeCtx(cfg Config, parent Context) *context {
|
||||
ctx := context{cfg, parent, nil}
|
||||
return &ctx
|
||||
return &context{cfg, parent, nil}
|
||||
}
|
||||
|
||||
// top-level application context
|
||||
|
|
|
@ -46,10 +46,6 @@ func MakeBase(name string, starter common.StartFct) *Base {
|
|||
}
|
||||
}
|
||||
|
||||
func Setup(cfg common.Config) common.Config {
|
||||
return cfg
|
||||
}
|
||||
|
||||
// overridable settings
|
||||
|
||||
type Settings map[string]string
|
||||
|
|
|
@ -14,7 +14,10 @@ func Config() common.Config {
|
|||
Home: ovr(".", HOME),
|
||||
AppType: "standard",
|
||||
}
|
||||
cfg.Add(config.Cfg{b("config", config.Start), "etc"})
|
||||
cfg.Add(config.Cfg{
|
||||
Base: b("config", config.Start),
|
||||
ConfigFormat: "etc",
|
||||
})
|
||||
return &cfg
|
||||
}
|
||||
|
||||
|
|
|
@ -6,11 +6,10 @@ import (
|
|||
"demo/etc"
|
||||
|
||||
"git.sr.ht/~cco/go-scopes"
|
||||
"git.sr.ht/~cco/go-scopes/config"
|
||||
)
|
||||
|
||||
func main() {
|
||||
cfg := config.Setup(etc.Config())
|
||||
cfg := etc.Config()
|
||||
fmt.Println(cfg.Name())
|
||||
appCfg := cfg.(*scopes.Cfg)
|
||||
fmt.Println(appCfg.Home)
|
||||
|
|
|
@ -27,6 +27,13 @@ func SetUp(tbase *testing.T) *T {
|
|||
return t
|
||||
}
|
||||
|
||||
func SetUpApp(tbase *testing.T, cfg common.Config) *T {
|
||||
t := SetUp(tbase)
|
||||
t.Ctx = common.AppContext(cfg)
|
||||
cfg.Starter()(t.Ctx)
|
||||
return t
|
||||
}
|
||||
|
||||
// testing methods
|
||||
|
||||
func (t *T) Run(name string, f func(*T)) bool {
|
||||
|
|
|
@ -14,7 +14,10 @@ func Config() common.Config {
|
|||
Home: ovr(".", HOME),
|
||||
AppType: "standard",
|
||||
}
|
||||
cfg.Add(config.Cfg{b("config", config.Start), "etc"})
|
||||
cfg.Add(config.Cfg{
|
||||
Base: b("config", config.Start),
|
||||
ConfigFormat: "etc",
|
||||
})
|
||||
return &cfg
|
||||
}
|
||||
|
||||
|
|
|
@ -4,17 +4,12 @@ import (
|
|||
tbase "testing"
|
||||
|
||||
"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"
|
||||
"git.sr.ht/~cco/go-scopes/tests/etc"
|
||||
)
|
||||
|
||||
func TestConfig(tb *tbase.T) {
|
||||
t := testing.SetUp(tb)
|
||||
cfg := config.Setup(etc.Config())
|
||||
t.Ctx = common.AppContext(cfg)
|
||||
cfg.Starter()(t.Ctx)
|
||||
t := testing.SetUpApp(tb, etc.Config())
|
||||
t.Run("config", ConfigTest)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue